[18기_이영교] Github Action을 이용한 CI/CD 배포 미션 제출합니다. #2
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
# This is a basic workflow to help you get started with Actions | |
name: CI | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push or pull request events but only for the "master" branch | |
push: | |
branches: [ "YoungGyo-00" ] | |
pull_request: | |
branches: [ "YoungGyo-00" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
## 버전 확인 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
## gradle build | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
## 웹 이미지 빌드 및 도커허브에 push | |
- name: web docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t younggyolee/market . | |
docker push younggyolee/market | |
- name: executing remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: | | |
## 여러분이 원하는 경로로 이동합니다. | |
cd /home/ubuntu/ | |
## docker-compose를 실행합니다. | |
sudo chmod 666 /var/run/docker.sock | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull younggyolee/market | |
docker-compose -f docker-compose.yml --env-file ./.env up -d | |
docker image prune -f |