Skip to content

Commit 4bf1eca

Browse files
authored
Merge pull request #7 from Xpirix/pre-deployment-setup
Pre deployment setup
2 parents 41efa2c + e529fdb commit 4bf1eca

File tree

14 files changed

+567
-192
lines changed

14 files changed

+567
-192
lines changed

deployment/.env.example

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copy paste the env variable as .env to use
2-
COMPOSE_PROJECT_NAME=qgis_changelog_website
2+
COMPOSE_PROJECT_NAME=qgis_members_website
33

44
## Btsync credentials notes:
55
# The environment file should define two variables:
@@ -32,7 +32,7 @@ VIRTUAL_HOST=members.qgis.org
3232
VIRTUAL_PORT=8080
3333

3434
# DB Backups
35-
DUMPPREFIX=PG_QGIS_CHANGELOG
35+
DUMPPREFIX=PG_QGIS_MEMBERS
3636

3737

3838
# Nginx config
@@ -49,16 +49,18 @@ VALID_DOMAIN=["localhost", "members.qgis.org", "staging.members.qgis.org"]
4949

5050
# Email
5151
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
52-
EMAIL_HOST=''
53-
EMAIL_PORT=25
52+
EMAIL_HOST='smtp.resend.com'
53+
EMAIL_PORT=465
5454
EMAIL_USE_TLS=True
55-
EMAIL_HOST_USER=''
56-
EMAIL_HOST_PASSWORD=''
57-
EMAIL_SUBJECT_PREFIX=''
55+
EMAIL_HOST_USER="resend" # e.g., no-reply@yourdomain.com
56+
EMAIL_HOST_PASSWORD="your_resend_api_key" # Your Resend API key
57+
EMAIL_SUBJECT_PREFIX='[QGIS Sustaining Members]'
5858
MAILDOMAIN=''
5959
SERVER_EMAIL=''
6060
ADMIN_EMAIL=''
61-
DEFAULT_FROM_EMAIL=''
61+
DEFAULT_FROM_EMAIL='no-reply@yourdomain.com'
62+
# Resend email
63+
RESEND_EMAIL_API_KEY=''
6264

6365
# Stripe
6466
STRIPE_LIVE_SECRET_KEY='sk_live_key'
@@ -70,3 +72,9 @@ DJSTRIPE_WEBHOOK_SECRET='whsec_'
7072
# SENTRY
7173
SENTRY_DSN=''
7274
SENTRY_RATE=0.2
75+
76+
# Deployment environment: dev, staging, prod or prod-ssl
77+
WEB_ENV=prod-ssl
78+
79+
# UWSGI Docker Image
80+
UWSGI_DOCKER_IMAGE=qgis/qgis-members-uwsgi:latest

deployment/docker-compose.override.example.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ volumes:
77
type: none
88
device: ${PWD}/pg/postgres_data
99
o: bind
10-
db-backups:
11-
driver_opts:
12-
type: none
13-
device: ${PWD}/backups
14-
o: bind
1510
static-data:
1611
driver_opts:
1712
type: none
@@ -34,27 +29,30 @@ volumes:
3429
o: bind
3530
services:
3631
uwsgi:
32+
image: ${UWSGI_DOCKER_IMAGE}
3733
build:
3834
context: ${PWD}/../
3935
dockerfile: deployment/docker/Dockerfile
4036
target: prod
4137
volumes:
4238
- ../django_project:/home/web/django_project
39+
- ${MEDIA_VOLUME}:/home/web/media:rw
4340
- ./logs:/var/log
4441

4542
web:
4643
volumes:
4744
- ./logs:/var/log/nginx
45+
- ${MEDIA_VOLUME}:/home/web/media:ro
4846
ports:
49-
- "${HTTP_PORT}:8080"
47+
- "${HTTP_PORT}:80"
5048
- "${HTTPS_PORT}:443"
5149

5250
devweb:
53-
image: kartoza/project-uwsgi:dev-latest
5451
build:
5552
context: ${PWD}/../
5653
dockerfile: deployment/docker/Dockerfile
5754
target: dev
5855
volumes:
5956
- ../django_project:/home/web/django_project
57+
- ${MEDIA_VOLUME}:/home/web/media:rw
6058
- ./logs:/var/log

deployment/docker-compose.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ volumes:
1414
reports-data:
1515
nginx-conf:
1616
services:
17-
# smtp:
18-
# image: catatnight/postfix
19-
# hostname: postfix
20-
# environment:
21-
# # You could change this to something more suitable
22-
# - maildomain=kartoza.com
23-
# - smtp_user=noreply:docker
24-
# restart: unless-stopped
2517

2618
db:
2719
image: kartoza/postgis:16-3.4
@@ -35,12 +27,17 @@ services:
3527
restart: unless-stopped
3628
ports:
3729
- "7543:5432"
30+
networks:
31+
internal:
3832

3933
uwsgi: &uwsgi-common
34+
image: ${UWSGI_DOCKER_IMAGE}
4035
build:
4136
context: ${PWD}/../
4237
dockerfile: deployment/docker/Dockerfile
4338
target: prod
39+
expose:
40+
- "8080"
4441
environment:
4542
- DATABASE_NAME=${DATABASE_NAME}
4643
- DATABASE_USERNAME=${DATABASE_USERNAME}
@@ -73,6 +70,7 @@ services:
7370
- static-data:/home/web/static:rw
7471
- media-data:/home/web/media:rw
7572
- reports-data:/home/web/reports
73+
- ./docker/uwsgi.conf:/uwsgi.conf
7674
command: bash -c "npm install && npm run build && uwsgi --ini /uwsgi.conf"
7775
links:
7876
- db:db
@@ -84,6 +82,8 @@ services:
8482
options:
8583
max-size: "10m"
8684
max-file: "10"
85+
networks:
86+
internal:
8787

8888
dbbackups:
8989
image: kartoza/pg-backup:16-3.4
@@ -104,14 +104,25 @@ services:
104104
- POSTGRES_HOST=${DATABASE_HOST}
105105
- PGDATABASE=${DATABASE_NAME}
106106
restart: unless-stopped
107+
networks:
108+
internal:
107109

108110
# This is normally the main entry point for a production server
109111
web:
110112
image: nginx
113+
entrypoint:
114+
- /etc/nginx/sites-available/docker-entrypoint.sh
115+
ports:
116+
- "80:80"
117+
- "443:443"
118+
command:
119+
- ${WEB_ENV}
111120
volumes:
112-
- nginx-conf:/etc/nginx/conf.d:ro
121+
- nginx-conf:/etc/nginx/sites-available/:ro
113122
- static-data:/home/web/static:ro
114123
- media-data:/home/web/media:ro
124+
- ./webroot:/var/www/webroot
125+
- ./certbot-etc:/etc/letsencrypt
115126
links:
116127
- uwsgi:uwsgi
117128
restart: unless-stopped
@@ -120,6 +131,8 @@ services:
120131
options:
121132
max-size: "10m"
122133
max-file: "10"
134+
networks:
135+
internal:
123136

124137
# This is the entry point for a development server.
125138
# Run with --no-deps to run attached to the services
@@ -132,6 +145,8 @@ services:
132145
target: dev
133146
ports:
134147
- "62202:8000"
148+
networks:
149+
internal:
135150

136151
webpack:
137152
build:
@@ -144,5 +159,21 @@ services:
144159
- ../django_project:/home/web/django_project
145160
- static-data:/home/web/static:rw
146161
- ${MEDIA_VOLUME}:/home/web/media:rw
162+
networks:
163+
internal:
164+
165+
certbot:
166+
image: certbot/certbot
167+
container_name: certbot
168+
volumes:
169+
- ./webroot:/var/www/webroot
170+
- ./certbot-etc:/etc/letsencrypt
171+
depends_on:
172+
- web
173+
command: certonly --webroot --webroot-path=/var/www/webroot --email admin@qgis.org --agree-tos --no-eff-email --force-renewal -d ${VIRTUAL_HOST:-members.qgis.org}
174+
networks:
175+
internal:
147176

148177

178+
networks:
179+
internal:

deployment/docker/REQUIREMENTS.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ pyjwt~=2.8
5757
# New dependencies
5858
# Webpack
5959
django-webpack-loader~=3.1
60-
sorl-thumbnail~=12.11
60+
sorl-thumbnail~=12.11
61+
62+
# Resend email
63+
resend~=2.7

deployment/docker/uwsgi.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ module = core.wsgi
77
master = true
88
pidfile=/tmp/django.pid
99
socket = 0.0.0.0:8080
10-
http-socket = 0.0.0.0:80
1110
workers = 4
1211
cheaper = 2
1312
env = DJANGO_SETTINGS_MODULE=core.settings.prod_docker
1413
# disabled so we run in the foreground for docker
1514
#daemonize = /tmp/django.log
1615
req-logger = file:/var/log/uwsgi-requests.log
1716
logger = file:/var/log/uwsgi-errors.log
18-
log
19-
reload-os-env
20-
#uid = 1000
21-
#gid = 1000
2217
memory-report = true
2318
harakiri = 100
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This directory is used to contain nginx configuration
2+
when using a non dockergen nginx configuration.
3+
4+
See docker-compose.yml to see how it is used.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ server {
1616
error_log /var/log/nginx/error.log;
1717

1818
# the port your site will be served on
19-
listen 8080;
19+
listen 80;
2020
# the domain name it will serve for
2121
server_name "";
2222
charset utf-8;
@@ -84,5 +84,6 @@ server {
8484
uwsgi_param REMOTE_PORT $remote_port;
8585
uwsgi_param SERVER_PORT $server_port;
8686
uwsgi_param SERVER_NAME $server_name;
87+
8788
}
8889
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
# Clean up sites-enabled
4+
echo "Clean sites-enabled"
5+
rm -rf /etc/nginx/conf.d/*.conf
6+
mkdir -p /etc/nginx/conf.d
7+
8+
if [ $# -eq 1 ]; then
9+
case $1 in
10+
# Debug mode, enable dev.conf
11+
[Dd][Ee][Vv])
12+
echo "Run in debug mode"
13+
CONF_FILE=dev.conf
14+
ln -s /etc/nginx/sites-available/$CONF_FILE /etc/nginx/conf.d/$CONF_FILE
15+
exec nginx -g "daemon off;"
16+
;;
17+
# Production mode, run using uwsgi
18+
[Pp][Rr][Oo][Dd])
19+
echo "Run in prod mode"
20+
CONF_FILE=prod.conf
21+
ln -s /etc/nginx/sites-available/$CONF_FILE /etc/nginx/conf.d/$CONF_FILE
22+
exec nginx -g "daemon off;"
23+
;;
24+
# Production SSL mode, run using uwsgi
25+
[Pp][Rr][Oo][Dd][-][Ss][Ss][Ll])
26+
echo "Run in prod SSL mode"
27+
CONF_FILE=prod-ssl.conf
28+
ln -s /etc/nginx/sites-available/$CONF_FILE /etc/nginx/conf.d/$CONF_FILE
29+
exec nginx -g "daemon off;"
30+
;;
31+
# Staging SSL mode, run using uwsgi
32+
[Ss][Tt][Aa][Gg][Ii][Nn][Gg])
33+
echo "Run in staging SSL mode"
34+
CONF_FILE=staging.conf
35+
ln -s /etc/nginx/sites-available/$CONF_FILE /etc/nginx/conf.d/$CONF_FILE
36+
exec nginx -g "daemon off;"
37+
;;
38+
esac
39+
fi
40+
41+
# Run as bash entrypoint
42+
exec "$@"

0 commit comments

Comments
 (0)