name: Build and Push on: push: branches: [main] tags: ["v*"] workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Derive image reference id: img run: | echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT echo "sha_short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v3 with: registry: ${{ vars.REGISTRY_URL }} username: ${{ github.actor }} password: ${{ secrets.REGISTRY_TOKEN }} - name: Compute tags id: tags run: | IMAGE="${{ vars.REGISTRY_URL }}/${{ steps.img.outputs.name }}" TAGS="${IMAGE}:${{ steps.img.outputs.sha_short }}" if [ "${{ github.ref }}" = "refs/heads/main" ]; then TAGS="${TAGS},${IMAGE}:latest" fi if [[ "${{ github.ref }}" == refs/tags/v* ]]; then TAGS="${TAGS},${IMAGE}:${GITHUB_REF_NAME}" fi echo "tags=${TAGS}" >> $GITHUB_OUTPUT - uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.tags.outputs.tags }} cache-from: type=registry,ref=${{ vars.REGISTRY_URL }}/${{ steps.img.outputs.name }}:buildcache cache-to: type=registry,ref=${{ vars.REGISTRY_URL }}/${{ steps.img.outputs.name }}:buildcache,mode=max