Merge pull request #57 from dajeongdev/feature/github-actions #15
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: Auto Deploy | |
on: | |
push: | |
branches: | |
- develop | |
jobs: | |
build: | |
name: Push to NCP container registry | |
runs-on: ubuntu-latest | |
steps: | |
# checkout | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# JDK setting | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
# secret yml file 생성 | |
- name: Set secret yml | |
run: | | |
mkdir -p src/main/resources | |
echo "${{ secrets.DATABASE_YML }}" | base64 --decode > src/main/resources/application-database.yml | |
echo "${{ secrets.NAVER_TOKEN_YML }}" | base64 --decode > src/main/resources/application-naver-token.yml | |
echo "${{ secrets.SECURITY_YML }}" | base64 --decode > src/main/resources/application-security.yml | |
find src | |
shell: bash | |
# Gradle 권한 부여 | |
- name: Grant permission for gradlew | |
run: chmod +x ./gradlew | |
# 테스트 없이 빌드 | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
# Docker Buildx 설치 | |
- 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 }}/americanote:latest | |
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/americanote:latest | |
cache-to: type=inline | |
deploy: | |
name: Connect server ssh and pull from container registry | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Connect ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_HOST }} | |
username: ${{ secrets.NCP_USERNAME }} | |
password: ${{ secrets.NCP_PASSWORD }} | |
port: ${{ secrets.NCP_PORT }} | |
script: | | |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/americanote | |
docker stop $(docker ps -a -q) | |
docker rm $(docker ps -a -q) | |
docker run -d -p 8009:80 --name americanote_docker ${{ secrets.NCP_CONTAINER_REGISTRY }}/americanote | |
docker image prune -f |