chore #16: Add gradle.yml for Github Action #12
Workflow file for this run
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
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
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' | |
- name: Make application-prod.yml | |
run: | | |
cd ../../SpringBoot-Damoacon/src/main/resources && touch ./application-prod.yml && echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 | |
with: | |
arguments: build | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t app . | |
docker tag app ${{ secrets.DOCKER_USERNAME }}/damoacon:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/damoacon:latest | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
# 도커 작업 | |
script: | | |
docker pull ${{ secrets.DOCKER_USERNAME }}/damoacon:latest | |
docker stop $(docker ps -a -q) | |
docker run -d --log-driver=syslog -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/damoacon:latest | |
docker rm $(docker ps --filter 'status=exited' -a -q) | |
docker image prune -a -f |