-
Notifications
You must be signed in to change notification settings - Fork 3
111 lines (96 loc) · 3.17 KB
/
django-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Web Application CI/CD Pipeline
on:
push:
branches:
- main
pull_request_target:
types: [closed, labeled]
jobs:
CI:
runs-on: ubuntu-latest
services:
db:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.DATABASE_USER_PASSWORD }}
MYSQL_DATABASE: ${{ secrets.DATABASE_NAME }}
MYSQL_USER: ${{ secrets.DATABASE_USER }}
MYSQL_PASSWORD: ${{ secrets.DATABASE_USER_PASSWORD }}
ports:
- 3306:3306
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create .env file
run: |
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "DEBUG=${{ secrets.DEBUG }}" >> .env
echo "DJANGO_DEPLOY=${{ secrets.DJANGO_DEPLOY }}" >> .env
echo "DATABASE_ENGINE=${{ secrets.DATABASE_ENGINE }}" >> .env
echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_USER_PASSWORD=${{ secrets.DATABASE_USER_PASSWORD }}" >> .env
echo "DATABASE_HOST=db" >> .env
echo "DATABASE_PORT=3306" >> .env
echo "CELERY_BROKER_URL=${{ secrets.CELERY_BROKER_URL }}" >> .env
echo "CELERY_RESULT_BACKEND=${{ secrets.CELERY_RESULT_BACKEND }}" >> .env
cat .env
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run migrations and tests
run: |
cat .env
python manage.py makemigrations
python manage.py migrate
python manage.py test
build_and_push:
needs: CI
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:latest
deploy:
needs: build_and_push
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: SSH into server and pull Docker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /root/linenow-dev
docker-compose down
docker-compose pull
docker-compose up -d
- name: Collect static files
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
docker exec linenow-was python manage.py collectstatic --noinput