Merge pull request #255 from Onion-City/domain/user #244
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 Pipeline | |
on: | |
push: | |
branches: | |
- 'develop' | |
- 'main' | |
jobs: | |
CD: | |
runs-on: ubuntu-latest | |
env: | |
RESOURCE_PATH: ./src/main/resources/application.yml | |
steps: | |
## Project JDK 17 Setting | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set yml file | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: ${{ env.RESOURCE_PATH }} | |
env: | |
spring.datasource.url: ${{ secrets.DB_URL }} | |
spring.datasource.username: ${{ secrets.DB_USERNAME }} | |
spring.datasource.password: ${{ secrets.DB_PASSWORD }} | |
spring.security.oauth2.client.registration.kakao.client-id: ${{ secrets.KAKAO_CLIENT_ID }} | |
spring.security.oauth2.client.registration.kakao.client-secret: ${{ secrets.KAKAO_CLIENT_SECRET }} | |
spring.jpa.hibernate.ddl-auto: update | |
coolsms.api.number: ${{ secrets.FROMNUMBER }} | |
coolsms.api.secret: ${{ secrets.COOLSMS_API_SECRET }} | |
coolsms.api.key: ${{ secrets.COOLSMS_API_KEY }} | |
cloud.aws.s3.bucket: ${{ secrets.S3_BUCKET }} | |
cloud.aws.credentials.access-key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
cloud.aws.credentials.secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
cloud.aws.region.static: ap-northeast-2 | |
spring.redis.data.host: ${{ secrets.REDIS_HOST }} | |
spring.redis.data.password: ${{ secrets.REDIS_PASSWORD }} | |
server.url: ${{ secrets.SERVER_URL }} | |
front.url: ${{ secrets.FRONT_URL }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build | |
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} | |
# Login to ghcr | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: pinetree2 | |
password: ${{ secrets.GHCR_TOKEN }} | |
# Docker 빌드 생성 및 푸시 | |
- name: dev Docker build & push | |
if: contains(github.ref, 'main') || contains(github.ref, 'develop') | |
run: | | |
docker build -f Dockerfile -t ghcr.io/onion-city/whatssue_be_v2/whatssue:latest . | |
docker push ghcr.io/onion-city/whatssue_be_v2/whatssue:latest | |
# 개발서버 SSH접속 및 배포 | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
id: deploy | |
if: contains(github.ref, 'main') || contains(github.ref, 'develop') | |
with: | |
key: ${{secrets.SSH_PRIVATE_KEY }} | |
host: ${{ secrets.DEV_SERVER_DNS }} | |
username: ${{ secrets.DEV_SERVER_USER }} | |
script: | | |
echo "${{ secrets.GHCR_TOKEN }}" | sudo docker login ghcr.io -u pinetree2 --password-stdin | |
cd /home/ubuntu/docker-compose | |
# 이전 버전의 Spring Boot 컨테이너 중지 및 삭제 | |
if [ "$(docker ps -aq -f name=whatssue-be)" ]; then | |
sudo docker-compose stop springboot | |
sudo docker-compose rm -f springboot | |
fi | |
if [ "$(docker images -q ghcr.io/onion-city/whatssue_be_v2/whatssue)" ]; then | |
sudo docker rmi ghcr.io/onion-city/whatssue_be_v2/whatssue | |
fi | |
sudo docker-compose pull springboot | |
sudo docker-compose up -d springboot | |
# 사용하지 않는 이미지 정리 | |
sudo docker image prune -a -f |