ci: MySQL 이미지 추가 #58
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 API Server | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'package.json' | |
- 'bun.lockb' | |
- 'tsconfig.json' | |
- 'Dockerfile' | |
- 'prisma/**' | |
- 'src/**' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DK_USERNAME }} | |
password: ${{ secrets.DK_TOKEN }} | |
- name: Create .env file with Secrets | |
uses: SpicyPizza/[email protected] | |
with: | |
envkey_DB_DATABASE: ${{ secrets.DB_DATABASE }} | |
envkey_DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
envkey_DB_HOST: ${{ secrets.DB_HOST }} | |
envkey_DB_PORT: ${{ secrets.DB_PORT }} | |
envkey_DB_USER: ${{ secrets.DB_USER }} | |
envkey_DK_IMAGE: ${{ secrets.DK_IMAGE }} | |
envkey_DK_USERNAME: ${{ secrets.DK_USERNAME }} | |
envkey_NODE_ENV: ${{ secrets.NODE_ENV }} | |
envkey_JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
envkey_PORT: ${{ secrets.PORT }} | |
envkey_TZ: ${{ secrets.TZ }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.DK_USERNAME }}/${{ secrets.DK_IMAGE }}:latest | |
- name: Send docker-compose.yml, .env to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ubuntu | |
key: ${{ secrets.EC2_KEY }} | |
source: docker-compose.yml,.env | |
target: /home/ubuntu/ | |
- name: Deploy Docker to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ubuntu | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
export $(cat .env | xargs) | |
sudo docker compose pull | |
sudo docker compose up -d | |
sudo docker container prune -f | |
sudo docker image prune -f | |
rm -f docker-compose.yml .env |