Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
yajith committed Sep 24, 2024
1 parent c72c7df commit 0e85823
Showing 1 changed file with 51 additions and 84 deletions.
135 changes: 51 additions & 84 deletions .github/workflows/portainer-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
- name: "[preparation] set up qemu"
uses: docker/setup-qemu-action@v3.2.0

- name: "[preparation] set up docker context for buildx"
run: docker context create builders

- name: "[preparation] set up docker buildx"
uses: docker/setup-buildx-action@v3.6.1
with:
Expand All @@ -48,107 +45,77 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: "[preparation] set the container image tag"
run: |
# set the container image tag prefix
if [[ "${GITHUB_REF_NAME}" =~ ^release/.*$ ]]; then
# use the release branch name as the tag for release branches
# for instance, release/2.19 becomes 2.19
TAG_PREFIX=$(echo $GITHUB_REF_NAME | cut -d "/" -f 2)
elif [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
# use pr${{ github.event.number }} as the tag for pull requests
# for instance, pr123
TAG_PREFIX="pr${{ github.event.number }}"
else
# replace / with - in the branch name
# for instance, feature/1.0.0 -> feature-1.0.0
TAG_PREFIX=$(echo $GITHUB_REF_NAME | sed 's/\//-/g')
fi
# set the container image tag suffix
TAG_SUFFIX="${{ matrix.config.platform }}${{ matrix.config.version }}-${{ matrix.config.arch }}"
# set the container image tag
echo "CONTAINER_IMAGE_TAG=${TAG_PREFIX}-${TAG_SUFFIX}" >> $GITHUB_ENV
- name: "[metadata] generate image tags"
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.DOCKER_HUB_REPO }}
tags: |
type=ref,event=branch
type=ref,event=pr
- name: "build and push images - linux"
if: ${{ matrix.config.platform == 'linux' }}
- name: "[build] build and push by digest"
id: build
uses: docker/build-push-action@v6.7.0
with:
context: .
tags: ${{ env.DOCKER_HUB_REPO }}:${{ env.CONTAINER_IMAGE_TAG }}
build-args: |
GIT_COMMIT=$(git log -1 --format=%h)
platforms: ${{ matrix.config.platform }}/${{ matrix.config.arch }}
file: build/${{ matrix.config.platform }}/Dockerfile
sbom: true
provenance: true
push: true

- name: "build and push images - windows"
if: ${{ matrix.config.platform == 'windows' }}
uses: docker/build-push-action@v6.7.0
with:
context: .
tags: ${{ env.DOCKER_HUB_REPO }}:${{ env.CONTAINER_IMAGE_TAG }}
build-args: |
GIT_COMMIT=$(git log -1 --format=%h)
OSVERSION=${{ matrix.config.version }}
platforms: ${{ matrix.config.platform }}/${{ matrix.config.arch }}
file: build/${{ matrix.config.platform }}/Dockerfile
sbom: true
provenance: true
push: true
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.DOCKER_HUB_REPO }},push-by-digest=true,name-canonical=true,push=true

- name: "[build] export digest"
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: "[build] upload digest"
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

build_manifests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
needs: [build_images]
steps:
- name: '[preparation] docker login'
uses: docker/login-action@v3.0.0
- name: "[preparation] download digests"
uses: actions/download-artifact@v4
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: '[preparation] set up docker context for buildx'
run: docker version && docker context create builders
- name: "[metadata] generate image tags"
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.DOCKER_HUB_REPO }}

- name: '[preparation] set up docker buildx'
- name: "[preparation] set up docker buildx"
uses: docker/setup-buildx-action@v3.0.0
with:
endpoint: builders
driver-opts: image=moby/buildkit:v0.16.0

- name: "[preparation] set the container image tag"
run: |
# set the container image tag prefix
if [[ "${GITHUB_REF_NAME}" =~ ^release/.*$ ]]; then
# use the release branch name as the tag for release branches
# for instance, release/2.19 becomes 2.19
TAG_PREFIX=$(echo $GITHUB_REF_NAME | cut -d "/" -f 2)
elif [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
# use pr${{ github.event.number }} as the tag for pull requests
# for instance, pr123
TAG_PREFIX="pr${{ github.event.number }}"
else
# replace / with - in the branch name
# for instance, feature/1.0.0 -> feature-1.0.0
TAG_PREFIX=$(echo $GITHUB_REF_NAME | sed 's/\//-/g')
fi
# set the container image tag prefix
echo "TAG_PREFIX=${TAG_PREFIX}" >> $GITHUB_ENV
- name: "[preparation] docker login"
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: '[execution] build and push manifests'
- name: "[build] create manifest list and push"
working-directory: /tmp/digests
run: |
# Create image manifest
docker manifest create "${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}" \
"${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}-linux-amd64" \
"${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}-linux-arm64" \
"${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}-linux-arm" \
"${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}-linux-ppc64le" \
"${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}-windowsltsc2022-amd64" \
"${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}-windows1809-amd64"
# Push image manifest to publish
docker manifest push "${{ env.DOCKER_HUB_REPO }}:${TAG_PREFIX}"
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.DOCKER_HUB_REPO }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 comments on commit 0e85823

Please sign in to comment.