Skip to content

Commit 9216648

Browse files
authored
fix: ci pipeline (#228)
* fix: build & deploy ci/cd * added aws creds to gh action * updating ci config * fix config * syntax fix * fixing sts token issue * added permissions * typo fixed * ecs deploy fix * syntax fix * ecs task def updated * typo fix * testing tags var * testing tags var * gh action workflow completed
1 parent d253c50 commit 9216648

File tree

3 files changed

+34
-55
lines changed

3 files changed

+34
-55
lines changed

.github/workflows/build_prod.yml renamed to .github/workflows/build-deploy-prod.yml

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
# Copyright 2020 ChainSafe Systems
22
# SPDX-License-Identifier: LGPL-3.0-only
33

4-
name: Build & Push Docker Image to AWS ECR
4+
name: Build & Deploy PROD
55

66
on:
77
push:
8-
branches:
9-
- main
8+
tags:
9+
- 'v*'
10+
workflow_dispatch:
1011

1112
env:
1213
AWS_REGION: ${{ secrets.AWS_REGION }}
1314
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
14-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
15-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
1615
ECR_REPO: ${{ secrets.AWS_ECR_REPO }}
17-
16+
ECS_CLUSTER: ${{ secrets.AWS_ECS_CLUSTER }}
17+
ECS_SERVICE: ${{ secrets.AWS_ECS_SERVICE }}
18+
ENVIRONMENT: PROD
19+
1820
jobs:
1921
build:
20-
name: build_prod
22+
name: build_deploy_prod
2123
runs-on: ubuntu-latest
24+
permissions:
25+
id-token: write
26+
contents: write
2227

2328
steps:
2429
# download the source code into the runner
2530
- name: checkout
2631
uses: actions/checkout@v2
27-
28-
- name: short sha
32+
33+
- name: Set output
2934
id: vars
30-
run: echo "::set-output name=sha::$(git rev-parse --short HEAD)"
35+
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
36+
37+
- name: Configure AWS credentials
38+
uses: aws-actions/configure-aws-credentials@v1
39+
with:
40+
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-role
41+
aws-region: ${{ env.AWS_REGION }}
3142

3243
# gather metadata from git & github actions to reference in docker
3344
- name: git & github metadata
@@ -48,5 +59,15 @@ jobs:
4859
file: ./Dockerfile
4960
push: true
5061
tags: |
51-
${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.AWS_ECR_REPO }}:latest
52-
${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.AWS_ECR_REPO }}:${{ steps.vars.outputs.sha }}
62+
${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPO }}:latest
63+
${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPO }}:${{ steps.vars.outputs.tag }}
64+
65+
# deploy to AWS ECS
66+
- name: Deploy to Amazon ECS
67+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
68+
with:
69+
task-definition: infra/aws-ecs/task_definition_${{ env.ENVIRONMENT }}.json
70+
service: ${{ env.ECS_SERVICE }}
71+
cluster: ${{ env.ECS_CLUSTER }}
72+
wait-for-service-stability: true
73+

.github/workflows/deploy_prod.yml

-42
This file was deleted.

infra/aws-ecs/task_definition_PROD.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"containerDefinitions": [
44
{
55
"name": "nodewatch-prod-container",
6-
"image": "381177214925.dkr.ecr.us-east-2.amazonaws.com/nodewatch-prod-ecr:v1.3.1",
6+
"image": "381177214925.dkr.ecr.us-east-2.amazonaws.com/nodewatch-prod-ecr",
77
"cpu": 256,
88
"portMappings": [
99
{

0 commit comments

Comments
 (0)