From c0ef86200c231406b4ff463fd119c63725ee33a3 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 7 Jul 2023 09:52:17 +0300 Subject: [PATCH] Add deploy workflow + aux scritps --- .github/scripts/build.sh | 13 ++++++++++ .github/scripts/deploy.sh | 10 ++++++++ .github/workflows/deploy.yml | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 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..604911c --- /dev/null +++ b/.github/scripts/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +build=$1 + +[ $build = "enable" ] || exit 0 + +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 pse-web . +docker tag pse-web:latest 490752553772.dkr.ecr.eu-central-1.amazonaws.com/pse-web:latest +docker push 490752553772.dkr.ecr.eu-central-1.amazonaws.com/pse-web:latest + +exit 0 diff --git a/.github/scripts/deploy.sh b/.github/scripts/deploy.sh new file mode 100755 index 0000000..64556a3 --- /dev/null +++ b/.github/scripts/deploy.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -ex + +tasks="pse-web" +for task in $tasks; do + pse-web_revision=$(aws ecs describe-task-definition --task-definition $task --query "taskDefinition.revision") + aws ecs update-service --cluster pse-web --service $task --force-new-deployment --task-definition $task:$pse-web_revision +done + +aws ecs wait services-stable --cluster pse-web --services $tasks diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..79d05fd --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,48 @@ +name: Deploy +on: + push: + branches: [main] + workflow_dispatch: + inputs: + build: + description: "Build trigger" + required: true + default: "enable" + type: choice + options: + - enable + - disable + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + deploy: + runs-on: ubuntu-latest + env: + DATA: ${{ github.event.inputs.build }} + 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/pse-web-ecs-deploy-slc + role-duration-seconds: 1800 + aws-region: eu-central-1 + + - name: Build and Push images to ECR + run: | + .github/scripts/build.sh ${{ env.DATA }} + + - name: Create Deployment + run: | + .github/scripts/deploy.sh