Java CI with Gradle #37
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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: '배포할 브랜치를 입력합니다. (예: release/1.0.0)' | |
required: true | |
default: 'release/1.0.0' | |
tag: | |
description: '배포내용을 입력합니다.' | |
required: true | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.branch }} | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: create remote directory | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: mkdir -p /home/ubuntu/srv/ubuntu | |
- name: copy source via ssh key | |
uses: burnett01/[email protected] | |
with: | |
switches: -avzr --delete | |
remote_path: /home/ubuntu/srv/ubuntu | |
remote_host: ${{ secrets.HOST }} | |
remote_user: ubuntu | |
remote_key: ${{ secrets.KEY }} | |
## create application-prod.yml | |
- name: make application-prod.yml | |
run: | | |
## create application-prod.yml | |
cd ./src/main/resources | |
# application-database.yml 파일 생성 | |
touch ./application-prod.yml | |
# GitHub-Actions 에서 설정한 값을 application-prod.yml 파일에 쓰기 | |
echo "${{ secrets.PROD_YML }}" >> ./application-prod.yml | |
shell: bash | |
## gradle build | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
## 웹 이미지 빌드 및 도커허브에 push | |
- name: web docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_REPO }}/modutime-web . | |
docker push ${{ secrets.DOCKER_REPO }}/modutime-web | |
## docker compose up | |
- name: executing remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: | | |
cd /home/ubuntu/srv/ubuntu | |
sudo sh install-docker.sh | |
sudo docker rm -f $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/modutime-web | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/modutime-nginx | |
sudo docker-compose up -d | |
sudo docker image prune -f |