Fix: 스크립트 수정 #7
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: Deploy to Naver Cloud Platform | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
workflow_dispatch: | |
env: | |
PROJECT_NAME: seesaw-app | |
jobs: | |
build_and_push: | |
name: Build and Push to NCP container registry | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Make application-secret.yml | |
run: echo ${{ secrets.APPLICATION_SECRET_BASE64 }} | base64 --decode > ./src/main/resources/application-secret.yml | |
- name: Make application-dev.yml | |
run: echo ${{ secrets.APPLICATION_DEV_BASE64 }} | base64 --decode > ./src/main/resources/application-dev.yml | |
- name: Make application-prod.yml | |
run: echo ${{ secrets.APPLICATION_PROD_BASE64 }} | base64 --decode > ./src/main/resources/application-prod.yml | |
- name: Create Firebase Admin SDK JSON | |
uses: jsdaniell/[email protected] | |
with: | |
name: "madii-app-firebase-adminsdk-uriyk-c04677456f.json" | |
json: ${{ secrets.FIREBASE_KEY_JSON }} | |
dir: "src/main/resources/" | |
- 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: Build with Gradle | |
run: ./gradlew build | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- 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: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/${{ env.PROJECT_NAME }}:latest | |
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/${{ env.PROJECT_NAME }}:latest | |
cache-to: type=inline | |
deploy: | |
name: Deploy to NCP server | |
needs: build_and_push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setting NCP CLI & Credentials | |
run: | | |
cd ~ | |
wget https://www.ncloud.com/api/support/download/5/65 | |
unzip 65 | |
mkdir ~/.ncloud | |
echo -e "[DEFAULT]\nncloud_access_key_id = ${{ secrets.NCP_ACCESS_KEY }}\nncloud_secret_access_key = ${{ secrets.NCP_SECRET_KEY }}\nncloud_api_url = https://ncloud.apigw.ntruss.com" >> ~/.ncloud/configure | |
- name: deploy file | |
uses: wlixcc/[email protected] | |
with: | |
username: 'root' | |
server: ${{ secrets.NCP_DEV_HOST }} | |
password: ${{ secrets.NCP_DEV_PASSWORD }} | |
local_path: './docker-compose.yml' | |
remote_path: '/root' | |
sftpArgs: '-o ConnectTimeout=5' | |
- name: Connect SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_DEV_HOST }} | |
username: root | |
password: ${{ secrets.NCP_DEV_PASSWORD }} | |
port: 22 | |
script: | | |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/${{ env.PROJECT_NAME }}:latest | |
docker stop ${{ env.PROJECT_NAME }} || true | |
docker rm ${{ env.PROJECT_NAME }} || true | |
docker run -d --name ${{ env.PROJECT_NAME }} -p 8080:8080 \ | |
-e SPRING_PROFILES_ACTIVE=prod \ | |
${{ secrets.NCP_CONTAINER_REGISTRY }}/${{ env.PROJECT_NAME }}:latest | |
docker image prune -f | |