-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (110 loc) · 4.1 KB
/
ci-cd-pipeline.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# .github/workflows/ci-cd-pipeline.yml
name: CI/CD Pipeline
on:
push:
branches: [main]
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
DJANGO_DEBUG: "True"
DJANGO_SECURE_SSL_REDIRECT: "False"
DJANGO_SECURE_HSTS_SECONDS: 0
DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS: "False"
DJANGO_SECURE_HSTS_PRELOAD: "False"
DJANGO_SESSION_COOKIE_SECURE: "False"
DJANGO_CSRF_COOKIE_SECURE: "False"
MDB_PRO_KEY: ${{ secrets.MDB_PRO_KEY }}
AWS_REGION: us-west-2
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-
- name: Create .env file
run: |
echo "DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }}" >> .env
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> .env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" >> .env
echo "POSTGRES_HOST=${{ secrets.POSTGRES_HOST }}" >> .env
echo "MDB_PRO_KEY=${{ secrets.MDB_PRO_KEY }}" >> .env
- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: false
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Start Docker Compose services
run: docker-compose up -d
- name: Run backend tests
run: docker-compose run web pytest
- name: Add MDB API Key
run: docker-compose exec -T web python manage.py addapikey
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: "20.x"
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: ./frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node.js dependencies
run: npm install
working-directory: ./frontend/
- name: Run frontend tests
run: npm test
working-directory: ./frontend/
- name: Remove MDB API Key
run: docker-compose exec -T web python manage.py removeapikey
- name: Zip the Dockerrun.aws.json file
run: zip dockerrun.zip Dockerrun.aws.json
- name: Docker Hub Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
logout: True
- name: Build Docker image
run: docker build -t mastertheorem-aws .
- name: Tag Docker image
run: docker tag mastertheorem-aws:latest drcbeatz/mastertheorem-aws:latest
- name: Push to Docker Hub
run: docker push drcbeatz/mastertheorem-aws:latest
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install EB CLI and Deploy
run: |
pip install awsebcli --upgrade
eb use mastertheorem-aws-dev --region ${{ env.AWS_REGION }}
eb deploy --staged --region ${{ env.AWS_REGION }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Clean up
run: docker-compose down