localhost 로 바꿔서 실행해보기 #117
Workflow file for this run
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: issue-tracker auto deploy | |
on: | |
push: | |
branches: [ "charlie-test" ] | |
permissions: | |
contents: read | |
env: | |
BE_WORKING_DIR: ./secondhand | |
NGINX_WORKING_DIR: ./nginx | |
APPLICATION_FILE_PATH: ./src/main/resources/application.yml | |
jobs: | |
# Job[1]: BACKEND -> docker hub로 build & push | |
be-deploy: | |
runs-on: ubuntu-latest | |
services: | |
mysql_db: | |
image: mysql:8.0.23 | |
ports: | |
- 3306:3306 # HOST:CONTAINER | |
env: | |
MYSQL_DATABASE: second_hand | |
MYSQL_ROOT_PASSWORD: 1234 | |
redis: | |
image: redis:latest | |
ports: | |
- 6379:6379 | |
defaults: | |
run: | |
working-directory: ${{ env.BE_WORKING_DIR }} | |
steps: | |
# 1. Source 단계 | |
- name: Checkout Source Code | |
uses: actions/checkout@v3 | |
# JDK 세팅 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
# 3. build 단계 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -Djasypt.encryptor.password=${{ secrets.JASYPT_SECRET }} | |
# 4. docker hub로 build & push | |
- name: docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-be:latest . | |
docker push ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-be:latest | |
# job[2]: nginx -> docker hub로 build & push | |
nginx-deploy: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ env.NGINX_WORKING_DIR }} | |
steps: | |
# 1. Source 단계 | |
- name: Checkout Source Code | |
uses: actions/checkout@v3 | |
# 2. docker hub로 build & push | |
- name: docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-nginx:latest . | |
docker push ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-nginx:latest | |
# job[3]: EC2에서 docker 이미지 pull하고 실행 | |
SSH-Transfer: | |
needs: [ be-deploy, nginx-deploy ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: SSH Transfer | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: | | |
sudo docker-compose down -v | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-be:latest | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/team-5-second-hand-nginx:latest | |
sudo docker-compose up -d | |
sudo docker image prune -a -f |