Merge pull request #112 from Likelion-YeungNam-Univ/feature-auth #50
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 CD with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. checkout | |
- uses: actions/checkout@v3 | |
# 2. Java 17 설정 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# 3. properties 설정 | |
- name: Set up application.yml | |
run: | | |
mkdir -p src/main/resources | |
echo "${{ secrets.APPLICATION }}" > src/main/resources/application.yml | |
# 4. gradlew build | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 | |
with: | |
arguments: build | |
# 5. Docker 이미지 빌드 | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/holing-was . | |
# 6. DockerHub 로그인 | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# 7. Docker Hub 이미지 푸시 | |
- name: docker Hub push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/holing-was | |
# 8. EC2 pull | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
script: | | |
docker stop holing-was-container | |
docker rm holing-was-container | |
docker image prune -af | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/holing-was | |
docker run -d -p 8080:8080 --name holing-was-container -e TZ=Asia/Seoul ${{ secrets.DOCKERHUB_USERNAME }}/holing-was |