Merge pull request #25 from najakgil/feature/#23 #83
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: Backend CI | |
on: | |
push: | |
branches: [ main ] # 빌드 작업을 진행할 브랜치를 선택합니다. | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
token: ${{ secrets.ACTION_TOKEN }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: 스프링부트 애플리케이션 빌드 # (1) | |
run: ./gradlew clean build | |
# 스프링 부트 애플리케이션을 빌드합니다. | |
- name: 도커 이미지 빌드 # (2) | |
run: docker build -t ${{ secrets.DOCKERHUB_REPO }}/myprecious . | |
# 스프링 부트 애플리케이션의 도커 이미지를 빌드합니다. | |
- name: Docker Hub 로그인 # (3) | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# Docker Hub에 로그인합니다. | |
- name: Docker Hub 퍼블리시 # (4) | |
run: docker push ${{ secrets.DOCKERHUB_REPO }}/myprecious | |
# 빌드한 도커 이미지를 Docker Hub에 푸시합니다. | |
#EC2에 로그인해 docker image pull & run : https://github.com/appleboy/ssh-action | |
- name: EC2 login and docker image pull and run | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.EC2_PASSWORD }} | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
script: | | |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
sudo docker stop $(sudo docker ps -aq) | |
sudo docker rm -f $(sudo docker ps -aq) | |
sudo docker pull ${{ secrets.DOCKERHUB_REPO }}/myprecious | |
sudo docker run -d -p 9000:8080 ${{ secrets.DOCKERHUB_REPO }}/myprecious sleep infinity | |
sudo docker image prune -f | |
ps -ef | grep java |