-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (94 loc) · 3.09 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Artifact Registry
on:
push:
branches:
- main
pull_request:
release:
types: [published]
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pages: write
id-token: write
attestations: write
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
ARTIFACT_REPO: public
IMAGE_NAME: eds
PLATFORM_PROJECT_ID: shopmonkey-v2
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
timeout-minutes: 2
with:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_SA_KEY }}
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Construct the tags
id: construct_tags
env:
GIT_BRANCH: ${{ steps.branch-name.outputs.current_branch }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
MERGE_SHA: ${{ github.sha }}
run: |
SHA=""
if [ "$GIT_BRANCH" = "main" ];
then
SHA=$MERGE_SHA
else
SHA=$PR_SHA
fi
echo sha=$SHA >> $GITHUB_OUTPUT
# default to the SHA
TAGS="$SHA"
VERSION="$SHA"
# if we're on the main branch, add the beta tag
if [[ $GITHUB_REF == 'refs/heads/main' ]]; then
TAGS="$TAGS beta"
fi
# if it's a release, use the version and latest tags
if [[ $GITHUB_EVENT_NAME == 'release' ]]; then
VERSION=$(echo $GITHUB_REF | sed 's/refs\/tags\///')
TAGS="$TAGS $VERSION latest"
fi
echo version=$VERSION >> $GITHUB_OUTPUT
for TAG in $TAGS; do
TAG_LIST+="us-docker.pkg.dev/${{ env.PLATFORM_PROJECT_ID }}/${{ env.ARTIFACT_REPO }}/${{ env.IMAGE_NAME }}:$TAG,"
done
# remove the trailing comma
TAG_LIST=${TAG_LIST%,}
echo tags=$TAG_LIST >> $GITHUB_OUTPUT
- name: Build and push to Artifact Registry
uses: docker/build-push-action@v6
id: push
with:
push: true
context: .
file: ./Dockerfile
tags: ${{ steps.construct_tags.outputs.tags }}
build-args: |
BUILD_DATE=${{ steps.date.outputs.date }}
GIT_BRANCH=${{ steps.branch-name.outputs.current_branch }}
GIT_SHA=${{ steps.construct_tags.outputs.sha }}
VERSION=${{ steps.construct_tags.outputs.version }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: us-docker.pkg.dev/${{ env.PLATFORM_PROJECT_ID }}/${{ env.ARTIFACT_REPO }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true