Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-buster
FROM node:22-bookworm

LABEL maintainer="smapshot@heig-vd.ch"

Expand All @@ -13,6 +13,12 @@ RUN apt-get update && \

COPY requirements.txt /

RUN python3 -m pip install --trusted-host pypi.python.org --upgrade pip \
&& pip install --trusted-host pypi.python.org --upgrade setuptools wheel \
&& pip3 install -r requirements.txt
RUN python3 -m pip install \
--trusted-host pypi.python.org \
--break-system-packages \
--upgrade pip \
&& pip install \
--trusted-host pypi.python.org \
--break-system-packages \
--upgrade setuptools wheel \
&& pip3 install --break-system-packages -r requirements.txt
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# https://docs.docker.com/compose/compose-file/
version: "3.8"

services:
# Application container (Node.js server).
Expand All @@ -21,7 +20,7 @@ services:
# (https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set).
DB_HOST: db
DB_PORT: 5432
DB_NAME: smapshot_v2
DB_NAME: smapshot
DB_USER: postgres
DB_PASS: postgres
# If this variable is set, the entrypoint script will run `npm install`
Expand Down Expand Up @@ -50,8 +49,6 @@ services:
# -c work_mem=1GB
hostname: db
environment:
POSTGRES_DB: smapshot_v2
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
# Expose the database on port 5432 of the host by default
Expand All @@ -63,7 +60,10 @@ services:
# data survives container restart.
- "db_data:/var/lib/postgresql/data"
- ./init_db.sh:/docker-entrypoint-initdb.d/11_init_db.sh
#- "${DUMP_PATH}:/tmp/dump.sql" #uncomment if you need to bootstrap your db from a dump
# If you need to bootstrap your database from a dump file, make sure
# the DUMP_PATH variable is correctly set up in your .env and then
# uncomment the following line:
#- "${DUMP_PATH}:/tmp/dump.sql"

# Vector tiles generation for points container
vt_generate:
Expand All @@ -77,7 +77,7 @@ services:
# (https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set).
DB_HOST: db
DB_PORT: 5432
DB_NAME: smapshot_v2
DB_NAME: smapshot
DB_USER: postgres
DB_PASS: postgres
restart: "always"
Expand Down
83 changes: 65 additions & 18 deletions init_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,81 @@

set -e

DUMP_FILE="/tmp/dump.sql"
NPROC=$(nproc)
JOBS=$((NPROC-1))
# This variable is used by the legacy code:
POSTGRES_DB="smapshot"

# Create the smapshot role to avoid the following error:
# psql:/tmp/dump.sql:1814634: ERROR: role "smapshot" does not exist
echo "Create role smapshot..."
psql \
-U ${POSTGRES_USER} \
-d ${POSTGRES_DB} \
-c 'CREATE ROLE smapshot;'
#-v ON_ERROR_STOP=1 # this sanity check SHOULD be activated, but the dump is not clean.

echo "Role smapshot successfully created!"
# Check if the dump file is existing. This files must be made available as a
# bind mount in the "db" service of the Compose file.
if [[ -f "/tmp/dump.sql" ]];
then
DUMP_FILE="/tmp/dump.sql"
else
# We exit the initialization script
printf "%s\n" \
"WARNING: No database dump set up in the db service of the Compose file." \
" It is therfore assumed that you already have an initialized database." \
" Otherwise ask for a fresh dump from the prod database," \
" and uncomment the line containing the DUMP_PATH variable" \
" under the volumes section of the db service in the Compose file." \
"Exiting intialization script now. Bye."
exit 1
fi

# Start with a clean database for psql to work with hereafter
echo "INFO: Setting up the \"${POSTGRES_DB}\" database..."
psql \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
-f "/tmp/dump.sql"
#-v ON_ERROR_STOP=1 # this sanity check SHOULD be activated, but the dump is not clean.
-d "postgres" \
-c "DROP DATABASE IF EXISTS ${POSTGRES_DB};" \
-c "CREATE DATABASE ${POSTGRES_DB};"

echo "INFO: \"${POSTGRES_DB}\" database created with: SUCCESS!"

echo "INFO: Creating role smapshot..."
psql \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
-c "CREATE ROLE smapshot;" \
-v ON_ERROR_STOP=1

echo "INFO: smapshot role created with: SUCCESS!"

if [[ $(pg_restore -l "${DUMP_FILE}" 2>/dev/null) ]];
then
echo "INFO: restoring DB with pg_restore using ${JOBS} job(s), please wait..."
pg_restore \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
--clean \
--if-exists \
--no-owner \
--no-privileges \
--jobs=${JOBS} \
"${DUMP_FILE}"
echo "INFO: dump \"${DUMP_FILE}\" restored with pg_restore with: SUCCESS!"
else
# Legacy code; should be avoided because it has many flaws:
# Create the smapshot role to avoid the following error:
# psql:/tmp/dump.sql:1814634: ERROR: role "smapshot" does not exist
echo "INFO: restoring the smapshot database with psql, please wait..."
psql \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
-f "${DUMP_FILE}"
#-v ON_ERROR_STOP=1 # this sanity check SHOULD be activated, but the dump is not clean.

#rm -rf "${DUMP_FILE}"
#rm -rf "${DUMP_FILE}"

echo "Dump ${DUMP_FILE} successfully restored!"
echo "INFO: dump file \"${DUMP_FILE}\" restored with psql with: SUCCESS!"
fi

echo "Creating default user..."
echo "INFO: creating default user..."
psql \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
-c "INSERT INTO public.users (first_name, last_name, email, username, date_registr, letter, lang, \"password\", roles, active)
VALUES ('Franck', 'Dulin', 'super_admin@smapshot.ch', 'super_admin', now(), TRUE, 'fr','\$2b\$12\$v80JamELNdJnvHyVAQrUZOaIRJJ2BI48vTsZop4s5mgoA9jbcX4Ni','{volunteer,super_admin}',TRUE);"

echo "Default user created successfully!"
echo "INFO: default user created with: SUCCESS!"
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
]
},
"engines": {
"node": ">=12.0.0 <19.0.0"
"node": ">=22.0.0 <23.0.0"
},
"dependencies": {
"@aws-sdk/client-ses": "^3.658.1",
Expand Down