From 231ac2b851f41757cbec09fc0c823ede21b2432f Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Thu, 7 Jul 2022 12:32:44 +0200 Subject: [PATCH] Install PostgreSQL in pgsql conda environment. --- .github/workflows/build_and_test_on_pr.yml | 2 +- Dockerfile | 4 +++- opt/start-postgres.sh | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_and_test_on_pr.yml b/.github/workflows/build_and_test_on_pr.yml index 5726a62..137d46f 100644 --- a/.github/workflows/build_and_test_on_pr.yml +++ b/.github/workflows/build_and_test_on_pr.yml @@ -52,7 +52,7 @@ jobs: export DOCKERID=`docker run -v $PWD/tmp:/home/aiida -d aiida-prerequisites:latest` docker exec --tty --user root $DOCKERID wait-for-services docker exec --tty --user aiida $DOCKERID wait-for-services - docker exec --tty --user aiida $DOCKERID /bin/bash -l -c '/usr/lib/postgresql/14/bin/pg_ctl -D /home/$SYSTEM_USER/.postgresql status' # Check that postgres is up. + docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'conda run -n pgsql pg_ctl -D /home/$SYSTEM_USER/.postgresql status' # Check that postgres is up. docker exec --tty --user root $DOCKERID /bin/bash -l -c 'service rabbitmq-server status' # Check that rabbitmq is up. docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'conda create -y -n test_env python=3.8' # Check that one can create a new conda environment. docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'conda activate test_env' # Check that new environment works. diff --git a/Dockerfile b/Dockerfile index a9e46cd..5e00213 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ graphviz \ locales \ less \ - postgresql \ psmisc \ rabbitmq-server \ rsync \ @@ -93,6 +92,9 @@ RUN cd /tmp && \ conda update --all --quiet --yes && \ conda clean --all -f -y +# Install PostgreSQL in a dedicated conda environment. +RUN conda create -c conda-forge -n pgsql postgresql=14 && conda clean --all -f -y + # Copy the script load-singlesshagent.sh to /usr/local/bin. COPY bin/load-singlesshagent.sh /usr/local/bin/load-singlesshagent.sh diff --git a/opt/start-postgres.sh b/opt/start-postgres.sh index c1d9403..20ac98e 100755 --- a/opt/start-postgres.sh +++ b/opt/start-postgres.sh @@ -1,17 +1,17 @@ #!/bin/bash -PGSQL_VERSION=14 -PGBIN=/usr/lib/postgresql/${PGSQL_VERSION}/bin +# Activate the conda environment with PostgreSQL installed in it. +conda activate pgsql # -w waits until server is up -PSQL_START_CMD="${PGBIN}/pg_ctl --timeout=180 -w -D /home/${SYSTEM_USER}/.postgresql -l /home/${SYSTEM_USER}/.postgresql/logfile start" -PSQL_STOP_CMD="${PGBIN}/pg_ctl -w -D /home/${SYSTEM_USER}/.postgresql stop" -PSQL_STATUS_CMD="${PGBIN}/pg_ctl -D /home/${SYSTEM_USER}/.postgresql status" +PSQL_START_CMD="pg_ctl --timeout=180 -w -D /home/${SYSTEM_USER}/.postgresql -l /home/${SYSTEM_USER}/.postgresql/logfile start" +PSQL_STOP_CMD="pg_ctl -w -D /home/${SYSTEM_USER}/.postgresql stop" +PSQL_STATUS_CMD="pg_ctl -D /home/${SYSTEM_USER}/.postgresql status" # make DB directory, if not existent if [ ! -d /home/${SYSTEM_USER}/.postgresql ]; then mkdir /home/${SYSTEM_USER}/.postgresql - ${PGBIN}/initdb -D /home/${SYSTEM_USER}/.postgresql + initdb -D /home/${SYSTEM_USER}/.postgresql echo "unix_socket_directories = '/tmp'" >> /home/${SYSTEM_USER}/.postgresql/postgresql.conf ${PSQL_START_CMD}