Skip to content

Commit be20b8b

Browse files
committed
OpenConceptLab/ocl_issues#2240 | GHA for prod deployment
1 parent 4dfa9e5 commit be20b8b

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
ECS_CLUSTER_QA: "ocl-qa-demo" # set this to your Amazon ECS cluster name
1313
ECS_SERVICE_STAGING: "staging-map" # set this to your Amazon ECS service name
1414
ECS_CLUSTER_STAGING_PRODUCTION: "ocl-staging-production" # set this to your Amazon ECS cluster name
15+
ECS_SERVICE_PRODUCTION: "production-map" # set this to your Amazon ECS service name
1516

1617

1718
jobs:
@@ -247,3 +248,56 @@ jobs:
247248
task-definition: ${{ steps.task-def.outputs.task-definition }}
248249
service: ${{ env.ECS_SERVICE_STAGING }}
249250
cluster: ${{ env.ECS_CLUSTER_STAGING_PRODUCTION }}
251+
deploy-production:
252+
needs: [deploy-staging]
253+
name: Deploy to Production
254+
runs-on: ubuntu-latest
255+
environment: production
256+
257+
steps:
258+
- name: Configure AWS credentials
259+
uses: aws-actions/configure-aws-credentials@v1
260+
with:
261+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
262+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
263+
aws-region: ${{ env.AWS_REGION }}
264+
- name: Login to Amazon ECR
265+
id: login-ecr
266+
uses: aws-actions/amazon-ecr-login@v1
267+
- name: Checkout repo
268+
uses: actions/checkout@v3
269+
- name: Get npm version
270+
id: package-version
271+
uses: martinbeentjes/npm-get-version-action@v1.3.1
272+
- name: Add GITHUB_SHA_SHORT env property with commit short sha
273+
run: echo "GITHUB_SHA_SHORT=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
274+
- name: Push image to Amazon ECR
275+
id: push-image
276+
env:
277+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
278+
IMAGE_TAG: ${{ steps.package-version.outputs.current-version}}-${{env.GITHUB_SHA_SHORT}}
279+
run: |
280+
# Build a docker container and
281+
# push it to ECR so that it can
282+
# be deployed to ECS.
283+
docker pull openconceptlab/oclmap:$IMAGE_TAG
284+
docker tag openconceptlab/oclmap:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production
285+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production
286+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
287+
- name: Download task definition
288+
run: |
289+
aws ecs describe-task-definition --task-definition $ECS_SERVICE_PRODUCTION --query taskDefinition > task-definition.json
290+
- name: Fill in the new image ID in the Amazon ECS task definition
291+
id: task-def
292+
uses: aws-actions/amazon-ecs-render-task-definition@v1
293+
with:
294+
task-definition: "task-definition.json"
295+
container-name: ${{ env.ECS_SERVICE_PRODUCTION }}
296+
image: ${{ steps.push-image.outputs.image }}
297+
298+
- name: Deploy Amazon ECS task definition
299+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
300+
with:
301+
task-definition: ${{ steps.task-def.outputs.task-definition }}
302+
service: ${{ env.ECS_SERVICE_PRODUCTION }}
303+
cluster: ${{ env.ECS_CLUSTER_STAGING_PRODUCTION }}

0 commit comments

Comments
 (0)