Skip to content

Commit a44f2b4

Browse files
author
ntampakas
authored
Automated deployment on AWS Fargate (#13)
* Create Dockerfile for app * Add deployment workflow * Add aux scripts needed to build/deploy
1 parent 853edd7 commit a44f2b4

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

.github/scripts/build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 490752553772.dkr.ecr.eu-central-1.amazonaws.com
5+
6+
docker build -t tlsnotary-explorer -f apps/Dockerfile .
7+
docker tag tlsnotary-explorer:latest 490752553772.dkr.ecr.eu-central-1.amazonaws.com/tlsnotary-explorer:latest
8+
docker push 490752553772.dkr.ecr.eu-central-1.amazonaws.com/tlsnotary-explorer:latest
9+
10+
exit 0

.github/scripts/deploy.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
ecs_cluster="tlsnotary-explorer"
5+
services="tlsnotary-explorer"
6+
7+
for service in $services; do
8+
tlsnotary_explorer_revision=$(aws ecs describe-task-definition --task-definition $service --query "taskDefinition.revision")
9+
aws ecs update-service --cluster $ecs_cluster --service $service --force-new-deployment --task-definition $service:$tlsnotary_explorer_revision
10+
done
11+
12+
aws ecs wait services-stable --cluster $ecs_cluster --services $services && break || continue
13+
14+
exit 0

.github/workflows/cd-deploy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: cd-deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write
16+
contents: read
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
with:
22+
persist-credentials: false
23+
24+
- name: Configure AWS Credentials
25+
uses: aws-actions/configure-aws-credentials@v2
26+
with:
27+
role-to-assume: arn:aws:iam::490752553772:role/tlsnotary-explorer-ecs-deploy-slc
28+
role-duration-seconds: 2700
29+
aws-region: eu-central-1
30+
31+
- name: Build and Push images to ECR
32+
run: |
33+
.github/scripts/build.sh
34+
35+
- name: Trigger Deployment
36+
run: |
37+
.github/scripts/deploy.sh

apps/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Build app
2+
FROM node:latest as builder
3+
4+
ENV PATH="${PATH}:/root/.cargo/bin"
5+
WORKDIR /builder
6+
7+
COPY . .
8+
9+
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y
10+
RUN npm i
11+
RUN npm i --prefix rs/verifier/
12+
RUN npm run build
13+
14+
# Create image for the app by copying build artifacts from builder
15+
FROM node:latest as runner
16+
17+
RUN apt-get update; apt-get install netcat-openbsd -y
18+
USER node
19+
20+
ARG PORT=3000
21+
22+
WORKDIR /home/node/explorer
23+
COPY --from=builder /builder/build ./build
24+
25+
EXPOSE ${PORT}
26+
CMD ["node", "build/server/index.bundle.js"]

0 commit comments

Comments
 (0)