Skip to content

Commit 2a64316

Browse files
committed
ci(aws): add aws deployment workflow
Signed-off-by: Jayne Doe <[email protected]>
1 parent 03915ac commit 2a64316

File tree

2 files changed

+95
-10
lines changed

2 files changed

+95
-10
lines changed

.github/workflows/aws.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
env:
5+
required: true
6+
type: string
7+
secrets:
8+
AWS_ACCESS_KEY_ID:
9+
required: true
10+
AWS_SECRET_ACCESS_KEY:
11+
required: true
12+
13+
name: Deploy to Amazon ECS
14+
15+
jobs:
16+
deploy:
17+
name: Deploy
18+
runs-on: ubuntu-latest
19+
environment: production
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Configure AWS credentials
26+
uses: aws-actions/configure-aws-credentials@v1
27+
with:
28+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
aws-region: eu-west-2
31+
32+
- name: Login to Amazon ECR
33+
id: login-ecr
34+
uses: aws-actions/amazon-ecr-login@v1
35+
36+
- name: Build, tag, and push image to Amazon ECR
37+
id: build-image
38+
env:
39+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
40+
ECR_REPOSITORY: j4numbers/personal-website
41+
IMAGE_TAG: ${{ github.sha }}
42+
run: |
43+
# Build a docker container and
44+
# push it to ECR so that it can
45+
# be deployed to ECS.
46+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
47+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
48+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
49+
50+
- name: HashiCorp - Setup Terraform
51+
uses: hashicorp/[email protected]
52+
with:
53+
# The version of Terraform CLI to install. Defaults to `latest`.
54+
terraform_version: "> 0.15.5"
55+
56+
- name: Validate and plan deployment Terraform
57+
id: terraform-plan-validate
58+
env:
59+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
60+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
61+
62+
TF_VAR_deploy_version: ${{ github.sha }}
63+
TF_VAR_vpc_id: ${{ secrets.DEPLOY_VPC_ID }}
64+
TF_VAR_application_debug_mode: "false"
65+
66+
TF_VAR_logger_level: "info"
67+
run: |
68+
cd tf/site/
69+
terraform init -backend-config backend_config/dev.conf
70+
terraform validate
71+
terraform plan -no-color -out plan.tfplan
72+
73+
- name: Deploy Terraform
74+
id: terraform-apply
75+
env:
76+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
77+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
78+
run: cd tf/site/ && terraform apply plan.tfplan

.github/workflows/npm-build-and-test.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ name: NodeJS build and test
22

33
on: push
44

5+
env:
6+
default_node_version: 14.x
7+
58
jobs:
69
build:
710
runs-on: ubuntu-latest
811

9-
strategy:
10-
matrix:
11-
node-version: [12.x, 14.x, 16.x]
12-
1312
steps:
1413
- uses: actions/checkout@v2
1514

1615
- name: Use Node.js ${{ matrix.node-version }}
1716
uses: actions/setup-node@v1
1817
with:
19-
node-version: ${{ matrix.node-version }}
18+
node-version: ${{ env.default_node_version }}
2019

2120
- name: Build
2221
run: |
@@ -50,10 +49,6 @@ jobs:
5049
needs: build
5150
continue-on-error: true
5251

53-
strategy:
54-
matrix:
55-
node-version: [12.x, 14.x, 16.x]
56-
5752
steps:
5853
- uses: actions/checkout@v2
5954

@@ -75,7 +70,7 @@ jobs:
7570
- name: Use Node.js ${{ matrix.node-version }}
7671
uses: actions/setup-node@v1
7772
with:
78-
node-version: ${{ matrix.node-version }}
73+
node-version: ${{ env.default_node_version }}
7974

8075
- name: Perform lint checks
8176
run: |
@@ -119,3 +114,15 @@ jobs:
119114
npm i
120115
npm run generate-certs
121116
npm run test:unit
117+
118+
deploy:
119+
if: github.ref_name == 'main'
120+
needs:
121+
- test
122+
uses: j4numbers/common-workflows/.github/workflows/build-ecr-aws.yml@main
123+
with:
124+
env: production
125+
repo_name: j4numbers/personal-website
126+
secrets:
127+
AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }}
128+
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }}

0 commit comments

Comments
 (0)