Skip to content

Update README.md

Update README.md #132

Workflow file for this run

# 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: Nanal Backend
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions: write-all
jobs:
build:
runs-on: ubuntu-20.04
#JDK 세팅
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
#gradle Caching
- name: Gradle Cashing
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
#CI
#gradle 권한 추가
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew
#빌드
- name: Build with Gradle
run: ./gradlew build
## properties 설정
- name: create application-dev.properties
if: contains(github.ref, 'develop')
run: |
cd ./src/main/resources
touch ./application-dev.properties
echo "${{ secrets.PROPERTIES_DEV }}" > ./application-dev.properties
shell: bash
## 배포용 properties 설정
- name: create application-prod.properties
if: contains(github.ref, 'main')
run: |
cd ./src/main/resources
touch ./application-prod.properties
echo "${{ secrets.PROPERTIES_PROD }}" > ./application.properties
shell: bash
##CD
#빌드
- name: Build With Gradle
if: contains(github.ref, 'main')
run: ./gradlew build
#도커 빌드
- name: Docker build
run : docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }} .
#도커 허브 로그인
- name: Docker Hub Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
#도커 푸시
- name: docker push
if: contains(github.ref, 'main')
run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
#배포
- name: Deploy
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
docker stop ${{ secrets.DOCKER_REPOSITORY }}
docker rm -f ${{ secrets.DOCKER_REPOSITORY }}
docker compose up -d
docker image prune -f