Skip to content

Feature/borrow posts #79

Feature/borrow posts

Feature/borrow posts #79

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 [ $(sudo docker ps -a -q -f name=bill-api) ]; then
sudo docker stop bill-api
sudo docker rm bill-api
fi
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}"
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}"
sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest bill-api
sudo docker run --name bill-api -d -p 80:8080 \
-e SPRING_DATASOURCE_DRIVER_CLASS_NAME=${{ secrets.SPRING_DATASOURCE_DRIVER_CLASS_NAME }} \
-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 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 }} \
-e SPRINGDOC_API_DOCS_PATH=${{ secrets.SPRINGDOC_API_DOCS_PATH }} \
-e SPRINGDOC_CACHE_ENABLED=false \
-e SPRINGDOC_DEFAULT_CONSUMES_MEDIA_TYPE="${{secrets.SPRINGDOC_DEFAULT_CONSUMES_MEDIA_TYPE}}" \
-e SPRINGDOC_DEFAULT_PRODUCES_MEDIA_TYPE="${{secrets.SPRINGDOC_DEFAULT_PRODUCES_MEDIA_TYPE}}" \
-e SPRINGDOC_PACKAGES_TO_SCAN=${{ secrets.SPRINGDOC_PACKAGES_TO_SCAN }} \
-e SPRINGDOC_SWAGGER_UI_DISABLE_SWAGGER_DEFAULT_URL=${{ secrets.SPRINGDOC_SWAGGER_UI_DISABLE_SWAGGER_DEFAULT_URL }} \
-e SPRINGDOC_SWAGGER_UI_OPERATIONS_SORTER=${{ secrets.SPRINGDOC_SWAGGER_UI_OPERATIONS_SORTER }} \
-e SPRINGDOC_SWAGGER_UI_PATH=${{ secrets.SPRINGDOC_SWAGGER_UI_PATH }} \
-e SPRING_DEVTOOLS_LIVERELOAD_ENABLE=${{ secrets.SPRING_DEVTOOLS_LIVERELOAD_ENABLE }} \
-e CLOUD_AWS_CREDENTIALS_ACCESS_KEY=${{ secrets.CLOUD_AWS_CREDENTIALS_ACCESS_KEY }} \
-e CLOUD_AWS_CREDENTIALS_SECRET_KEY=${{secrets.CLOUD_AWS_CREDENTIALS_SECRET_KEY }} \
-e CLOUD_AWS_REGION_STATIC=${{secrets.CLOUD_AWS_REGION_STATIC}} \
-e CLOUD_AWS_S3_BUCKET=${{secrets.CLOUD_AWS_S3_BUCKET}} \
-e CLOUD_AWS_REGION_AUTO=false \
-e CLOUD_AWS_STACK_AUTO=false \
-e SPRING_SERVLET_MULTIPART_MAXFILESIZE=${{secrets.SPRING_SERVLET_MULTIPART_MAXFILESIZE}} \
-e SPRING_SERVLET_MULTIPART_MAXREQUESTSIZE=${{secrets.SPRING_SERVLET_MULTIPART_MAXREQUESTSIZE}} \
-e KAKAO_CLIENT_ID=${{secrets.KAKAO_CLIENT_ID}} \
-e KAKAO_REDIRECT_URI=${{secrets.KAKAO_REDIRECT_URI}} \
-e KAKAO_PROVIDER_AUTHORIZATION_URI=${{secrets.KAKAO_PROVIDER_AUTHORIZATION_URI}} \
-e KAKAO_PROVIDER_TOKEN_URI=${{secrets.KAKAO_PROVIDER_TOKEN_URI}} \
-e KAKAO_PROVIDER_USER_INFO_URI=${{secrets.KAKAO_PROVIDER_USER_INFO_URI}} \
-e PORTONE_API_SECRET=${{secrets.PORTONE_API_SECRET}} \
-e WEBHOOK_URL=${{secrets.WEBHOOK_URL}} \
${{ secrets.DOCKERHUB_USERNAME }}/bill-api:latest
sudo docker rm $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker image prune -a -f