-
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 all 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 |
---|---|---|
|
@@ -54,22 +54,8 @@ group "default" { | |
targets = "${TARGETS}" | ||
} | ||
|
||
target "base-meta" { | ||
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. Unrelated cleanup |
||
tags = tags("base") | ||
} | ||
target "base-with-services-meta" { | ||
tags = tags("base-with-services") | ||
} | ||
target "lab-meta" { | ||
tags = tags("lab") | ||
} | ||
|
||
target "full-stack-meta" { | ||
tags = tags("full-stack") | ||
} | ||
|
||
target "base" { | ||
inherits = ["base-meta"] | ||
tags = tags("base") | ||
context = "stack/base" | ||
platforms = "${PLATFORMS}" | ||
args = { | ||
|
@@ -78,7 +64,7 @@ target "base" { | |
} | ||
} | ||
target "base-with-services" { | ||
inherits = ["base-with-services-meta"] | ||
tags = tags("base-with-services") | ||
context = "stack/base-with-services" | ||
contexts = { | ||
base = "target:base" | ||
|
@@ -90,7 +76,7 @@ target "base-with-services" { | |
} | ||
} | ||
target "lab" { | ||
inherits = ["lab-meta"] | ||
tags = tags("lab") | ||
context = "stack/lab" | ||
contexts = { | ||
base = "target:base" | ||
|
@@ -103,7 +89,7 @@ target "lab" { | |
} | ||
} | ||
target "full-stack" { | ||
inherits = ["full-stack-meta"] | ||
tags = tags("full-stack") | ||
context = "stack/full-stack" | ||
contexts = { | ||
base-with-services = "target:base-with-services" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,20 @@ ARG AIIDA_VERSION | |
ARG PGSQL_VERSION | ||
ARG TARGETARCH | ||
|
||
# Location of the Postgresql DB | ||
# This variable is automatically picked up by initdb and pg_ctl | ||
# WARNING: If you change this, you have to change it in full-stack as well! | ||
ENV PGDATA=/home/${NB_USER}/.postgresql | ||
|
||
# Install RabbitMQ and PostgreSQL in a dedicated conda environment. | ||
# | ||
# RabbitMQ is not available on conda-forge at the time being, see: | ||
# https://github.com/conda-forge/rabbitmq-server-feedstock/issues/67If | ||
# 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 +65,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,30 +1,32 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
if [[ -z $PGDATA ]]; then | ||
echo "ERROR: PGDATA variable not set, cannot start PostgreSQL!" | ||
exit 1 | ||
fi | ||
|
||
PSQL_LOGFILE="${PGDATA}/logfile" | ||
# -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 ${PSQL_LOGFILE} start" | ||
|
||
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 | ||
${MAMBA_RUN} ${PSQL_START_CMD} | ||
|
||
# Initialize DB directory if it does not exist | ||
if [[ ! -d ${PGDATA} ]]; then | ||
mkdir "${PGDATA}" | ||
${MAMBA_RUN} initdb | ||
echo "unix_socket_directories = '/tmp'" >> "${PGDATA}/postgresql.conf" | ||
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 | ||
chmod -R g-rwxs "${PGDATA}" | ||
|
||
if ! ${MAMBA_RUN} ${PSQL_STATUS_CMD}; then | ||
# Cleaning up the mess if Postgresql was not shutdown properly. | ||
# TODO: Rotate logfile | ||
echo "" > /home/${NB_USER}/.postgresql/logfile | ||
rm -vf /home/${NB_USER}/.postgresql/postmaster.pid | ||
${MAMBA_RUN} ${PSQL_START_CMD} | ||
fi | ||
if [[ -f ${PGDATA}/logfile ]]; then | ||
mv "${PSQL_LOGFILE}" "${PSQL_LOGFILE}.1" && gzip "${PSQL_LOGFILE}.1" | ||
fi | ||
# Cleaning up the mess if PostgreSQL was not shutdown properly. | ||
rm -vf "${PGDATA}/postmaster.pid" | ||
fi | ||
|
||
# Start the server | ||
${MAMBA_RUN} ${PSQL_START_CMD} |
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.
This I don't understand, what different it will make?
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.
Oh, this just pretty prints the json output so that it is easier to read in the Github Actions logs. Previously it was on a single line, and it was a bit annoying when I needed to copy the image name.
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.
This is how it looks now in the amd64 image build