Skip to content

temp: CI/CD 임시용 commit #54

temp: CI/CD 임시용 commit

temp: CI/CD 임시용 commit #54

Workflow file for this run

name: Java CI/CD
# 동작 조건 설정 : Pull_request가 closed 됐을경우
on:
pull_request:
types: [closed] #pull_request closed 됐을 경우
workflow_dispatch: # 수동실행도 가능하도록
jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정
build-docker-image:
runs-on: ubuntu-latest
#만약 머지가 됬을 경우, 또 base ref가 main일경우 실행
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
steps:
- name: Checkout
uses: actions/checkout@v3
# 1. Java 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# 2. gradelw에 권한 부여
- name: Grant execute permission for gradelw
run: chmod +x ./gradlew
shell: bash
# 3. Spring Boot 애플리케이션 빌드
- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash
# 4. Docker 이미지 빌드
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/bill-api .
# 5. DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# 6. Docker Hub 이미지 빌드 및 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/bill-api
#7. EC2 배포
- name: Docker image pull & Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_SERVER_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY}}
script : |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest
if [ $(docker ps -a -q -f name=bill-api) ]; then
sudo docker stop bill-api
sudo docker rm bill-api
fi
sudo docker tag jainefer/bill-api:latest bill-api
sudo docker run --name bill-api -d -p 80:8080 \
-e SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }} \
-e SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }} \
-e SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }} \
-e SPRING_DATASOURCE_DRIVER_CLASS_NAME=${{ secrets.SPRING_DATASOURCE_DRIVER_CLASS_NAME }} \
-e JWT_BILL_SECRET_KEY=${{secrets.JWT_BILL_SECRET_KEY}} \
-e JWT_BILL_ACCESS_TOKEN_EXPIRED=${{secrets.JWT_BILL_ACCESS_TOKEN_EXPIRED}} \
-e JWT_BILL_REFRESH_TOKEN_EXPIRED=${{secrets.JWT_BILL_REFRESH_TOKEN_EXPIRED}} \
${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest
sudo docker rm $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker image prune -a -f