Add 1st version of code-deploy using Actions

This commit is contained in:
Nick Tampakas
2023-03-15 14:59:20 +02:00
parent 47c2f13fb7
commit 58ce3991a0
8 changed files with 129 additions and 0 deletions

21
.github/scripts/deploy.sh vendored Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -x
COMMIT_HASH=$(git rev-parse HEAD)
DEPLOY_ID=$(aws deploy create-deployment --application-name zkgroups --deployment-group-name zkgroups-group --github-location repository=$GITHUB_REPOSITORY,commitId=$COMMIT_HASH --ignore-application-stop-failures --file-exists OVERWRITE --output text)
while true; do
STATUS=$(aws deploy get-deployment --deployment-id $DEPLOY_ID --query 'deploymentInfo.status' --output text)
if [ $STATUS != "InProgress" ] && [ $STATUS != "Created" ]; then
if [ $STATUS = "Succeeded" ]; then
echo "SUCCESS"
exit 0
else
echo "Failed"
exit 1
fi
else
echo "Deploying..."
fi
sleep 30
done

40
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: Deploy
on:
#push:
# branches: [ master ]
workflow_dispatch: {}
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/zkgroups-deploy-slc
role-duration-seconds: 900
aws-region: eu-central-1
- name: Build and Push image to ECR
run: |
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 zkgroups .
docker tag zkgroups:latest 490752553772.dkr.ecr.eu-central-1.amazonaws.com/zkgroups:latest
docker push 490752553772.dkr.ecr.eu-central-1.amazonaws.com/zkgroups:latest
- name: Create Deployment
run: |
.github/scripts/deploy.sh

30
appspec.yml Normal file
View File

@@ -0,0 +1,30 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/zk-groups
permissions:
- object: /home/ubuntu/zk-groups
owner: ubuntu
group: ubuntu
hooks:
BeforeInstall:
- location: scripts/before_install.sh
timeout: 300
runas: ubuntu
AfterInstall:
- location: scripts/after_install.sh
timeout: 300
runas: ubuntu
ApplicationStart:
- location: scripts/start_app.sh
timeout: 300
runas: ubuntu
ApplicationStop:
- location: scripts/stop_app.sh
timeout: 300
runas: ubuntu
ValidateService:
- location: scripts/validate_app.sh
timeout: 300
runas: ubuntu

8
scripts/after_install.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e
cd ~/zk-groups
#aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 490752553772.dkr.ecr.eu-central-1.amazonaws.com
#docker pull 490752553772.dkr.ecr.eu-central-1.amazonaws.com/zkgroups:latest
exit 0

6
scripts/before_install.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
set -e
docker image prune --filter "until=48h" -f
exit 0

7
scripts/start_app.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -e
cd ~/zk-groups
docker compose up -d
exit 0

11
scripts/stop_app.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 490752553772.dkr.ecr.eu-central-1.amazonaws.com
docker pull 490752553772.dkr.ecr.eu-central-1.amazonaws.com/zkgroups:latest
sleep 1
cd ~/zk-groups
docker compose down
exit 0

6
scripts/validate_app.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
docker ps | grep app1
[ $? -eq 0 ] || exit 1
exit 0