-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (100 loc) · 4.04 KB
/
aws_prod_release.yml
File metadata and controls
118 lines (100 loc) · 4.04 KB
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
name: AWS-Build-Push-Prod
on:
release:
types: [published]
env:
REPOSITORY: 'sdk-prod'
ECS_Cluster: "topia-prod-sdk-apps"
ENV: "prod"
reponame: "${{ github.event.repository.name }}"
concurrency:
group: ${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
Build:
runs-on: ubuntu-latest
outputs:
service: ${{ steps.sername.outputs.service }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
- name: get servicename
id: sername
run: |
service_value=$(jq -c ".\"$reponame\"" <<< '${{ vars.repo_service_map }}')
echo "$(echo $service_value | jq -c)"
if [[ $service_value == null ]]; then
echo "Service value from map is missing. Using repository name instead."
echo "service=[\""$reponame"\"]" >> "$GITHUB_OUTPUT"
elif [[ -n "$service_value" && $(echo "$service_value" | jq 'length == 0') == "true" ]]; then
echo "The app has no service deployed"
echo "service=[]" >> "$GITHUB_OUTPUT"
else
echo "service=$service_value" >> "$GITHUB_OUTPUT"
echo "Service value: $(echo $service_value | jq -c )"
fi
- uses: actions/setup-node@v4
with:
node-version: 20.10
cache: 'npm'
- run: git config --global user.email devops@topia.io
- run: git config --global user.name Devops
- run: npm version --no-git-tag-version --workspaces --include-workspace-root true ${{ github.event.release.tag_name }}
- run: npm i
- run: CI=false npm run build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.0.0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::368076259134:role/github-actions-role
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Image Metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }}
tags: |
type=raw,value=${{ github.event.repository.name }}-${{ github.event.release.tag_name }}
- name: Image Metadata
id: metadata-latest
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }}
tags: |
type=raw,value=${{ github.event.repository.name }}-latest
- name: Build and version tag
run: |
docker build --build-arg REF=${{ github.ref}} --build-arg COMMIT_HASH=$(git rev-parse --short ${{ github.sha }}) -t ${{ steps.metadata.outputs.tags }} .
docker tag ${{ steps.metadata.outputs.tags }} ${{ steps.metadata-latest.outputs.tags }}
- name: push docker image to Amazon ECR
run: |
docker push ${{ steps.metadata.outputs.tags }}
docker push ${{ steps.metadata-latest.outputs.tags }}
deploy_matrix:
runs-on: ubuntu-latest
needs: Build
strategy:
matrix:
service: ${{ fromJson(needs.Build.outputs.service) }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::471112828260:role/github-actions-role
aws-region: us-east-1
- name: deploy
run: |
aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment