[chore] #139 develop 브랜치 cicd #1
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
name: Java CI & CD with Gradle | |
on: | |
push: | |
branches: | |
- chore/139-server-seperation | |
- 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: application.yml 설정 | |
run: | | |
cd ./src/main | |
mkdir resources | |
cd ./resources | |
touch ./application.yml | |
echo "$APPLICATION_DEVELOP" > ./application.yml | |
env: | |
APPLICATION_DEVELOP: ${{ secrets.APPLICATION_DEVELOP }} | |
- 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- | |
# gradle build | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
## 웹 이미지 빌드 및 도커허브에 push | |
- name: web docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_REPO }}/ussum-develop:latest . | |
docker push ${{ secrets.DOCKER_REPO }}/ussum-develop:latest | |
## 도커 허브에서 jar파일 및 pull후에 컴포즈 up | |
- name: Deploy to Dev | |
uses: appleboy/ssh-action@master | |
with: | |
username: ubuntu | |
host: ${{ secrets.DEVELOP_HOST }} | |
key: ${{ secrets.DEVELOP_KEY }} | |
script: | | |
sudo docker stop ussum-develop || true | |
sudo docker container prune -f | |
sudo docker pull ${{ secrets.DOCKER_REPO }}/ussum-develop:latest | |
sudo docker run -d --log-driver=syslog \ | |
-e TZ=Asia/Seoul \ | |
-p 8080:8080 --name ussum-develop \ | |
${{ secrets.DOCKERHUB_REPO }}/ussum-develop:latest |