|
34 | 34 | tag:
|
35 | 35 | description: "Image tag"
|
36 | 36 | value: ${{ jobs.push.outputs.tag }}
|
| 37 | + full_tag: |
| 38 | + description: "Full image tag" |
| 39 | + value: ${{ jobs.push.outputs.full_tag }} |
37 | 40 | jobs:
|
38 | 41 | push:
|
39 | 42 | name: "Build & Push"
|
40 | 43 | runs-on: ubuntu-latest
|
41 | 44 | outputs:
|
42 | 45 | imageid: ${{ steps.build.outputs.imageid }}
|
43 |
| - tag: ${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }} |
| 46 | + tag: ${{ steps.vars.outputs.tag }} |
| 47 | + full_tag: ${{ steps.vars.outputs.full_tag }} |
44 | 48 | steps:
|
45 | 49 | - uses: actions/checkout@v4
|
46 | 50 | - name: Docker login to Google Cloud
|
47 | 51 | id: vars
|
48 | 52 | run: |
|
49 | 53 | echo "$B64_GOOGLE_KEY" | docker login -u _json_key_base64 --password-stdin https://$REGISTRY
|
50 |
| - echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 54 | + sha_short=$(git rev-parse --short HEAD) |
51 | 55 | branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
|
52 |
| - echo "branch=$(echo "$branch" | tr '/\' '-')" >> $GITHUB_OUTPUT |
| 56 | + tag="${branch}-${sha_short}" |
| 57 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 58 | + echo "full_tag=$REGISTRY/$GCP_PROJECT/$REPO:$tag" >> $GITHUB_OUTPUT |
53 | 59 | shell: bash
|
54 | 60 | env:
|
| 61 | + GCP_PROJECT: ${{ secrets.GCLOUD_PROJECT }} |
55 | 62 | B64_GOOGLE_KEY: ${{ secrets.GCLOUD_SECRET_KEY }}
|
56 | 63 | REGISTRY: ${{ inputs.registry }}
|
57 |
| - # - name: Check image |
58 |
| - # id: image_exists |
59 |
| - # continue-on-error: true |
60 |
| - # uses: cloudposse/github-action-docker-image-exists@main |
61 |
| - # with: |
62 |
| - # registry: ${{ inputs.registry }} |
63 |
| - # image_name: ${{ secrets.GCLOUD_PROJECT }}/${{ inputs.repo }} |
64 |
| - # tag: ${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }} |
| 64 | + REPO: ${{ inputs.repo }} |
| 65 | + - name: Check image |
| 66 | + id: image_exists |
| 67 | + continue-on-error: true |
| 68 | + uses: cloudposse/github-action-docker-image-exists@main |
| 69 | + with: |
| 70 | + registry: ${{ inputs.registry }} |
| 71 | + image_name: ${{ secrets.GCLOUD_PROJECT }}/${{ inputs.repo }} |
| 72 | + tag: ${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }} |
65 | 73 | - uses: docker/setup-buildx-action@v3
|
66 | 74 | if: steps.image_exists.outcome == 'failure'
|
67 | 75 | - uses: docker/build-push-action@v5
|
68 |
| - # if: steps.image_exists.outcome == 'failure' |
| 76 | + if: steps.image_exists.outcome == 'failure' |
69 | 77 | id: build
|
70 | 78 | with:
|
71 | 79 | context: ${{ inputs.context }}
|
72 | 80 | file: ${{ inputs.dockerfile }}
|
73 |
| - # cache-from: type=gha |
74 |
| - # cache-to: type=gha,mode=max |
| 81 | + cache-from: type=gha |
| 82 | + cache-to: type=gha,mode=max |
75 | 83 | push: true
|
76 | 84 | labels: |
|
77 | 85 | ci.run_id=${{ github.run_id }}
|
78 | 86 | build-args: |
|
79 | 87 | ${{ vars.BUILD_ARGS }}
|
80 | 88 | ${{ inputs.build_args }}
|
81 | 89 | tags: |
|
82 |
| - ${{ inputs.registry }}/${{ secrets.GCLOUD_PROJECT }}/${{ inputs.repo }}:${{ steps.vars.outputs.branch }}-${{ steps.vars.outputs.sha_short }} |
| 90 | + ${{ steps.vars.outputs.full_tag }} |
0 commit comments