Skip to content

Commit

Permalink
Merge pull request #319 from IceButler/cicd/#318-cicd
Browse files Browse the repository at this point in the history
#318 cicd 설정
  • Loading branch information
psyeon1120 authored Jul 6, 2024
2 parents 8c21031 + 0733af3 commit 847ba69
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 94 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: build

on:
pull_request:
branches: [ "develop" ]

jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Build and Test
run: ./gradlew build -x test
58 changes: 58 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: deploy

on:
push:
branches: [ "develop" ]

jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- run: touch ./src/main/resources/application.yml
- run: echo "${{ secrets.APPLICATION_SECRET }}" > ./src/main/resources/application.yml
- run: cat ./src/main/resources/application.yml

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Build and no Test
run: ./gradlew build -x test

- name: Docker build & push to dev
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/ice .
docker push ${{ secrets.DOCKER_USERNAME }}/ice
- name: Deploy to dev
uses: appleboy/ssh-action@master
id: deploy-dev
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo docker stop $(docker ps -a -q)
sudo docker rm $(docker ps -a -q)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/ice
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/ice
sudo docker image prune -f
15 changes: 15 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/ice
permissions:
- object: /home/ubuntu/ice/
owner: ubuntu
group: ubuntu
hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 60
runas: ubuntu
22 changes: 22 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

REPOSITORY=/home/ubuntu/ice
cd $REPOSITORY

APP_NAME=ice
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1)
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME

CURRENT_PID=$(pgrep -f $APP_NAME)

if [ -z $CURRENT_PID ]
then
echo "> 종료할 애플리케이션이 없습니다."
else
echo "> kill -9 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

echo "> Deploy - $JAR_PATH "
nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null &
94 changes: 0 additions & 94 deletions src/main/resources/application.yml

This file was deleted.

0 comments on commit 847ba69

Please sign in to comment.