Skip to content

Commit

Permalink
Automated deployment on AWS Fargate (#13)
Browse files Browse the repository at this point in the history
* Create Dockerfile for app

* Add deployment workflow

* Add aux scripts needed to build/deploy
  • Loading branch information
ntampakas authored Apr 16, 2024
1 parent 853edd7 commit a44f2b4
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -ex

aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 490752553772.dkr.ecr.eu-central-1.amazonaws.com

docker build -t tlsnotary-explorer -f apps/Dockerfile .
docker tag tlsnotary-explorer:latest 490752553772.dkr.ecr.eu-central-1.amazonaws.com/tlsnotary-explorer:latest
docker push 490752553772.dkr.ecr.eu-central-1.amazonaws.com/tlsnotary-explorer:latest

exit 0
14 changes: 14 additions & 0 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -ex

ecs_cluster="tlsnotary-explorer"
services="tlsnotary-explorer"

for service in $services; do
tlsnotary_explorer_revision=$(aws ecs describe-task-definition --task-definition $service --query "taskDefinition.revision")
aws ecs update-service --cluster $ecs_cluster --service $service --force-new-deployment --task-definition $service:$tlsnotary_explorer_revision
done

aws ecs wait services-stable --cluster $ecs_cluster --services $services && break || continue

exit 0
37 changes: 37 additions & 0 deletions .github/workflows/cd-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: cd-deploy
on:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::490752553772:role/tlsnotary-explorer-ecs-deploy-slc
role-duration-seconds: 2700
aws-region: eu-central-1

- name: Build and Push images to ECR
run: |
.github/scripts/build.sh
- name: Trigger Deployment
run: |
.github/scripts/deploy.sh
26 changes: 26 additions & 0 deletions apps/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build app
FROM node:latest as builder

ENV PATH="${PATH}:/root/.cargo/bin"
WORKDIR /builder

COPY . .

RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y
RUN npm i
RUN npm i --prefix rs/verifier/
RUN npm run build

# Create image for the app by copying build artifacts from builder
FROM node:latest as runner

RUN apt-get update; apt-get install netcat-openbsd -y
USER node

ARG PORT=3000

WORKDIR /home/node/explorer
COPY --from=builder /builder/build ./build

EXPOSE ${PORT}
CMD ["node", "build/server/index.bundle.js"]

0 comments on commit a44f2b4

Please sign in to comment.