Skip to content

Merge pull request #35 from billbill-project/fix/auth/v1 #36

Merge pull request #35 from billbill-project/fix/auth/v1

Merge pull request #35 from billbill-project/fix/auth/v1 #36

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:

Check failure on line 54 in .github/workflows/dev_deply.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/dev_deply.yml

Invalid workflow file

You have an error in your yaml syntax on line 54
host: ${{ secrets.EC2_SERVER_HOST }}
username: ubuntu
key: ${{ secrets.EC2_PRIVATE_KEY}}
script: |
# Docker 이미지 pull
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest
# 기존 컨테이너 중지 및 제거
if [ $(sudo docker ps -a -q -f name=bill-api) ]; then
sudo docker stop bill-api
sudo docker rm bill-api
fi
# Docker 이미지 태그 설정 및 실행
sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest bill-api
sudo docker run --name bill-api -d -p 80:8080 \
-e SPRING_DATASOURCE_URL="${SPRING_DATASOURCE_URL}" \
-e SPRING_DATASOURCE_USERNAME="${SPRING_DATASOURCE_USERNAME}" \
-e SPRING_DATASOURCE_PASSWORD="${SPRING_DATASOURCE_PASSWORD}" \
-e SPRING_DATASOURCE_DRIVER_CLASS_NAME="${SPRING_DATASOURCE_DRIVER_CLASS_NAME}" \
-e JWT_BILL_SECRET_KEY="${JWT_BILL_SECRET_KEY}" \
-e JWT_BILL_ACCESS_TOKEN_EXPIRED="${JWT_BILL_ACCESS_TOKEN_EXPIRED}" \
-e JWT_BILL_REFRESH_TOKEN_EXPIRED="${JWT_BILL_REFRESH_TOKEN_EXPIRED}" \
-e SPRINGDOC_API_DOCS_PATH="${SPRINGDOC_API_DOCS_PATH}" \
-e SPRINGDOC_CACHE_DISABLED="${SPRINGDOC_CACHE_DISABLED}" \
-e SPRINGDOC_DEFAULT_CONSUMES_MEDIA_TYPE="${SPRINGDOC_DEFAULT_CONSUMES_MEDIA_TYPE}" \
-e SPRINGDOC_DEFAULT_PRODUCES_MEDIA_TYPE="${SPRINGDOC_DEFAULT_PRODUCES_MEDIA_TYPE}" \
-e SPRINGDOC_PACKAGES_TO_SCAN="${SPRINGDOC_PACKAGES_TO_SCAN}" \
-e SPRINGDOC_SWAGGER_UI_DISABLE_SWAGGER_DEFAULT_URL="${SPRINGDOC_SWAGGER_UI_DISABLE_SWAGGER_DEFAULT_URL}" \
-e SPRINGDOC_SWAGGER_UI_OPERATIONS_SORTER="${SPRINGDOC_SWAGGER_UI_OPERATIONS_SORTER}" \
-e SPRINGDOC_SWAGGER_UI_PATH="${SPRINGDOC_SWAGGER_UI_PATH}" \
-e SPRING_DEVTOOLS_LIVERELOAD_ENABLE="${SPRING_DEVTOOLS_LIVERELOAD_ENABLE}" \
${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest
# 사용하지 않는 컨테이너 및 이미지 정리
sudo docker rm $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker image prune -a -f