Skip to content

Commit 94d96c2

Browse files
authored
Merge pull request #14 from developmentseed/deploy
Deploy with docker-caddy
2 parents 4323ea6 + 83c8328 commit 94d96c2

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

deploy/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Deploying vbos-backend
2+
3+
This app is currently deployed on a Digital Ocean Droplet using docker-caddy reverse proxy.
4+
All deploy related configuration are in the `deploy/` directory.
5+
6+
1. `deploy/caddy/docker-compose.yml` — starts the caddy reverse proxy which will watch any new containers with the caddy label.
7+
2. `deploy/vbos/docker-compose.yml` — pulls the latest vbos-backend image and runs the application, with `.env` as the environment.
8+
9+
To update or redeploy:
10+
1. First ssh into the server. Keys are in 1PW
11+
2. Fetch code and run migrations.
12+
* Activate venv. `. ~/vbos-env/bin/activate`
13+
* `cd vbos-backend && git pull`. `python manage.py migrate`
14+
3. Then run `docker compose -f deploy/vbos/docker-compose.yml pull` to pull the new image. By default the image tag is `main`
15+
4. Then run `docker compose -f deploy/vbos/docker-compose.yml --env-file /home/devseed/vbos-backend/.env up --force-recreate -d --no-deps vbos-backend` — this will start a new container and kill the older one for deploys with no downtime

deploy/caddy/docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
caddy:
3+
image: lucaslorentz/caddy-docker-proxy:ci-alpine
4+
ports:
5+
- 80:80
6+
- 443:443
7+
environment:
8+
- CADDY_INGRESS_NETWORKS=caddy
9+
networks:
10+
- caddy
11+
volumes:
12+
- /var/run/docker.sock:/var/run/docker.sock
13+
- caddy_data:/data
14+
- /home/devseed/vbos-backend/static:/www/html/static
15+
restart: unless-stopped
16+
# labels:
17+
# caddy.debug:
18+
19+
networks:
20+
caddy:
21+
external: true
22+
23+
volumes:
24+
caddy_data: {}

deploy/vbos/docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
services:
2+
vbos-backend:
3+
image: ghcr.io/developmentseed/vbos-backend:main
4+
deploy:
5+
mode: replicated
6+
replicas: 1
7+
update_config:
8+
order: start-first
9+
failure_action: rollback
10+
healthcheck:
11+
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
12+
interval: 10s
13+
timeout: 5s
14+
retries: 5
15+
environment:
16+
- DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
17+
- DJANGO_AWS_ACCESS_KEY_ID=${DJANGO_AWS_ACCESS_KEY_ID}
18+
- DJANGO_AWS_SECRET_ACCESS_KEY=${DJANGO_AWS_SECRET_ACCESS_KEY}
19+
- DJANGO_AWS_STORAGE_BUCKET_NAME=${DJANGO_AWS_STORAGE_BUCKET_NAME}
20+
- DJANGO_DB_URL=${DJANGO_DB_URL}
21+
- DJANGO_SETTINGS_MODULE=vbos.config.production
22+
- PORT=8000
23+
ports:
24+
- "8080:8000"
25+
ipc: host
26+
networks:
27+
- caddy
28+
labels:
29+
caddy: vbos-backend.ds.io
30+
caddy.reverse_proxy: "{{upstreams 8000}}"
31+
caddy.handle: "/static/*"
32+
caddy.handle.root: "* /www/html"
33+
caddy.handle.file_server:
34+
35+
networks:
36+
caddy:
37+
external: true

vbos/config/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Common(Configuration):
4141
)
4242

4343
ALLOWED_HOSTS = ["*"]
44+
CSRF_TRUSTED_ORIGINS = ["https://vbos-backend.ds.io"]
4445
ROOT_URLCONF = "vbos.urls"
4546
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
4647
WSGI_APPLICATION = "vbos.wsgi.application"

0 commit comments

Comments
 (0)