Update gradle.yml #24
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 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' | |
# yml 주입 | |
- name: make ymls | |
run: | | |
cd ./src/main/resources | |
touch ./application-prod.yml | |
echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml | |
touch ./application-redis.yml | |
echo "${{ secrets.APPLICATION_REIDS }}" > ./application-redis.yml | |
touch ./application-mail.yml | |
echo "${{ secrets.APPLICATION_MAIL }}" > ./application-mail.yml | |
touch ./secrets.yml | |
echo "${{ secrets.SECRETS }}" > ./secrets.yml | |
touch ./application-s3.yml | |
echo "${{ secrets.APPLICATION_S3 }}" > ./application-s3.yml | |
# 권한 부여 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# 배포 전 테스트 | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
# 도커 허브 푸쉬 | |
- name: Docekr Build | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/hbc . | |
docker push ${{ secrets.DOCKER_USERNAME }}/hbc | |
# 도커 컨테이너 변경 | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ec2-user | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
script: | | |
sudo docker rm $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/hbc | |
docker-compose up -d | |
sudo docker image prune -f | |