코드 리팩터링 및 CI/CD 작업 수정 #158
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: [ "develop" ] | |
pull_request: | |
branches: [ "develop" ] | |
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-base-addi.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-base-addi.yml | |
echo "${{ secrets.BASE_ADDI }}" > ./application-base-addi.yml | |
shell: bash | |
- name: Make docker-compose-prod.yml | |
run: | | |
touch ./docker-compose-prod.yml | |
echo "${{ secrets.DOCKER_COMPOSE }}" > ./docker-compose-prod.yml | |
shell: bash | |
- name: Build with Gradle | |
run: | | |
chmod +x ./gradlew | |
./gradlew bootJar | |
- name: Send docker-compose-prod.yml | |
uses: appleboy/ssh-action@v1.0.1 | |
with: | |
host: ${{ secrets.BACKEND_HOST }} | |
username: ${{ secrets.BACKEND_USERNAME }} | |
password: ${{ secrets.BACKEND_PASSWORD }} | |
port: ${{ secrets.BACKEND_PORT }} | |
script: | | |
scp /docker-compose-prod.yml ${{ secrets.BACKEND_USERNAME }}@${{ secrets.BACKEND_HOST }}:${{ secrets.BACKEND_PATH }}/docker-compose-prod.yml | |
- name: Docker build and push to docker repo | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
docker build -t ${{ secrets.BACKEND_PROJECT_NAME }} --build-arg PROFILES=prod . | |
docker push ${{ secrets.BACKEND_PROJECT_NAME }} | |
- name: remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.BACKEND_HOST }} | |
username: ${{ secrets.BACKEND_USERNAME }} | |
key: ${{ secrets.BACKEND_PASSWORD }} | |
port: ${{ secrets.BACKEND_PORT }} | |
script: | | |
sudo docker-compose -f ${{ secrets.BACKEND_PATH }}/docker-compose-prod.yml down | |
sudo docker rmi ${{ secrets.BACKEND_PROJECT_NAME }} | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
sudo docker pull ${{ secrets.BACKEND_PROJECT_NAME }} | |
sudo docker-compose -f ${{ secrets.BACKEND_PATH }}/docker-compose-prod.yml up -d | |
sudo docker image prune -f |