Server/release/#0.5.6 aws 배포 #31
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: CI/CD Docker | |
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- 'server/release/*' | |
env: | |
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/nest-openlist-deploy | |
VERSION: ${{ github.sha }} | |
NAME: go_cicd | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out source code | |
uses: actions/checkout@v2 | |
# .env 파일 생성 | |
- name: Generate .env file | |
run: | | |
cat << EOF > ./server/.env | |
JWT_SECRET=${{ secrets.JWT_SECRET }} | |
ACCESS_TOKEN_EXPIRES=${{ secrets.ACCESS_TOKEN_EXPIRES }} | |
REFRESH_TOKEN_EXPIRES=${{ secrets.REFRESH_TOKEN_EXPIRES }} | |
HASH_ROUNDS=${{ secrets.HASH_ROUNDS }} | |
PROTOCOL=${{ secrets.PROTOCOL }} | |
HOST=${{ secrets.HOST }} | |
DB_HOST=${{ secrets.DB_HOST }} | |
DB_PORT=${{ secrets.DB_PORT }} | |
DB_USERNAME=${{ secrets.DB_USERNAME }} | |
DB_PASSWORD=${{ secrets.DB_PASSWORD }} | |
DB_DATABASE=${{ secrets.DB_DATABASE }} | |
SUB=${{ secrets.SUB }} | |
ALG=${{ secrets.ALG }} | |
KID=${{ secrets.KID }} | |
ISS=${{ secrets.ISS }} | |
AUTHKEY=${{ secrets.AUTHKEY }} | |
X_NCP_CLOVASTUDIO_API_KEY=${{ secrets.X_NCP_CLOVASTUDIO_API_KEY }} | |
X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }} | |
X_NCP_CLOVASTUDIO_REQUEST_ID=${{ secrets.X_NCP_CLOVASTUDIO_REQUEST_ID }} | |
REDIS_URL=${{ secrets.REDIS_URL }} | |
REDIS_USERNAME=${{ secrets.REDIS_USERNAME }} | |
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} | |
ADMIN_EMAIL=${{ secrets.ADMIN_EMAIL }} | |
ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }} | |
EOF | |
- name: Generate .p8 file | |
run: | | |
cat << EOF > ./server/.p8 | |
${{ secrets.P8 }} | |
EOF | |
- name: Set up docker buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ env.VERSION }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: ./server | |
file: ./server/Dockerfile | |
push: true | |
tags: ${{ env.DOCKER_IMAGE }}:latest | |
# 배포 Job - 서버 1 | |
deploy-server1: | |
needs: build | |
name: Deploy to Server 1 | |
runs-on: [ self-hosted, label-server1 ] | |
steps: | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Docker run (Server 1) | |
run: | | |
docker stop go_cicd1 || true | |
docker rm go_cicd1 || true | |
docker pull ${{ env.DOCKER_IMAGE }}:latest | |
docker run -d -p 3000:3000 --name go_cicd1 --restart always ${{ env.DOCKER_IMAGE }}:latest | |
# 배포 Job - 서버 2 | |
deploy-server2: | |
needs: build | |
name: Deploy to Server 2 | |
runs-on: [ self-hosted, label-server2 ] | |
steps: | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Docker run (Server 2) | |
run: | | |
docker stop go_cicd2 || true | |
docker rm go_cicd2 || true | |
docker pull ${{ env.DOCKER_IMAGE }}:latest | |
docker run -d -p 3000:3000 --name go_cicd2 --restart always ${{ env.DOCKER_IMAGE }}:latest |