Skip to content

Use transactions for database dump restore (#112) #35

Use transactions for database dump restore (#112)

Use transactions for database dump restore (#112) #35

Workflow file for this run

name: Deploy backend
on:
push:
branches:
- main
paths:
- "server/**"
- ".github/workflows/backdeploy.yaml"
env:
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.CI_CD_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_CD_AWS_SECRET_ACCESS_KEY }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Restore gradle dependencies
uses: actions/cache@v2
with:
path: "~/.gradle"
key: ${{ runner.os }}-modules-${{ hashFiles('**/server/build.gradle') }}
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Add version info
run: |
export GIT_HASH=$(git rev-parse --short HEAD)
sed -i "s|version: 1.0.0|version: ${GIT_HASH}|g" server/src/main/resources/application.yaml
- name: Build jar
run: ./server/gradlew build -p server -x test
- name: Restore application.yaml
run: git checkout server/src/main/resources/application.yaml
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push to ECR
run: |
cd server
./gradlew clean build --info -x test
export STAGE=prod
GIT_HASH=$(git rev-parse --short HEAD)
# Get value from ssm and export it
ECR_URL_PARAM=$(aws ssm get-parameter --name "/$STAGE/ecr/url/statistics_server")
ECR_URL=$(echo $ECR_URL_PARAM | jq -r '.Parameter.Value')
# Before and after the bar
ECR_URL_ROOT="${ECR_URL%%/*}"
ECR_URL_SPEC="${ECR_URL##*/}"
aws ecr get-login-password --region ${{ env.AWS_DEFAULT_REGION }} | docker login --username AWS --password-stdin $ECR_URL_ROOT
docker build -t $ECR_URL_SPEC .
docker tag $ECR_URL_SPEC:latest $ECR_URL:latest
docker tag $ECR_URL_SPEC:latest $ECR_URL:$GIT_HASH
docker push $ECR_URL:latest
docker push $ECR_URL:$GIT_HASH
- name: Blue green deployment
run: |
aws deploy create-deployment \
--application-name ${{ secrets.APPLICATION_NAME }} \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP }} \
--s3-location ${{ secrets.S3_LOCATION }}