Skip to content

Merge pull request #209 from OutDecision/issue/197 #81

Merge pull request #209 from OutDecision/issue/197

Merge pull request #209 from OutDecision/issue/197 #81

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "develop" ]
# pull_request:
# branches: [ "develop" ]
permissions:
contents: read
jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정
push_to_registry:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set environment variable
run: echo "DB_URL:$DB_URL,DB_USER:$DB_USER,DB_PASS:$DB_PASS,REDIS_HOST:$REDIS_HOST,REDIS_PASS:$REDIS_PASS,REDIS_PORT:$REDIS_PORT"
# 1. Java 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# 2. Gradle Wrapper 스크립트에 실행 권한 부여
- name: Grant execute permission to Gradle Wrapper script
run: chmod +x ./gradlew
# 3. Spring Boot 애플리케이션 빌드
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: clean bootJar
- name: Login to NCP Container Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/docker-springboot:latest
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/docker-springboot:latest
cache-to: type=inline
build-args: |
DB_URL=${{ secrets.DB_URL }}
DB_USER=${{ secrets.DB_USER }}
DB_PASS=${{ secrets.DB_PASS }}
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PASS=${{ secrets.REDIS_PASS }}
REDIS_PORT=${{ secrets.REDIS_PORT }}
JOIN_SECRET=${{ secrets.JOIN_SECRET }}
GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_REDIRECT_URI=${{ secrets.GOOGLE_REDIRECT_URI }}
KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}
KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}
NCP_ACCESS_KEY=${{ secrets.NCP_ACCESS_KEY }}
NCP_SECRET_KEY=${{ secrets.NCP_SECRET_KEY }}
BUCKET_NAME=${{ secrets.BUCKET_NAME }}
IP=${{ secrets.IP }}
DEFAULT_PROFILE_IMG=${{ secrets.DEFAULT_PROFILE_IMG }}
pull_from_registry:
name: Connect server ssh and pull from container registry
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: connect ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_HOST }}
username: ${{ secrets.DEV_USERNAME }}
password: ${{ secrets.DEV_PASSWORD }}
port: ${{ secrets.DEV_PORT }}
script: |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/docker-springboot
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker run -d -p 8080:8080 --name con ${{ secrets.NCP_CONTAINER_REGISTRY }}/docker-springboot
docker image prune -f