Skip to content

배포 (#137)

배포 (#137) #45

Workflow file for this run

on:
push:
branches:
- main
paths:
- docker-compose-backend.yml
- Dockerfile
- gradle.properties
- gradlew
- gradlew.bat
- build.gradle.kts
- settings.gradle.kts
- src/**
- gradle/**
- .github/workflows/deploy.yaml
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Setup Java JDK
uses: actions/setup-java@v3.12.0
with:
java-version: '17'
distribution: 'adopt'
-
run: ./gradlew clean bootJar -x test
-
name: Log in to the Container Registry
uses: docker/login-action@v2.2.0
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
-
name: Build and push Docker image
uses: docker/build-push-action@v4.1.1
with:
context: .
push: true
build-args: |
PROFILE=prod
tags: |
ghcr.io/wafflestudio/csereal-server/server_image:latest
ghcr.io/wafflestudio/csereal-server/server_image:${{github.sha}}
-
name: Create .env file
run: |
echo "MYSQL_ROOT_PASSWORD=${{secrets.MYSQL_ROOT_PASSWORD}}" > .env
echo "MYSQL_USER=${{secrets.MYSQL_USER}}" >> .env
echo "MYSQL_PASSWORD=${{secrets.MYSQL_PASSWORD}}" >> .env
echo "MYSQL_DATABASE=${{secrets.MYSQL_DATABASE}}" >> .env
echo "PROFILE=prod" >> .env
echo "OIDC_CLIENT_SECRET_DEV=${{secrets.OIDC_CLIENT_SECRET_DEV}}" >> .env
echo "URL=${{secrets.URL}}" >> .env
-
name: SCP Command to Transfer Files
uses: appleboy/scp-action@v0.1.4
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-backend.yml, .env"
target: "~/app"
overwrite: true
-
name: SSH Remote Commands
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
script: | # TODO: Change to blue-green deployment
cd ~/app
source .env
docker-compose -f docker-compose-backend.yml down
docker-compose -f docker-compose-backend.yml pull
docker-compose -f docker-compose-backend.yml up -d