From 29da69843d004b609106e645e9f8e007f9570a62 Mon Sep 17 00:00:00 2001 From: Nick Tampakas Date: Wed, 6 Nov 2024 10:15:05 +0200 Subject: [PATCH 1/2] Create workflow + aux scripts for build/deploy --- .github/scripts/build.sh | 13 +++++++++++++ .github/scripts/deploy.sh | 13 +++++++++++++ .github/workflows/deploy.yml | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100755 .github/scripts/build.sh create mode 100755 .github/scripts/deploy.sh create mode 100644 .github/workflows/deploy.yml diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh new file mode 100755 index 0000000..ff28a3a --- /dev/null +++ b/.github/scripts/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ex + +# Download poaps +aws s3 cp s3://tlsn-plugin-demo/poaps.txt server/util/ + +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 tlsn-plugin-demo . +docker tag tlsn-plugin-demo:latest 490752553772.dkr.ecr.eu-central-1.amazonaws.com/tlsn-plugin-demo:latest +docker push 490752553772.dkr.ecr.eu-central-1.amazonaws.com/tlsn-plugin-demo:latest + +exit 0 diff --git a/.github/scripts/deploy.sh b/.github/scripts/deploy.sh new file mode 100755 index 0000000..5d7b8d3 --- /dev/null +++ b/.github/scripts/deploy.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ex + +tasks="tlsn-plugin-demo" +for task in $tasks; do + revision=$(aws ecs describe-task-definition --task-definition $task --query "taskDefinition.revision") + aws ecs update-service --cluster tlsn-plugin-demo --service $task --force-new-deployment --task-definition $task:$revision +done + +for loop in {1..3}; do + [ "$loop" -eq 3 ] && exit 1 + aws ecs wait services-stable --cluster tlsn-plugin-demo --services $tasks && break || continue +done diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..8db3933 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,36 @@ +name: 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@v4 + with: + persist-credentials: false + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::490752553772:role/tlsn-plugin-demo-ecs-deploy-slc + role-duration-seconds: 1800 + 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 From efb0fb3e34605a8790a1f9de8c249d1d66b64a79 Mon Sep 17 00:00:00 2001 From: Nick Tampakas Date: Wed, 6 Nov 2024 10:16:08 +0200 Subject: [PATCH 2/2] Create Dockerfile --- Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ed1ca5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:20-alpine + +ARG PORT=3030 +WORKDIR /app + +COPY . . + +RUN npm install +RUN touch server/util/poaps.txt +RUN touch server/util/assignments.json +RUN npm run build + +EXPOSE ${PORT} +CMD ["node", "build/server/index.bundle.js"]