-
Notifications
You must be signed in to change notification settings - Fork 14
188 lines (165 loc) · 6.44 KB
/
fileserver-container.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Build file-server container
on:
workflow_dispatch:
inputs:
fileserver_release_name:
description: 'file-server package version'
required: false
default: 'nightly'
fileserver_ref:
description: 'file-server package ref'
required: false
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build single-architecture container images
uses: flowforge/github-actions-workflows/.github/workflows/build_container_image.yml@9d655b572fffebb432b259566b68be1a7aff7ed5
with:
image_name: 'file-server'
package_dependencies: |
@flowforge/file-server
build_context: 'file-server'
npm_registry_url: ${{ vars.PUBLIC_NPM_REGISTRY_URL }}
secrets:
npm_registry_auth_token: ${{ secrets.NPM_PUBLISH_TOKEN }}
temporary_registry_token: ${{ secrets.GITHUB_TOKEN }}
build-multi-architecture:
name: Build multi-architecture container image
needs: build
uses: flowforge/github-actions-workflows/.github/workflows/merge_multiarch_images.yml@9d655b572fffebb432b259566b68be1a7aff7ed5
with:
image_name: 'file-server'
secrets:
temporary_registry_token: ${{ secrets.GITHUB_TOKEN }}
deploy-stage:
name: Deploy to staging environment
environment: stage
runs-on: ubuntu-latest
needs: build-multi-architecture
permissions:
packages: read
contents: read
steps:
- name: Set unique image tag
id: set-image-tag
run: |
echo "image_tag=nightly-$(date +%Y%m%d%H%m%S)" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_KEY }}
aws-region: eu-west-1
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Login to temporary registry
id: login-ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to ECR
uses: akhilerm/[email protected]
with:
src: ${{ needs.build-multi-architecture.outputs.image }}
dst: |
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/flowforge/file-server:nightly
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/flowforge/file-server:${{ env.image_tag }}
- name: Configure AWS credentials for EKS interaction
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_KEY }}
aws-region: eu-west-1
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/K8sAdmin
role-duration-seconds: 1200
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: 'v1.23.4'
- name: Configure kubectl
run:
aws eks update-kubeconfig --region eu-west-1 --name ${{ secrets.EKS_CLUSTER_NAME }}
- name: Update image and wait for deployment to finish
timeout-minutes: 5
run: |
kubectl -n default set image deployment/flowforge-file file-storage=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/flowforge/file-server:${{ env.image_tag }}
kubectl -n default rollout status deployment/flowforge-file
- name: Rollback failed deployment
if: failure()
run: |
kubectl -n default rollout undo deployment/flowforge-file
kubectl -n default rollout status deployment/flowforge-file
deploy-prod:
if: false
name: Deploy to production environment
environment: production
runs-on: ubuntu-latest
needs: [build-multi-architecture, deploy-stage]
permissions:
packages: read
contents: read
steps:
- name: Set unique image tag
id: set-image-tag
run: |
echo "image_tag=nightly-$(date +%Y%m%d%H%m%S)" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.PRODUCTION_AWS_ID }}
aws-secret-access-key: ${{ secrets.PRODUCTION_AWS_KEY }}
aws-region: eu-west-1
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
- name: Login to temporary registry
id: login-ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to ECR
uses: akhilerm/[email protected]
with:
src: ${{ needs.build-multi-architecture.outputs.image }}
dst: |
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/flowforge/file-server:nightly
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/flowforge/file-server:${{ env.image_tag }}
- name: Configure AWS credentials for EKS interaction
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_KEY }}
aws-region: eu-west-1
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/K8sAdmin
role-duration-seconds: 1200
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: 'v1.23.4'
- name: Configure kubectl
run:
aws eks update-kubeconfig --region eu-west-1 --name ${{ secrets.EKS_CLUSTER_NAME }}
- name: Update image and wait for deployment to finish
timeout-minutes: 5
run: |
kubectl -n default set image deployment/flowforge-file file-storage=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-1.amazonaws.com/flowforge/file-server:${{ env.image_tag }}
kubectl -n default rollout status deployment/flowforge-file
- name: Rollback failed deployment
if: failure()
run: |
kubectl -n default rollout undo deployment/flowforge-file
kubectl -n default rollout status deployment/flowforge-file