Skip to content

Merge pull request #128 from studio-recoding/dev #25

Merge pull request #128 from studio-recoding/dev

Merge pull request #128 from studio-recoding/dev #25

Workflow file for this run

name: Deploy to Prod
## main에 릴리즈가 일어날 때마다 빌드 및 배포
on:
push:
branches: [ main ]
tags: [ "v*.*.*" ]
jobs:
build:
## checkout 후 자바 17 버전으로 설정
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
## gradlew에 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
## Copy properties files
- name: Make application.yml
run: |
echo "$PROFILE_PROD" > ./src/main/resources/application.yml
# Make env file
env:
PROFILE_PROD: ${{ secrets.PROFILE_PROD }}
## Copy properties files
- name: Make application-prod.yml
run: |
touch ./src/main/resources/application-prod.yml
echo "$PROPERTIES_PROD" > ./src/main/resources/application-prod.yml
# Make env file
env:
PROPERTIES_PROD: ${{ secrets.PROPERTIES_PROD }}
## gradle build
- name: Build with Gradle
run: ./gradlew clean build
## docker metadata(namespace/repository)
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: jeonhaeseung/ness-server-prod
tag-semver: |
{{version}}
{{major}}.{{minor}}
## 멀티-플랫폼 빌드 도구 Buildx 사용
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
## DockerHub에 로그인
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
## 위에서 설정한 테그를 참고해 push
- name: Docker build & push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.prod
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
## 원격에 접속 및 디렉토리 생성
- name: create remote directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USER_PROD }}
key: ${{ secrets.KEY_PROD }}
script: mkdir -p ./prod
## 소스 코드 복사 붙여넣기
- name: copy source via ssh key
uses: burnett01/[email protected]
with:
switches: -avzr --delete
path: ./config
remote_path: ./prod
remote_host: ${{ secrets.HOST_PROD }}
remote_user: ${{ secrets.USER_PROD }}
remote_key: ${{ secrets.KEY_PROD }}
## EC2에 배포(CD)
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USER_PROD }}
key: ${{ secrets.KEY_PROD }}
script: |
sh ./prod/config/scripts/deploy.sh
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
sudo docker rmi $(sudo docker images -q)
docker pull jeonhaeseung/ness-server-prod:main
docker run -d --name backend-server -p 80:8080 --restart unless-stopped jeonhaeseung/ness-server-prod:main