diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2ebbe27..0676b89 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,132 @@ include: - template/automagic.gitlab-ci.yaml #- template: Jobs/Container-Scanning.gitlab-ci.yml # see https://gitlab.com/gitlab-org/gitlab/-/issues/381665 + + +.build_docker_container: + stage: build + image: + name: nofusscomputing/docker-buildx-qemu:dev + pull_policy: always + services: + - name: docker:23-dind + entrypoint: ["env", "-u", "DOCKER_HOST"] + command: ["dockerd-entrypoint.sh"] + variables: + DOCKER_HOST: tcp://docker:2375/ + DOCKER_DRIVER: overlay2 + DOCKER_DOCKERFILE: dockerfile + # See https://github.com/docker-library/docker/pull/166 + DOCKER_TLS_CERTDIR: "" + before_script: + - git submodule foreach git submodule update --init + - if [ "0$JOB_ROOT_DIR" == "0" ]; then ROOT_DIR=gitlab-ci; else ROOT_DIR=$JOB_ROOT_DIR ; fi + - echo "[DEBUG] ROOT_DIR[$ROOT_DIR]" + - docker info + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + #- pip3 install -r gitlab-ci/gitlab_release/requirements.txt + - pip3 install setuptools wheel + - pip install -r $ROOT_DIR/conventional_commits/requirements.txt + - pip3 install gitlab-ci/gitlab_release/python-module/cz_nfc/. + # see: https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/1861 + # on why this `docker run` is required. without it multiarch support doesnt work. + - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - update-binfmts --display + - update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel + - docker buildx create --driver=docker-container --driver-opt image=moby/buildkit:v0.11.6 --use + - docker buildx inspect --bootstrap + + + # --label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \ + # --label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \ + script: + - update-binfmts --display + - | + + if [ "0$DOCKER_IMAGE_BUILD_TARGET_PLATFORMS" != "0" ]; then + + echo "[DEBUG] building multiarch/specified arch image"; + + docker buildx build --platform=$DOCKER_IMAGE_BUILD_TARGET_PLATFORMS . \ + --label org.opencontainers.image.created="$(date '+%Y-%m-%dT%H:%M:%S%:z')" \ + --label org.opencontainers.image.description="An Ansible Execution Environment" \ + --label org.opencontainers.image.documentation="$CI_PROJECT_URL" \ + --label org.opencontainers.image.source="$CI_PROJECT_URL" \ + --label org.opencontainers.image.revision="$CI_COMMIT_SHA" \ + --label io.artifacthub.package.readme-url="$CI_PROJECT_URL/-/raw/development/README.md?ref_type=heads" \ + --label io.artifacthub.package.maintainers='[{"name":"No Fuss Computing","email":"helpdesk@nofusscomputing.com"}, {"name":"jon_nfc","email":"jonathon.lockwood@networkedweb.com"}]' \ + --push \ + --build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN --build-arg CI_PROJECT_ID=$CI_PROJECT_ID --build-arg CI_API_V4_URL=$CI_API_V4_URL \ + --file $DOCKER_DOCKERFILE \ + --tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG; + + docker buildx imagetools inspect $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG; + + # during docker multi platform build there are >=3 additional unknown images added to gitlab container registry. cleanup + + DOCKER_MULTI_ARCH_IMAGES=$(docker buildx imagetools inspect "$DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG" --format "{{ range .Manifest.Manifests }}{{ if ne (print .Platform) \"&{unknown unknown [] }\" }}$DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG@{{ println .Digest }}{{end}} {{end}}"); + + docker buildx imagetools create $DOCKER_MULTI_ARCH_IMAGES --tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG; + + docker buildx imagetools inspect $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG; + + else + + echo "[DEBUG] building image"; + + docker build . \ + --label org.opencontainers.image.created="$(date '+%Y-%m-%dT%H:%M:%S%:z')" \ + --label org.opencontainers.image.description="An Ansible Execution Environment" \ + --label org.opencontainers.image.documentation="$CI_PROJECT_URL" \ + --label org.opencontainers.image.source="$CI_PROJECT_URL" \ + --label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \ + --label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \ + --label org.opencontainers.image.revision="$CI_COMMIT_SHA" \ + --label io.artifacthub.package.readme-url="$CI_PROJECT_URL/-/raw/development/README.md?ref_type=heads" \ + --label io.artifacthub.package.maintainers='[{"name":"No Fuss Computing","email":"helpdesk@nofusscomputing.com"}, {"name":"jon_nfc","email":"jonathon.lockwood@networkedweb.com"}]' \ + --build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN --build-arg CI_PROJECT_ID=$CI_PROJECT_ID --build-arg CI_API_V4_URL=$CI_API_V4_URL \ + --file $DOCKER_DOCKERFILE \ + --tag $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG; + + docker push $DOCKER_IMAGE_BUILD_REGISTRY/$DOCKER_IMAGE_BUILD_NAME:$DOCKER_IMAGE_BUILD_TAG; + + fi + rules: + + - if: # condition_git_tag + $CI_COMMIT_TAG != null && + $CI_COMMIT_BRANCH == null + exists: + - '{dockerfile,dockerfile.j2}' + when: on_success + + - if: # condition_dev_branch_push + $CI_COMMIT_BRANCH == "development" && + $CI_PIPELINE_SOURCE == "push" + exists: + - '{dockerfile,dockerfile.j2}' + changes: + paths: + - '{dockerfile,dockerfile.j2,includes/**/*}' + compare_to: 'master' + when: always + + - if: # condition_not_master_or_dev_push + $CI_COMMIT_BRANCH != "master" && + $CI_COMMIT_BRANCH != "development" && + $CI_PIPELINE_SOURCE == "push" + exists: + - '{dockerfile,dockerfile.j2}' + changes: + paths: + - '{dockerfile,dockerfile.j2,includes/**/*}' + compare_to: 'development' + when: always + + - when: never + + + .MKDocs_Build: image: python:3.11-buster diff --git a/README.md b/README.md index 8c7ff4a..66715ff 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ ![Project Status - Active](https://img.shields.io/badge/Project%20Status-Active-green?logo=gitlab&style=plastic) +[![Docker Pulls](https://img.shields.io/docker/pulls/nofusscomputing/ansible-ee?style=plastic&logo=docker&color=0db7ed)](https://hub.docker.com/r/nofusscomputing/ansible-ee) [![Artifact Hub](https://img.shields.io/endpoint?style=plastic&url=https://artifacthub.io/badge/repository/nfc-ansible-ee)](https://artifacthub.io/packages/search?repo=nfc-ansible-ee) +
![Gitlab forks count](https://img.shields.io/badge/dynamic/json?label=Forks&query=%24.forks_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F45741845%2F&color=ff782e&logo=gitlab&style=plastic) ![Gitlab stars](https://img.shields.io/badge/dynamic/json?label=Stars&query=%24.star_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F45741845%2F&color=ff782e&logo=gitlab&style=plastic) [![Open Issues](https://img.shields.io/badge/dynamic/json?color=ff782e&logo=gitlab&style=plastic&label=Open%20Issues&query=%24.statistics.counts.opened&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F45741845%2Fissues_statistics)](https://gitlab.com/nofusscomputing/projects/ansible/execution_environment/-/issues)