-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (90 loc) · 3.33 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Deploy
on:
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_TAG: latest
jobs:
publish-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Get repository code
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
- name: Get image name in lowercase
id: formatting
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository }}
- name: Build and push Frontend Docker image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.formatting.outputs.lowercase }}-frontend:${{env.IMAGE_TAG}}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Backend Docker image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.formatting.outputs.lowercase }}-backend:${{env.IMAGE_TAG}}
labels: ${{ steps.meta.outputs.labels }}
# TODO: убрать хардкоды из путей и тд
deploy:
needs: [publish-image]
runs-on: ubuntu-latest
steps:
- name: Get repository code
uses: actions/checkout@v4
- name: Stop all containers
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: docker stop $(docker ps -a -q)
- name: Pull latest frontend image version
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: docker pull ${{ env.REGISTRY }}/${{ github.repository }}-frontend:${{env.IMAGE_TAG}}
- name: Pull latest backend image version
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: docker pull ${{ env.REGISTRY }}/${{ github.repository }}-backend:${{env.IMAGE_TAG}}
- name: Copy docker compose config to remote server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
source: "docker-compose.prod.yml"
target: /tmp
- name: Run container
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: NOTISEND_TOKEN=${{ secrets.NOTISEND_TOKEN }} docker compose -f /tmp/docker-compose.prod.yml up -d