Create README.md #3
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: | |
backend_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout-source code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.ACCESS_TOKEN_FOR_GITHUB_ACTIONS }} | |
submodules: true | |
# JDK 설치 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
# Gradle 실행권한 부여 | |
- name: Grant execute permission to gradlew | |
run: chmod +x ./gradlew | |
# Spring boot application 빌드 | |
- name: Build with gradle | |
run: ./gradlew -x test clean build | |
# docker hub login | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
# docker image build and push | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:${{ secrets.DOCKER_HUB_USERNAME }} | |
# Copy docker-compose-deploy.yml | |
- name: Deliver docker-compose-deploy.yml file | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.WAS_HOST }} | |
username: ${{ secrets.WAS_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.WAS_SSH_PORT }} | |
source: "docker-compose-deploy.yml" | |
target: "/home/ubuntu" | |
# WAS 인스턴스 접속 & 애플리케이션 실행 | |
- name: Connect to WAS & Execute Application | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.WAS_HOST }} | |
username: ${{ secrets.WAS_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: 22 | |
script: | | |
docker-compose -f docker-compose-deploy.yml down -v | |
docker-compose -f docker-compose-deploy.yml pull | |
docker-compose -f docker-compose-deploy.yml up -d | |
docker image prune -f |