-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a86afa9
commit d5d1742
Showing
9 changed files
with
117 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.docker_container_id | ||
.docker_postgres_data_directory | ||
.docker_postgres_password | ||
.docker_secret_key | ||
.docker_volume_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,24 @@ | |
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
FROM debian:12 | ||
# If upgrading the version number from 12 to the next debian release, make sure to do the same | ||
# also in the shell scripts stored in this directory. | ||
MAINTAINER Francesco Ballarin <[email protected]> | ||
|
||
ARG SECRET_KEY | ||
ARG POSTGRES_PASSWORD | ||
|
||
WORKDIR /root | ||
|
||
RUN apt update -y -q && \ | ||
apt install -y -qq curl net-tools python3-pip unzip vim wget | ||
apt install -y -qq curl net-tools python3-pip sudo unzip vim wget | ||
|
||
COPY . . | ||
|
||
# Part 1: turing and its runtime dependencies | ||
RUN apt install -y -qq postgresql postgresql-client postgresql-contrib && \ | ||
echo "$POSTGRES_PASSWORD\n$POSTGRES_PASSWORD" | passwd postgres | ||
|
||
RUN bash patches/turing/apply_patches.sh && \ | ||
python3 -m pip install --break-system-packages -r turing/requirements.txt | ||
|
||
|
@@ -27,14 +33,13 @@ DEBUG=False | |
DEV_MODE=False | ||
ALLOWED_HOSTS=* | ||
INTERNAL_IPS=127.0.0.1 | ||
EMAIL_HOST= | ||
EMAIL_HOST_USER= | ||
EMAIL_HOST_PASSWORD= | ||
REGISTRATION_OPEN= | ||
RDS_DB_NAME=turing-dmf-db | ||
RDS_USERNAME=postgres | ||
RDS_PASSWORD=$POSTGRES_PASSWORD | ||
RDS_HOSTNAME=localhost | ||
EOF | ||
|
||
RUN cd turing && \ | ||
ln -s /mnt/database/db.sqlite3 . && \ | ||
python3 manage.py collectstatic | ||
|
||
# Part 2: test dependencies | ||
|
@@ -52,4 +57,4 @@ RUN LATEST_STABLE_RELEASE=$(curl -sS https://googlechromelabs.github.io/chrome-f | |
RUN python3 -m pip install --break-system-packages -r turing/requirements-dev.txt | ||
|
||
# The end: run server on docker container start | ||
CMD cd turing && python3 manage.py runserver 0.0.0.0:8080 | ||
CMD service postgresql start && cd turing && python3 manage.py runserver 0.0.0.0:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,25 +7,48 @@ | |
|
||
set -e | ||
|
||
# Outputs of previous steeps | ||
VOLUME_ID_FILE=".docker_volume_id" | ||
if [[ ! -f "${VOLUME_ID_FILE}" ]]; then | ||
echo "The database volume does not exist!" | ||
echo "Please create it with docker_create_volume.sh" | ||
exit 1 | ||
else | ||
VOLUME_ID=$(cat "${VOLUME_ID_FILE}") | ||
VOLUME_ID=$(cat "${VOLUME_ID_FILE}") | ||
|
||
POSTGRES_PASSWORD_FILE=".docker_postgres_password" | ||
POSTGRES_PASSWORD=$(cat "${POSTGRES_PASSWORD_FILE}") | ||
|
||
# Determine if the script was already run | ||
POSTGRES_INITIALIZED_FILE=".docker_postgres_initialized" | ||
if [[ -f "${POSTGRES_INITIALIZED_FILE}" ]]; then | ||
POSTGRES_INITIALIZED=$(cat "${POSTGRES_INITIALIZED_FILE}") | ||
if [[ ${POSTGRES_INITIALIZED} == ${VOLUME_ID} ]]; then | ||
echo "The database in volume ${VOLUME_ID} was already initialized!" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
docker run --rm -v ${VOLUME_ID}:/mnt/database turing-dmf:latest /bin/bash -c '\ | ||
DATABASE=/mnt/database/db.sqlite3 && \ | ||
if [[ -f "$DATABASE" ]]; then \ | ||
echo "Database already exists. Not overwriting"; \ | ||
else \ | ||
touch $DATABASE && \ | ||
cd turing && \ | ||
python3 manage.py makemigrations && \ | ||
python3 manage.py makemigrations engine && \ | ||
python3 manage.py migrate && \ | ||
[email protected] DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=admin python3 manage.py createsuperuser --no-input; | ||
fi \ | ||
' | ||
# Write out the postgresql data as of debian:12 | ||
POSTGRES_DATA_DIRECTORY_FILE=".docker_postgres_data_directory" | ||
POSTGRES_DATA_DIRECTORY="/var/lib/postgresql/15/main" | ||
echo ${POSTGRES_DATA_DIRECTORY} > ${POSTGRES_DATA_DIRECTORY_FILE} | ||
|
||
# Use a clean container to create the default postgresql data, since turing-dmf:latest cannot be used | ||
# because it already expects the database to exist | ||
docker run --rm -v ${VOLUME_ID}:${POSTGRES_DATA_DIRECTORY} -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} debian:12 /bin/bash -c "\ | ||
apt update -y -q && \ | ||
apt install -y -qq postgresql sudo && \ | ||
service postgresql start && \ | ||
echo \$(sudo -u postgres psql -c \"SHOW data_directory;\") && \ | ||
sudo -u postgres psql -c \"ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}';\" && \ | ||
sudo -u postgres createdb turing-dmf-db | ||
" | ||
|
||
# Once the database has been created, ask turing to initialize it | ||
docker run --rm -v ${VOLUME_ID}:${POSTGRES_DATA_DIRECTORY} turing-dmf:latest /bin/bash -c "\ | ||
service postgresql start && \ | ||
cd turing && \ | ||
python3 manage.py makemigrations && \ | ||
python3 manage.py makemigrations engine && \ | ||
python3 manage.py migrate && \ | ||
[email protected] DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=admin python3 manage.py createsuperuser --no-input; | ||
" | ||
|
||
# Mark the database in this volume as initialized | ||
echo ${VOLUME_ID} > ${POSTGRES_INITIALIZED_FILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# Copyright (C) 2024 by the Turing @ DMF authors | ||
# | ||
# This file is part of Turing @ DMF. | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
set -e | ||
|
||
SECRET_KEY_FILE=".docker_secret_key" | ||
if [[ -f "${SECRET_KEY_FILE}" ]]; then | ||
echo "A secret key already exists!" | ||
echo "If you want to destroy it and create a new one, please remove the ${SECRET_KEY_FILE} file" | ||
exit 1 | ||
else | ||
SECRET_KEY=$(cat /dev/urandom | tr -dc 'abcdefghijklmnopqrstuvwxyz0123456789!@#$^&*-_=+' | head -c 50; echo) | ||
echo ${SECRET_KEY} > ${SECRET_KEY_FILE} | ||
fi | ||
|
||
POSTGRES_PASSWORD_FILE=".docker_postgres_password" | ||
if [[ -f "${POSTGRES_PASSWORD_FILE}" ]]; then | ||
echo "A postgres password already exists!" | ||
echo "If you want to destroy it and create a new one, please remove the ${POSTGRES_PASSWORD_FILE} file" | ||
exit 1 | ||
else | ||
POSTGRES_PASSWORD=$(cat /dev/urandom | tr -dc 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | head -c 50; echo) | ||
echo ${POSTGRES_PASSWORD} > ${POSTGRES_PASSWORD_FILE} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# Copyright (C) 2024 by the Turing @ DMF authors | ||
# | ||
# This file is part of Turing @ DMF. | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
set -e | ||
|
||
VOLUME_ID_FILE=".docker_volume_id" | ||
VOLUME_ID=$(cat "${VOLUME_ID_FILE}") | ||
|
||
docker run -it --rm -v ${VOLUME_ID}:/mnt/docker-volume --workdir=/mnt/docker-volume debian:12 |