-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize DB during image build #457
Changes from 21 commits
f48a799
bdd8ef1
f02bc28
6f639aa
da9cffd
79231b6
a6320de
fac06ff
b4e6145
ac248db
2e5ba46
50e2611
be5846d
e89f505
9aaa20d
163e4f2
e4c45e1
1ac56fb
bdf3907
c8c1cef
2ddeac0
7e9c91c
2d0e8f4
d03f11b
94ab041
ae59bdb
8378fa5
236902b
5b2d0bd
2cfe15a
d480087
daa56ea
c08dd3d
7f80842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ WORKDIR /opt/ | |
ARG AIIDA_VERSION | ||
ARG PGSQL_VERSION | ||
ARG TARGETARCH | ||
# Location of the Postgresql DB | ||
# This variable is automatically picked up by initdb | ||
ARG PGDATA_FOLDER=/home/${NB_USER}/.postgresql | ||
ENV PGDATA=${PGDATA_FOLDER} | ||
|
||
# Install RabbitMQ and PostgreSQL in a dedicated conda environment. | ||
# | ||
|
@@ -17,6 +21,8 @@ ARG TARGETARCH | |
# Instead we need install erlang via apt and RabbitMQ as a "Generic Unix Build", see: | ||
# https://www.rabbitmq.com/install-generic-unix.html | ||
# Note that this version must be compatible with system's erlang version. | ||
# Currently installed Erlang version is 23.3, so the latest supported RMQ version is 3.9.21 | ||
# https://www.rabbitmq.com/docs/which-erlang#old-timers | ||
# Note that system erlang from arm64 is already installed in the base image, | ||
# together with other APT dependencies to save build time. | ||
RUN if [ "$TARGETARCH" = "amd64" ]; then \ | ||
|
@@ -58,4 +64,4 @@ USER ${NB_USER} | |
WORKDIR "/home/${NB_USER}" | ||
|
||
# Initialize the database | ||
RUN mamba run -n aiida-core-services initdb -D aiida_db -U aiida | ||
RUN mamba run -n aiida-core-services initdb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the DB name used when create aiida profile after this change? We set it explicitly in BTW, we need keep in mind to adapt the change to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. https://www.postgresql.org/docs/current/app-initdb.html#APP-INITDB-OPTION-PGDATA in this case it would set it to Note that the the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think we'll want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, thanks! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# Activate the conda environment with PostgreSQL installed in it. | ||
# conda activate pgsql | ||
set -x | ||
|
||
# -w waits until server is up | ||
PSQL_START_CMD="pg_ctl --timeout=180 -w -D /home/${NB_USER}/.postgresql -l /home/${NB_USER}/.postgresql/logfile start" | ||
PSQL_STOP_CMD="pg_ctl -w -D /home/${NB_USER}/.postgresql stop" | ||
PSQL_STATUS_CMD="pg_ctl -D /home/${NB_USER}/.postgresql status" | ||
PSQL_START_CMD="pg_ctl --timeout=180 -w -l ${PGDATA}/logfile start" | ||
PSQL_STATUS_CMD="pg_ctl status" | ||
|
||
MAMBA_RUN="mamba run -n aiida-core-services" | ||
|
||
# make DB directory, if not existent | ||
if [ ! -d /home/${NB_USER}/.postgresql ]; then | ||
mkdir /home/${NB_USER}/.postgresql | ||
${MAMBA_RUN} initdb -D /home/${NB_USER}/.postgresql | ||
echo "unix_socket_directories = '/tmp'" >> /home/${NB_USER}/.postgresql/postgresql.conf | ||
if [ ! -d ${PGDATA} ]; then | ||
mkdir ${PGDATA} | ||
${MAMBA_RUN} initdb | ||
echo "unix_socket_directories = '/tmp'" >> ${PGDATA}/postgresql.conf | ||
${MAMBA_RUN} ${PSQL_START_CMD} | ||
|
||
# else don't | ||
else | ||
# Fix problem with kubernetes cluster that adds rws permissions to the group | ||
# for more details see: https://github.com/materialscloud-org/aiidalab-z2jh-eosc/issues/5 | ||
chmod g-rwxs /home/${NB_USER}/.postgresql -R | ||
|
||
# stores return value in $? | ||
running=true | ||
${MAMBA_RUN} ${PSQL_STATUS_CMD} || running=false | ||
chmod -R g-rwxs ${PGDATA} | ||
|
||
# Postgresql was probably not shutdown properly. Cleaning up the mess... | ||
if ! $running ; then | ||
echo "" > /home/${NB_USER}/.postgresql/logfile # empty log files | ||
rm -vf /home/${NB_USER}/.postgresql/postmaster.pid | ||
if ! ${MAMBA_RUN} ${PSQL_STATUS_CMD}; then | ||
# Cleaning up the mess if Postgresql was not shutdown properly. | ||
mv ${PGDATA}/logfile ${PGDATA/logfile.1 && gzip ${PGDATA}/logfile.1 | ||
danielhollas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rm -vf ${PGDATA}/postmaster.pid | ||
${MAMBA_RUN} ${PSQL_START_CMD} | ||
fi | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
set -em | ||
set -emx | ||
|
||
RABBITMQ_DATA_DIR="/home/${NB_USER}/.rabbitmq" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
set -em | ||
set -emx | ||
|
||
RABBITMQ_DATA_DIR="/home/${NB_USER}/.rabbitmq" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated cleanup