-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (101 loc) · 3.75 KB
/
main.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: CI/CD
on:
push:
branches: ["develop"]
workflow_dispatch:
jobs:
tests:
name: Tests Ruff and pytest
runs-on: ubuntu-latest
strategy:
max-parallel: 3
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Ruff check
uses: chartboost/ruff-action@v1
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/test.requirements.txt
build_and_push_to_docker_hub:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v5
with:
file: ./docker/dev.Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend:latest
server_environment:
runs-on: ubuntu-latest
needs: build_and_push_to_docker_hub
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Create project directory and .env-file
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
sudo mkdir -p ${{ secrets.PROJECT_NAME }}
sudo chmod 777 ${{ secrets.PROJECT_NAME }}
sudo cat > ${{ secrets.PROJECT_NAME }}/.env << _EOF_
APP_TITLE=${{ secrets.APP_TITLE }}
APP_DESCRIPTION=${{ secrets.APP_DESCRIPTION }}
SECRET_KEY=${{ secrets.SECRET_KEY }}
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
PROJECT_NAME=${{ secrets.PROJECT_NAME }}
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
_EOF_
- name: copy infra files via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: "docker/server.docker-compose.yml, docker/nginx.conf"
target: ${{ secrets.PROJECT_NAME }}
overwrite: true
strip_components: 1
deploy:
runs-on: ubuntu-latest
needs: server_environment
steps:
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ${{ secrets.PROJECT_NAME }}
sudo docker-compose -f server.docker-compose.yml --env-file .env down
sudo docker rmi \
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_frontend \
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend
sudo systemctl stop nginx
sudo docker-compose -f server.docker-compose.yml --env-file .env up -d --quiet-pull