Skip to content

Commit

Permalink
chore: update build-push workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Lor committed Nov 4, 2023
1 parent f7c0488 commit 9b4f633
Showing 1 changed file with 22 additions and 46 deletions.
68 changes: 22 additions & 46 deletions .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

0 comments on commit 9b4f633

Please sign in to comment.