Skip to content

Commit 367f354

Browse files
Merge pull request #297 from Ecotrust/docker-install-script
add bash script to install docker and TEKDB on Linux
2 parents 45ff69a + fb4b165 commit 367f354

7 files changed

Lines changed: 161 additions & 15 deletions

File tree

TEKDB/TEKDB/settings.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,4 @@
413413
try:
414414
from TEKDB.local_settings import * # noqa: F403
415415
except Exception:
416-
import sys
417-
418-
print(
419-
"ERROR: Unable to load local_settings.py. This is expected for docker deployment",
420-
file=sys.stderr,
421-
)
416+
pass

docker/common.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
services:
22
db:
3+
container_name: db
34
image: postgis/postgis:15-3.4
45
restart: always
56
platform: linux/amd64
@@ -18,8 +19,10 @@ services:
1819
timeout: 5s
1920
retries: 5
2021
redis:
22+
container_name: redis
2123
image: redis:alpine
2224
web:
25+
container_name: tekdb_web
2326
build:
2427
context: ../TEKDB/
2528
dockerfile: ../TEKDB/Dockerfile
@@ -37,7 +40,8 @@ services:
3740
retries: 5
3841
start_period: 30s
3942

40-
celery:
43+
celery:
44+
container_name: tekdb_celery
4145
entrypoint: []
4246
command: celery -A TEKDB worker -l info
4347
environment:
@@ -50,6 +54,7 @@ services:
5054
redis:
5155
condition: service_started
5256
celery-beat:
57+
container_name: tekdb_celery_beat
5358
entrypoint: []
5459
command: celery -A TEKDB beat -l info
5560
environment:

docker/docker-compose.prod.local.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
depends_on:
3131
- web
3232
ports:
33-
- "8080:8080"
33+
- "80:8080"
3434
volumes:
3535
- static_volume:/vol/static/static:ro
3636
- media_volume:/vol/static/media:ro

proxy/Dockerfile.local

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ FROM nginxinc/nginx-unprivileged:1-alpine
22

33
USER root
44

5-
COPY ./default.local.conf /etc/nginx/templates/default.local.conf
5+
COPY ./default.local.conf /etc/nginx/conf.d/default.conf
66
COPY ./uwsgi_params /etc/nginx/uwsgi_params
77

8-
RUN chmod 644 /etc/nginx/templates/default.local.conf /etc/nginx/uwsgi_params && \
8+
RUN chmod 644 /etc/nginx/conf.d/default.conf /etc/nginx/uwsgi_params && \
99
mkdir -p /vol/static && \
1010
chmod 755 /vol/static
1111

proxy/default.local.conf

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ server {
99
alias /vol/static/media;
1010
}
1111
location /import_database/ {
12-
uwsgi_request_buffering off;
13-
uwsgi_pass web:8000;
14-
include /etc/nginx/uwsgi_params;
12+
proxy_request_buffering off;
13+
proxy_pass http://web:8000;
14+
proxy_set_header Host $host;
15+
proxy_set_header X-Real-IP $remote_addr;
16+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
17+
proxy_set_header X-Forwarded-Proto $scheme;
1518
}
1619
location / {
17-
uwsgi_pass web:8000;
18-
include /etc/nginx/uwsgi_params;
20+
proxy_pass http://web:8000;
21+
proxy_set_header Host $host;
22+
proxy_set_header X-Real-IP $remote_addr;
23+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
24+
proxy_set_header X-Forwarded-Proto $scheme;
1925
}
2026

2127
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
ENV_FILE="${1:-.env.prod}"
3+
4+
if [ ! -f "$ENV_FILE" ]; then
5+
echo "Environment file $ENV_FILE not found!"
6+
exit 1
7+
fi
8+
9+
# Add Docker’s official GPG Key:
10+
echo "Adding Docker's official GPG key..."
11+
sudo apt update
12+
sudo apt install ca-certificates curl
13+
sudo install -m 0755 -d /etc/apt/keyrings
14+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
15+
sudo chmod a+r /etc/apt/keyrings/docker.asc
16+
17+
# Add the repository to apt sources:
18+
echo "Adding Docker's official repository..."
19+
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
20+
Types: deb
21+
URIs: https://download.docker.com/linux/ubuntu
22+
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
23+
Components: stable
24+
Architectures: $(dpkg --print-architecture)
25+
Signed-By: /etc/apt/keyrings/docker.asc
26+
EOF
27+
28+
sudo apt update
29+
30+
# Install Docker packages:
31+
echo "Installing Docker packages..."
32+
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
33+
34+
# Verify installation:
35+
if systemctl is-active --quiet docker; then
36+
echo "Docker is installed and running."
37+
else
38+
echo "Docker installation failed or Docker is not running."
39+
echo "Starting Docker..."
40+
sudo systemctl start docker
41+
if systemctl is-active --quiet docker; then
42+
echo "Docker started successfully."
43+
else
44+
echo "Failed to start Docker. Please check the installation and try again."
45+
exit 1
46+
fi
47+
fi
48+
49+
echo "Adding ubuntu user to the docker group..."
50+
sudo usermod -aG docker ubuntu
51+
52+
echo "Installing git..."
53+
sudo apt install git -y
54+
55+
echo "Creating TEKDB directory and cloning repository..."
56+
mkdir tekdb
57+
cd tekdb
58+
git clone https://github.com/Ecotrust/TEKDB.git
59+
60+
# TODO: change to the main branch once the develop branch is merged into main!!
61+
echo "Checking out the develop branch..."
62+
cd TEKDB
63+
git checkout develop
64+
git pull origin develop
65+
66+
echo "Moving the .env.prod file to the Docker directory..."
67+
mv $ENV_FILE docker/.env.prod
68+
69+
echo "Pulling the latest Docker image..."
70+
docker pull ghcr.io/ecotrust/tekdb/web:latest
71+
72+
echo "Starting the Docker containers..."
73+
docker compose --env-file docker/.env.prod -f docker/docker-compose.prod.local.yaml up -d
74+
75+
echo "Verifying that the containers are running..."
76+
if [ "$(docker container inspect -f '{{.State.Status}}' "tekdb_web" 2>/dev/null)" = "running" ]; then
77+
echo "TEKDB containers are running successfully."
78+
else
79+
echo "Failed to start TEKDB containers. Please check the Docker logs for more information."
80+
exit 1
81+
fi
82+
exit 0
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
ENV_FILE="${1:-docker/.env.prod}"
5+
COMPOSE_FILE="${2:-docker/docker-compose.prod.local.yaml}"
6+
7+
REMOVE_VOLUMES="${REMOVE_VOLUMES:-0}"
8+
REMOVE_IMAGES="${REMOVE_IMAGES:-0}"
9+
10+
# Optional flags can be passed after positional args.
11+
# --volumes => remove named/anonymous volumes
12+
# --rmi-local => remove images built locally by compose
13+
shift $(( $# > 2 ? 2 : $# )) || true
14+
for arg in "$@"; do
15+
case "$arg" in
16+
--volumes)
17+
REMOVE_VOLUMES=1
18+
;;
19+
--rmi-local)
20+
REMOVE_IMAGES=1
21+
;;
22+
*)
23+
echo "Unknown option: $arg"
24+
echo "Usage: $0 [env_file] [compose_file] [--volumes] [--rmi-local]"
25+
exit 1
26+
;;
27+
esac
28+
done
29+
30+
if ! command -v docker >/dev/null 2>&1; then
31+
echo "Docker CLI not found. Install Docker first."
32+
exit 1
33+
fi
34+
35+
if [ ! -f "$ENV_FILE" ]; then
36+
echo "Environment file not found: $ENV_FILE"
37+
exit 1
38+
fi
39+
40+
if [ ! -f "$COMPOSE_FILE" ]; then
41+
echo "Compose file not found: $COMPOSE_FILE"
42+
exit 1
43+
fi
44+
45+
echo "Stopping and removing TEKDB containers..."
46+
DOWN_CMD=(docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" down)
47+
48+
if [ "$REMOVE_VOLUMES" = "1" ]; then
49+
DOWN_CMD+=(--volumes)
50+
fi
51+
52+
if [ "$REMOVE_IMAGES" = "1" ]; then
53+
DOWN_CMD+=(--rmi local)
54+
fi
55+
56+
"${DOWN_CMD[@]}"
57+
58+
echo "TEKDB stack has been brought down successfully."

0 commit comments

Comments
 (0)