diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 2c872bd..a54fe0c 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -11,6 +11,11 @@ on: required: true type: string description: "Docker tag, e.g. latest or 1.2.3" + push_latest: + required: false + type: boolean + default: true + description: "Whether to tag and push the image as latest" jobs: build-and-push: @@ -23,8 +28,24 @@ jobs: uses: docker/login-action@v3 with: registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + + - name: Lowercase repo name + id: repo + run: | + echo "names_lowercase=$(echo "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + + - name: Generate tags + id: tags + run: | + TAGS="ghcr.io/${{ steps.repo.outputs.names_lowercase }}/${{ inputs.image_name }}:${{ inputs.tag }}" + if [ "${{ inputs.push_latest }}" = "true" ]; then + TAGS="${TAGS}"$'\n'"ghcr.io/${{ steps.repo.outputs.names_lowercase }}/${{ inputs.image_name }}:latest" + fi + echo "docker_tags<> $GITHUB_OUTPUT + echo "$TAGS" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -34,8 +55,6 @@ jobs: with: context: images/${{ inputs.image_name }} push: true - tags: | - ghcr.io/${{ github.repository }}/${{ inputs.image_name }}:${{ inputs.tag }} - ghcr.io/${{ github.repository }}/${{ inputs.image_name }}:latest + tags: "${{ steps.tags.outputs.docker_tags }}" cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5083eaa..face386 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,11 @@ on: description: "Tag to push (e.g. 1.2.3)" required: true type: string + push_latest: + description: "Tag and push as latest" + required: true + type: boolean + default: true permissions: contents: read @@ -25,27 +30,41 @@ jobs: parse-tag: runs-on: ubuntu-latest outputs: - image_name: ${{ steps.parse.outputs.image_name }} - tag: ${{ steps.parse.outputs.tag }} + image_name: "${{ steps.parse.outputs.image_name }}" + tag: "${{ steps.parse.outputs.tag }}" + push_latest: "${{ steps.parse.outputs.push_latest }}" steps: - - name: Parse tag or inputs + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Parse tag or inputs and validate id: parse run: | if [ "${{ github.event_name }}" = "push" ]; then REF="${{ github.ref_name }}" # e.g. bpy/v1.2.3 IMAGE="${REF%%/*}" # bpy TAG="${REF##*/v}" # 1.2.3 + PUSH_LATEST="true" else IMAGE="${{ inputs.image_name }}" TAG="${{ inputs.tag }}" + PUSH_LATEST="${{ inputs.push_latest }}" fi + + if [ ! -f "images/$IMAGE/Dockerfile" ]; then + echo "::error::Dockerfile not found at images/$IMAGE/Dockerfile. Please check your image name." + exit 1 + fi + echo "image_name=$IMAGE" >> $GITHUB_OUTPUT echo "tag=$TAG" >> $GITHUB_OUTPUT + echo "push_latest=$PUSH_LATEST" >> $GITHUB_OUTPUT build: needs: parse-tag uses: ./.github/workflows/build-image.yml secrets: inherit with: - image_name: ${{ needs.parse-tag.outputs.image_name }} - tag: ${{ needs.parse-tag.outputs.tag }} + image_name: "${{ needs.parse-tag.outputs.image_name }}" + tag: "${{ needs.parse-tag.outputs.tag }}" + push_latest: "${{ needs.parse-tag.outputs.push_latest == 'true' }}" diff --git a/images/bpy/Dockerfile b/images/bpy/Dockerfile index 237adc1..1c29a7f 100644 --- a/images/bpy/Dockerfile +++ b/images/bpy/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/catthehacker/ubuntu:act-latest +FROM ghcr.io/catthehacker/ubuntu:act-22.04 ENV DEBIAN_FRONTEND=noninteractive