name: Build and Push Docker Image on: push: branches: - development workflow_dispatch: inputs: tag_name: description: "Custom tag name for the Docker image" required: false default: "" jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: buildkitd-flags: --debug driver-opts: | image=moby/buildkit:v0.12.0 - name: Cache Docker layers uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - name: Login to Docker Registry uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Determine Docker image tag run: | echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV if [ "${{ github.event.inputs.tag_name }}" == "" ]; then IMAGE_TAG="${{ github.ref_name }}-development-latest" else IMAGE_TAG="${{ github.event.inputs.tag_name }}" fi echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV - name: Build and Push Multi-Arch Docker Image uses: docker/build-push-action@v4 with: context: . file: ./docker/Dockerfile push: true platforms: linux/amd64,linux/arm64 tags: ghcr.io/${{ env.REPO_OWNER }}/termix:${{ env.IMAGE_TAG }} labels: org.opencontainers.image.source=https://github.com/${{ github.repository }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max build-args: | BUILDKIT_INLINE_CACHE=1 # Temp fix for https://github.com/docker/build-push-action/issues/252 - name: Move cache run: | rm -rf /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache - name: Notify via ntfy run: | curl -d "Docker image build and push completed successfully for tag: ${{ env.IMAGE_TAG }}" \ https://ntfy.karmaa.site/termix-build - name: Delete all untagged image versions uses: quartx-analytics/ghcr-cleaner@v1 with: owner-type: user token: ${{ secrets.GHCR_TOKEN }} repository-owner: ${{ github.repository_owner }} delete-untagged: true - name: Cleanup Docker Images Locally run: | docker image prune -af docker system prune -af --volumes