Skip to content

Commit

Permalink
build: update odkcentral img, add entrypoint + healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 19, 2023
1 parent ab8ce15 commit 37c1796
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
44 changes: 22 additions & 22 deletions odkcentral/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ FROM docker.io/node:${node_version}

WORKDIR /usr/odk

RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg && \
apt-get update && \
apt-get install -y cron gettext postgresql-client-14

COPY --from=repo central/files/service/crontab /etc/cron.d/odk

COPY --from=repo central/server/package*.json ./

RUN npm clean-install --omit=dev --legacy-peer-deps --no-audit --fund=false --update-notifier=false
RUN npm install [email protected] -g

COPY --from=repo central/server/ ./
COPY --from=repo central/files/service/scripts/ ./
COPY --from=repo central/files/service/pm2.config.js ./

COPY --from=repo central/files/service/config.json.template /usr/share/odk/
COPY --from=repo central/files/service/odk-cmd /usr/bin/
# Add entrypoint script to init user
COPY ./init-user-and-start.sh ./
# package.json must be added and installed prior to final COPY
COPY --from=repo central/server/package*.json ./

# Required to start via entrypoint
RUN mkdir /etc/secrets sentry-versions \
# Install system deps
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg && \
apt-get update && \
apt-get install -y cron wait-for-it gettext postgresql-client-14 netcat-traditional \
# Install node_modules
&& npm clean-install --omit=dev --legacy-peer-deps --no-audit \
--fund=false --update-notifier=false \
# Required to start via entrypoint
&& mkdir /etc/secrets sentry-versions \
&& echo 'jhs9udhy987gyds98gfyds98f' > /etc/secrets/enketo-api-key \
&& echo '1' > sentry-versions/server \
&& echo '1' > sentry-versions/central \
&& echo '1' > sentry-versions/client
&& echo '1' > sentry-versions/client \
# Set entrypoint executable
&& chmod +x ./init-user-and-start.sh

# Add entrypoint script to init user
COPY ./init-user-and-start.sh ./
RUN chmod +x ./init-user-and-start.sh
CMD ["./wait-for-it.sh", "central-db:5432", \
"--", "./init-user-and-start.sh"]
# Add remaining files after deps installed
COPY --from=repo central/server/ ./

ENTRYPOINT ["./init-user-and-start.sh"]
EXPOSE 8383

# Add Healthcheck
HEALTHCHECK --start-period=10s --interval=5s --retries=10 \
CMD nc -z localhost 8383 || exit 1
11 changes: 6 additions & 5 deletions odkcentral/api/init-user-and-start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
set -eo pipefail

# Wait for database to be available
wait-for-it "${CENTRAL_DB_HOST:-central-db}:5432"

### Init, generate config, migrate db ###
echo "Stripping pm2 exec command from start-odk.sh script (last 2 lines)"
head -n -2 ./start-odk.sh > ./init-odk-db.sh
Expand All @@ -9,16 +12,14 @@ echo "Running ODKCentral start script to init environment and migrate DB"
echo "The server will not start on this run"
./init-odk-db.sh


### Create admin user ###
echo "Creating test user ${SYSADMIN_EMAIL} with password ${SYSADMIN_PASSWD}"
echo "${SYSADMIN_PASSWD}" | odk-cmd --email "${SYSADMIN_EMAIL}" user-create || true

echo "Elevating user to admin"
odk-cmd --email "${SYSADMIN_EMAIL}" user-promote || true


### Run server ###
### Run server (copied from start-odk.sh) ###
MEMTOT=$(vmstat -s | grep 'total memory' | awk '{ print $1 }')
if [ "$MEMTOT" -gt "1100000" ]
then
Expand All @@ -28,5 +29,5 @@ else
fi
echo "using $WORKER_COUNT worker(s) based on available memory ($MEMTOT).."

echo "Starting server"
exec pm2-runtime ./pm2.config.js
echo "Starting server."
exec npx pm2-runtime ./pm2.config.js

0 comments on commit 37c1796

Please sign in to comment.