-
Notifications
You must be signed in to change notification settings - Fork 122
152 lines (133 loc) · 4.55 KB
/
Copy pathmono-engine-deploy.yml
File metadata and controls
152 lines (133 loc) · 4.55 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
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
name: Mono Engine deploy
on:
push:
branches:
- main
paths:
- ".github/workflows/mono-engine-deploy.yml"
- "api-model/**"
- "ceres/**"
- "common/**"
- "context/**"
- "io-orbit/**"
- "jupiter/**"
- "mono/**"
- "saturn/**"
- "vault/**"
- "Cargo.toml"
env:
REGISTRY_ALIAS: m8q5m4u3
REPOSITORY: mega/mono-engine
IMAGE_TAG_BASE: latest
# Using AWS access key for authentication
permissions:
id-token: write
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-push-single-arch:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# -----------------------------
# AWS / ECR Public
# -----------------------------
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
# -----------------------------
# Build & push to ECR
# -----------------------------
- name: Build & push image to ECR (amd64)
env:
ECR_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
IMAGE_TAG_BASE: ${{ env.IMAGE_TAG_BASE }}
run: |
set -euo pipefail
ARCH_SUFFIX=amd64
IMAGE_TAG="${IMAGE_TAG_BASE}-${ARCH_SUFFIX}"
ECR_IMAGE="$ECR_REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}:$IMAGE_TAG"
ECR_CACHE_IMAGE="$ECR_REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}:buildcache-${ARCH_SUFFIX}"
CACHE_SCOPE="mono-engine-${ARCH_SUFFIX}"
echo "ECR_IMAGE=$ECR_IMAGE"
echo "ECR_CACHE_IMAGE=$ECR_CACHE_IMAGE"
echo "CACHE_SCOPE=$CACHE_SCOPE"
docker buildx build \
--cache-from type=gha,scope=$CACHE_SCOPE \
--cache-to type=gha,mode=max,scope=$CACHE_SCOPE \
--provenance=false \
--sbom=false \
-f ./mono/Dockerfile \
-t "$ECR_IMAGE" \
--push .
manifest:
needs: build-push-single-arch
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Create & push manifest
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
run: |
set -euo pipefail
IMAGE_BASE="$REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}"
SHORT_SHA="${GITHUB_SHA:0:7}"
# latest manifest
docker manifest create "$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}" \
"$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-amd64" \
"$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-arm64"
docker manifest push "$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}"
# commit-hash manifest (same digests as latest for this commit)
docker manifest create "$IMAGE_BASE:$SHORT_SHA" \
"$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-amd64" \
"$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-arm64"
docker manifest push "$IMAGE_BASE:$SHORT_SHA"
deploy-aws:
needs: manifest
if: ${{ github.repository == 'gitmono-dev/mega' }}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
include:
- cluster: gitmega-com
service: mono-engine-dev-service-xnmoxhxb
- cluster: gitmono-com-mega-app
service: mono-engine
steps:
- name: Force ECS redeploy
run: |
aws ecs update-service \
--cluster ${{ matrix.cluster }} \
--service ${{ matrix.service }} \
--force-new-deployment
env:
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}