-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (84 loc) · 3.08 KB
/
backend.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: backend CI/CD
on:
pull_request:
branches: [main]
paths:
- "front/src/**"
- "backend/src/**"
jobs:
path_changes:
runs-on: ubuntu-latest
outputs:
front: ${{ steps.filter.outputs.front }}
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
front:
- 'front/src/**'
backend:
- 'backend/src/**'
build_and_push_backend:
needs: path_changes
if: needs.path_changes.outputs.backend == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN_BACKEND }}
- name: Set up Docker Meta for Backend
id: docker_meta_backend
uses: docker/metadata-action@v5
with:
images: ${{ secrets.BACKEND_DOCKER_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=branch
type=ref,event=pr
type=sha
flavor: |
latest=true
- name: Build and Push Frontend Docker Image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta_backend.outputs.tags }}
labels: ${{ steps.docker_meta_backend.outputs.labels }}
no-cache: true
build-args: |
DEV_FRONT_URL=${{ secrets.DEV_FRONT_URL }}
PROD_FRONT_URL=${{ secrets.PROD_FRONT_URL }}
GMAIL_USER=${{ secrets.GMAIL_USER}}
MAIL_APP_PASSWORD=${{ secrets.MAIL_APP_PASSWORD }}
JWT_SIGNATURE=${{ secrets.JWT_SIGNATURE }}
DEV_MYSQL_PASSWORD=${{ secrets.DEV_MYSQL_PASSWORD }}
DEV_MYSQL_DATABASE=${{ secrets.DEV_MYSQL_DATABASE }}
PROD_MYSQL_USERNAME=${{ secrets.PROD_MYSQL_USERNAME }}
PROD_MYSQL_PASSWORD=${{ secrets.PROD_MYSQL_PASSWORD }}
PROD_MYSQL_DATABASE=${{ secrets.PROD_MYSQL_DATABASE }}
PROD_MYSQL_HOST=${{ secrets.PROD_MYSQL_HOST }}
BACK_END_NODE_ENV=${{ secrets.BACK_END_NODE_ENV }}
- name: EC2 Backend Docker Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.BACKEND_EC2_HOST }}
username: ec2-user
key: ${{ secrets.BACKEND_EC2_PEM_KEY }}
script: |
docker stop ${{ secrets.BACKEND_DOCKER_CONTAINER }} || true
docker rm ${{ secrets.BACKEND_DOCKER_CONTAINER }} || true
docker pull ${{ secrets.BACKEND_DOCKER_IMAGE }}:latest
docker run --name ${{ secrets.BACKEND_DOCKER_CONTAINER }} --rm -d -p 8080:80 ${{ secrets.BACKEND_DOCKER_IMAGE }}:latest