Skip to content

[Feat] docker CI/CD 추가 #1

[Feat] docker CI/CD 추가

[Feat] docker CI/CD 추가 #1

Workflow file for this run

name: CI/CD using docker & git actions
# 해당 브랜치에 push가 되었을 때 실행
on:
push:
branches: [ "main" ]
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
# JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방)
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# application.properties 생성
- name: make application.properties
if: contains(github.ref, 'main')
run: |
mkdir ./src/main/resources
cd ./src/main/resources
touch ./application.properties
echo "${{ secrets.Application }}" > ./application.properties # github actions에서 설정한 값을 application.properties 파일에 쓰기
# gradle build
- name: Build with Gradle
run: ./gradlew build -x test
# 도커 이미지 생성 & 도커 허브에 이미지 푸시
- name: Docker build & push
if: contains(github.ref, 'main')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/bjj .
docker push ${{ secrets.DOCKER_USERNAME }}/bjj
# 도커 이미지 배포
- name: Deploy docker image
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST}}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
sudo docker ps
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/bjj
sudo docker run -d -p 8020:8020 ${{ secrets.DOCKER_USERNAME }}/bjj
sudo docker image prune -f