chore: Dockerfile 방식에서 docker-compose 방식으로 대체 #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build_and_deploy: | |
name: Deploy CD | |
runs-on: ubuntu-latest | |
steps: | |
- name: 레포지토리를 가져온다 | |
uses: actions/checkout@v4 | |
- name: 자바 17을 설치한다 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: application.yml 파일 생성 | |
run: echo "${{ secrets.APPLICATION_ENV }}" > ./src/main/resources/application-prod.yml | |
- name: Gradle 명령 실행을 위해 권한을 부여한다 | |
run: chmod +x gradlew | |
- name: Gradle 로 build 를 수행한다 | |
run: ./gradlew clean build | |
- name: Docker Hub 로그인 | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker 이미지 빌드 & 푸쉬 | |
run: | | |
docker-compose -f ./docker-compose.yml build | |
docker-compose -f ./docker-compose.yml push | |
- name: Deploy with push | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PRIVATE_KEY }} | |
port: ${{ secrets.PORT }} | |
# 이미 멈춰있어서 발생하는 예외를 방지하기 위해 || true 설정 | |
script: | | |
sudo docker stop we-share-wish-hair || true | |
sudo docker stop wswh-redis || true | |
sudo docker container prune -f | |
sudo docker pull ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest | |
sudo docker run -d --log-driver=syslog \ | |
-p 8080:8080 --name we-share-wish-hair \ | |
${{ secrets.DOCKER_NAME }}/we-share-wish-hair:latest | |
sudo docker pull ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis | |
sudo docker run -d -p 6379:6379 --name wswh-redis ${{ secrets.DOCKER_NAME }}/we-share-wish-hair:redis | |