From 9b4f63386f0c5b7e63c9a20f2ee786db2e7e277d Mon Sep 17 00:00:00 2001 From: David-Lor <17401854+David-Lor@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:53:22 +0100 Subject: [PATCH] chore: update build-push workflow --- .github/workflows/build-push.yaml | 68 ++++++++++--------------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/.github/workflows/build-push.yaml b/.github/workflows/build-push.yaml index dd2423b..e9d346d 100644 --- a/.github/workflows/build-push.yaml +++ b/.github/workflows/build-push.yaml @@ -1,19 +1,21 @@ name: "Build & Push" on: - push: - branches: - - main - - develop workflow_dispatch: inputs: - tag_version: - description: "Tag-Version to upload the image" + image_tag_version: + description: "Image tag versions (comma-separated)" required: true jobs: build-push: name: "[${{ matrix.app }}] Build & Push" runs-on: ubuntu-latest + env: + IMAGE_TAG_BASE: "ghcr.io/david-lor/${{ matrix.app }}-gui" + IMAGE_TAG_INTERNAL: "${{ matrix.app }}-gui" + permissions: + packages: write + contents: read strategy: fail-fast: false matrix: @@ -29,51 +31,25 @@ jobs: with: fetch-depth: 1 - # Set Docker image tag - - name: "Docker image tag version (on main branch push) to file" - if: github.ref == 'refs/heads/main' - run: echo latest > /tmp/docker_tag_version.txt - - name: "Docker image tag version (on develop branch push) to file" - if: github.ref == 'refs/heads/develop' - run: echo dev > /tmp/docker_tag_version.txt - - name: "Docker image tag version (on workflow dispatch) to file" - if: github.event.inputs.tag_version - run: echo ${{ github.event.inputs.tag_version }} > /tmp/docker_tag_version.txt - - name: "Read extracted image tag version from file" - id: get_docker_tag_version_from_file - uses: juliangruber/read-file-action@v1 - with: - path: /tmp/docker_tag_version.txt - - name: "Set image tag version to variable" - id: get_image_tag_version - run: echo ::set-output name=VERSION::$(echo ${{ steps.get_docker_tag_version_from_file.outputs.content }}) - - name: "Validate image tag version" - run: test ${{ steps.get_image_tag_version.outputs.VERSION }} || exit 1 - - name: "Set complete image tag" - id: get_image_tag - run: echo ::set-output name=TAG::$(echo ghcr.io/david-lor/${{ matrix.app }}-gui:${{ steps.get_image_tag_version.outputs.VERSION }}) - - name: "Validate final image tag" - run: |- - test ${{ steps.get_image_tag.outputs.TAG }} || exit 1 - [[ ${{ steps.get_image_tag.outputs.TAG }} =~ ^.+:.+$ ]] || exit 1 - - # Docker login + # Registry login - name: "Login to GitHub Container Registry" - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # Build & Push - - name: "Docker cache" - uses: satackey/action-docker-layer-caching@v0.0.11 - continue-on-error: true - with: - key: docker-cache-${{ matrix.app }}-{hash} - restore-keys: | - docker-cache-${{ matrix.app }}- - name: "Docker build" - run: docker build ./${{ matrix.app }} -t ${{ steps.get_image_tag.outputs.TAG }} - - name: "Docker push" - run: docker push ${{ steps.get_image_tag.outputs.TAG }} + working-directory: ${{ matrix.app }} + run: docker build . -t ${{ env.IMAGE_TAG_INTERNAL }} + - name: "Docker push tags" + run: | + for image_tag_version in $(echo "${{ github.event.inputs.image_tag_version }}" | sed "s/,/ /g") + do + IMAGE_TAG_FULL="${{ env.IMAGE_TAG_BASE }}:$image_tag_version" + echo "Tagging & Pushing image tag: $IMAGE_TAG_FULL" + + docker tag "${{ env.IMAGE_TAG_INTERNAL }}" "$IMAGE_TAG_FULL" + docker push "$IMAGE_TAG_FULL" + done