-
Notifications
You must be signed in to change notification settings - Fork 19
172 lines (148 loc) · 6.13 KB
/
image+upload.yaml
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build and Deploy
on:
push:
tags:
- "**"
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
tag_date: ${{ steps.hash.outputs.date }}
tag_git_hash: ${{ steps.hash.outputs.git_hash }}
service: ${{ steps.extract_tags.outputs.service }}
version: ${{ steps.extract_tags.outputs.version }}
ecr_url: ${{ steps.extract_tags.outputs.ecr_url }}
steps:
- uses: actions/checkout@master
- name: get date and git hash
id: hash
run: |
echo "date=$(date +'%Y%m%d.%H%M')" >> $GITHUB_OUTPUT
echo "git_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Check if ref is a tag
id: check_tag
run: |
echo "Tag name from GITHUB_REF_NAME: $GITHUB_REF_NAME"
echo "tag: ${{github.ref_name}}"
if [ "${GITHUB_REF_TYPE}" != "tag" ]; then
echo "This workflow only processes tags. Exiting."
exit 0
fi
- name: extract version and service from tag
id: extract_tags
run: |
tag_ref=${GITHUB_REF#refs/tags/}
echo "Tag: $tag_ref"
# Extract service name and version from the tag (e.g., service_name/v1.2.3)
if [[ $tag_ref =~ ^([a-zA-Z0-9_]+)/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
service="${BASH_REMATCH[1]}"
version="${BASH_REMATCH[2]}"
echo "Found service: $service"
echo "Found version: $version"
echo "service=${service}" >> $GITHUB_OUTPUT
echo "version=${version}" >> $GITHUB_OUTPUT
echo "ecr_url=public.ecr.aws/bisonai/orakl-${service}" >> $GITHUB_OUTPUT
else
echo "Tag does not match the pattern."
exit 1
fi
build:
name: Build
runs-on: ubuntu-latest
needs: prepare
permissions:
id-token: write
contents: read
outputs:
img_tag: ${{ steps.img-tag.outputs.img_tag }}
steps:
- uses: actions/checkout@master
- name: docker build ${{ needs.prepare.outputs.service }}
run: SERVICE_NAME=orakl-${{ needs.prepare.outputs.service }} docker compose -f docker-compose.build.yaml build
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.ROLE_ARN }}
- name: login to amazon ecr
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public
- name: publish image to ecr
run: |
docker tag orakl-${{ needs.prepare.outputs.service }} ${{ needs.prepare.outputs.ecr_url }}:latest
docker push ${{ needs.prepare.outputs.ecr_url }}:latest
docker tag ${{ needs.prepare.outputs.ecr_url }}:latest ${{ needs.prepare.outputs.ecr_url }}:v${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }}
docker push ${{ needs.prepare.outputs.ecr_url }}:v${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }}
- name: image tag output
id: img-tag
run: echo "img_tag=v${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }}" >> $GITHUB_OUTPUT
post-slack-image-upload:
name: Slack message for image upload
needs: [prepare, build]
uses: ./.github/workflows/post.slack.yaml
with:
status: "Success"
slack-message: "*${{ needs.prepare.outputs.service }}* ${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }} is uploaded"
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
if: ${{ success() }}
image-update:
name: Update image tag
needs: [prepare, build]
uses: ./.github/workflows/update.image-tag.yaml
with:
network: "baobab"
project-name: ${{ needs.prepare.outputs.service }}
version: ${{ needs.prepare.outputs.version }}
image-tag: ${{ needs.build.outputs.img_tag }}
tag_date: ${{ needs.prepare.outputs.tag_date }}
tag_git_hash: ${{ needs.prepare.outputs.tag_git_hash }}
secrets:
PAT: ${{ secrets.PAT }}
update-package-json-version:
name: Update package.json version
needs: [prepare, build, image-update]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: update package.json version
if: needs.prepare.outputs.version
run: |
version=${{ needs.prepare.outputs.version }}
sed -i 's/"version": "[^"]*"/"version": "'$version'"/' cli/package.json
echo "updating package.json to version $version"
npm version $version --no-git-tag-version
- name: commit updated package.json
if: needs.prepare.outputs.version
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git add package.json
git commit -m "chore: update package.json version to ${{ needs.prepare.outputs.version }}"
git push -f --tags origin HEAD:${{ github.ref_name }}
post-slack-tag-update-success:
name: Post slack message for tag update success
needs: [prepare, build, image-update]
uses: ./.github/workflows/post.slack.yaml
if: ${{ success() }}
with:
status: "Success"
slack-message: "*${{ needs.prepare.outputs.service }}* new image tag ${{ needs.prepare.outputs.version }}.${{ needs.prepare.outputs.tag_date }}.${{ needs.prepare.outputs.tag_git_hash }} is updated"
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
post-slack-tag-update-failure:
name: Post to a slack message for tag update failure
needs: [prepare, build, image-update]
if: ${{ failure() }}
uses: ./.github/workflows/post.slack.yaml
with:
status: "Failed"
slack-message: "Git action failed"
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}