[FIX] @EnableWebMvc 로 인한 역직렬화 오류로 제거 #20
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Java CD with Gradle in mogakGo | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build-and-push-docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
## caching Gradle | |
- name: Gradle caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
## create application.yml | |
- name: make application.yml | |
run: | | |
mkdir -p ./src/main/resources | |
touch ./src/main/resources/application.yml | |
shell: bash | |
## save application.yml for secrets | |
- name: save application.yml | |
run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml | |
shell: bash | |
## create firebase_service_key.json | |
- name: create-json | |
id: create-json | |
uses: jsdaniell/[email protected] | |
with: | |
name: "firebase_service_key.json" | |
json: ${{ secrets.FIREBASE_SERVICE }} | |
dir: ./src/main/resources/ | |
# - name: make firebase_service_key.json | |
# run: touch ./src/main/resources/firebase_service_key.json | |
# shell: bash | |
# | |
# - name: save firebase_service_key.json from secrets | |
# run: echo "${{ secrets.FIREBASE_SERVICE }}" > ./src/main/resources/firebase_service_key.json | |
# shell: bash | |
## grant permission for gradlew | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
## build gradle | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
## login before push docker-hub | |
- name: login Docker-Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
## build docker and push image | |
- name: Docker Build and Push | |
run: | | |
docker build -f Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/mogakgo . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/mogakgo | |
## deploy docker file to EC2 | |
- name: Deploy to Prod | |
uses: appleboy/ssh-action@master | |
id: deploy-prod | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ubuntu | |
key: ${{ secrets.EC2_PEM_KEY }} | |
port: 22 | |
script: | | |
if [ ! -z "$(docker ps -q)" ]; then | |
docker stop $(docker ps -q) | |
fi | |
if [ ! -z "$(docker ps -aq)" ]; then | |
docker rm $(docker ps -aq) | |
fi | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/mogakgo | |
docker run -d \ | |
--log-driver=awslogs \ | |
--log-opt awslogs-region=ap-northeast-2 \ | |
--log-opt awslogs-group=mogakgo-web \ | |
--log-opt awslogs-stream=log \ | |
--name mogakgo \ | |
-p 8080:8080 \ | |
-e TZ=Asia/Seoul \ | |
${{ secrets.DOCKERHUB_USERNAME }}/mogakgo | |
docker system prune -f |