Skip to content

Commit

Permalink
github flow 파일 재생성.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ddackkeun authored Apr 29, 2024
1 parent d9ca87d commit 1090620
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Java CI/CD 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/scp-action@master
with:
host: ${{ secrets.BACKEND_HOST }}
username: ${{ secrets.BACKEND_USERNAME }}
key: ${{ secrets.BACKEND_PRIVATE_KEY }}
port: ${{ secrets.BACKEND_PORT }}
source: "./docker-compose-prod.yml"
target: ${{ secrets.BACKEND_PATH }}

- 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

0 comments on commit 1090620

Please sign in to comment.