-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (66 loc) · 2.06 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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: /tmp
- name: Deploy Docker to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
script_stop: true
script: |
cd /tmp
export $(cat .env | xargs)
docker compose pull
docker compose up -d
docker container prune -f
docker image prune -f
rm -f docker-compose.yml .env