-
-
Notifications
You must be signed in to change notification settings - Fork 2
184 lines (159 loc) · 8.21 KB
/
main.yml
File metadata and controls
184 lines (159 loc) · 8.21 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
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
name: BuildEngine CI
on:
push:
branches: [master, develop, github-builds]
pull_request:
workflow_dispatch:
inputs:
logLevel:
description: "Log Level"
required: true
default: "warning"
tags:
description: "Tags"
schedule:
- cron: "0 0 * * 0" # weekly
env:
BUILD_TAG: "build-engine-api:${{ github.run_number }}"
BUILD_NUMBER: ${{ github.run_number }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get environment info
run: |
echo Docker version
docker --version
echo
echo Env
env
- name: Setup local.env
run: |
echo "COMPOSER_AUTH={\"github-oauth\":{\"github.com\":\""${{ secrets.GITHUB_TOKEN }}\""}}" > local.env
- name: Install dependencies
run: |
echo "Installing ecs-deploy script..."
mkdir -p $HOME/.local/bin
curl -o $HOME/.local/bin/ecs-deploy https://raw.githubusercontent.com/silinternational/ecs-deploy/master/ecs-deploy
chmod +x $HOME/.local/bin/ecs-deploy
- name: Tests
run: |
make test
- name: Build docker image
uses: docker/build-push-action@v4
with:
push: false
tags: ${{ env.BUILD_TAG }}
context: .
load: true
- name: Determine branch tag
id: branch
run: |
if [[ "${GITHUB_HEAD_REF}" != "" ]]; then BRANCH="${GITHUB_HEAD_REF}"; else BRANCH="${GITHUB_REF_NAME}"; fi
case $BRANCH in develop) DOCKER_TAG="staging" ;; master) DOCKER_TAG="production" ;; *) DOCKER_TAG="${BRANCH//\//-}" ;; esac
case $BRANCH in develop) ECS_CLUSTER="scriptoria-stg";; master) ECS_CLUSTER="scriptoria-prd" ;; *) ECS_CLUSTER="none" ;; esac
echo "DockerTag=${DOCKER_TAG}" >> $GITHUB_OUTPUT
echo "EcsCluster=${ECS_CLUSTER}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GHCR
run: |
docker tag ${{ env.BUILD_TAG }} ghcr.io/sillsdev/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}
docker push ghcr.io/sillsdev/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}
- name: Configure AWS credentials (SIL)
id: aws_sil
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.SIL__AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SIL__AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.SIL__AWS_DEFAULT_REGION }}
- name: Login to AWS ECR (SIL)
id: ecr_sil
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ secrets.SIL__AWS_ECR_ACCOUNT }}
- name: Push to AWS ECR (SIL)
run: |
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
- name: Deploy to ECS (SIL)
if: ${{ steps.branch.outputs.EcsCluster != 'none' }}
run: |
echo "Deploying ${{ env.BUILD_NUMBER }} to ${{ steps.branch.outputs.EcsCluster }}"
# Deploy to ECS cluster with service name 'build-engine', setting all images to the latest tag
ecs-deploy -c ${{ steps.branch.outputs.EcsCluster }} -n buildengine -i ignore -to ${{ env.BUILD_NUMBER }} --max-definitions 20 --timeout 600
echo "Deployment initiated successfully."
- name: Configure AWS credentials (FCBH)
if: false # Temporarily disabled - remove this line to re-enable
# if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-prd' }} # Restore this when re-enabling
id: aws_fcbh
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.FCBH__AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.FCBH__AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.FCBH__AWS_DEFAULT_REGION }}
- name: Login to AWS ECR (FCBH)
if: false # Temporarily disabled - remove this line to re-enable
# if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-prd' }} # Restore this when re-enabling
id: ecr_fcbh
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ secrets.FCBH__AWS_ECR_ACCOUNT }}
- name: Push to AWS ECR (FCBH)
if: false # Temporarily disabled - remove this line to re-enable
# if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-prd' }} # Restore this when re-enabling
run: |
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
docker push "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
docker push "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
- name: Deploy to ECS (FCBH)
if: false # Temporarily disabled - remove this line to re-enable
# if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-prd' }} # Restore this when re-enabling
run: |
echo "Deploying ${{ env.BUILD_NUMBER }} to ${{ steps.branch.outputs.EcsCluster }}"
# Deploy to ECS cluster with service name 'build-engine', setting all images to the latest tag
ecs-deploy -c ${{ steps.branch.outputs.EcsCluster }} -n buildengine -i ignore -to ${{ env.BUILD_NUMBER }} --max-definitions 20 --timeout 600
echo "Deployment initiated successfully."
- name: Configure AWS credentials (LU)
if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-stg' }}
id: aws_lu
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.LU__AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.LU__AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.LU__AWS_DEFAULT_REGION }}
- name: Login to AWS ECR (LU)
if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-stg' }}
id: ecr_lu
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ secrets.LU__AWS_ECR_ACCOUNT }}
- name: Push to AWS ECR (LU)
if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-stg' }}
run: |
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
docker push "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
docker push "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
- name: Deploy to ECS (LU)
if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-stg' }}
run: |
echo "Deploying ${{ env.BUILD_NUMBER }} to ${{ steps.branch.outputs.EcsCluster }}"
# Deploy to ECS cluster with service name 'build-engine', setting all images to the latest tag
ecs-deploy -c ${{ steps.branch.outputs.EcsCluster }} -n buildengine -i ignore -to ${{ env.BUILD_NUMBER }} --max-definitions 20 --timeout 600
echo "Deployment initiated successfully."
- name: Clean up older packages
uses: actions/delete-package-versions@v4
with:
package-name: "appbuilder-buildengine-api"
package-type: "container"
min-versions-to-keep: 6
delete-only-untagged-versions: "true"