Skip to content
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

Add optional healthcheck scripts to WBS images #755

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions build/elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN \
org.wikimedia.search:extra:${ELASTICSEARCH_PLUGIN_WIKIMEDIA_EXTRA} && \
./bin/elasticsearch-plugin install \
org.wikimedia.search.highlighter:experimental-highlighter-elasticsearch-plugin:${ELASTICSEARCH_PLUGIN_WIKIMEDIA_HIGHLIGHTER}
COPY healthcheck.sh /healthcheck.sh
rti marked this conversation as resolved.
Show resolved Hide resolved
COPY default.jvm.options /default.jvm.options
RUN cat /default.jvm.options >> /usr/share/elasticsearch/config/jvm.options && \
rm /default.jvm.options
13 changes: 7 additions & 6 deletions build/elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,25 @@ services:
DB_USER: "mariadb-user"
DB_PASS: "change-this-password"
ELASTICSEARCH_HOST: elasticsearch
healthcheck:
test: curl --silent --fail localhost/wiki/Main_Page
interval: 10s
start_period: 5m
depends_on:
mysql:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: /healthcheck.sh
interval: 10s
start_period: 5m

wikibase-jobrunner:
image: wikibase/wikibase
volumes_from:
- wikibase
command: /jobrunner-entrypoint.sh
depends_on:
wikibase:
condition: service_healthy
restart: always
environment:
IS_JOBRUNNER: true

mysql:
image: mariadb:10.11
Expand All @@ -90,7 +91,7 @@ services:
discovery.type: single-node
ES_JAVA_OPTS: -Xms512m -Xmx512m -Dlog4j2.formatMsgNoLookups=true
healthcheck:
test: curl --silent --fail localhost:9200
test: /healthcheck.sh
interval: 10s
start_period: 2m

Expand Down
17 changes: 17 additions & 0 deletions build/elasticsearch/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Ref. https://github.com/docker-library/healthcheck/blob/master/elasticsearch/docker-healthcheck

set -eo pipefail

host="$(hostname --ip-address || echo '127.0.0.1')"

if health="$(curl -fsSL "http://$host:9200/_cat/health?h=status")"; then
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
if [ "$health" = 'green' ]; then
exit 0
fi
echo >&2 "unexpected health status: $health"
fi

exit 1
1 change: 1 addition & 0 deletions build/quickstatements/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ COPY --from=composer /tmp/quickstatements /var/www/html/quickstatements
COPY --from=composer /tmp/magnustools /var/www/html/magnustools

COPY entrypoint.sh /entrypoint.sh
COPY healthcheck.sh /healthcheck.sh

COPY config.json /templates/config.json
COPY oauth.ini /templates/oauth.ini
Expand Down
12 changes: 7 additions & 5 deletions build/quickstatements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,20 @@ services:
DB_PASS: "change-this-password"
QUICKSTATEMENTS_PUBLIC_URL: https://quickstatements.example
healthcheck:
test: curl --silent --fail localhost/wiki/Main_Page
test: /healthcheck.sh
interval: 10s
start_period: 5m

wikibase-jobrunner:
image: wikibase/wikibase
command: /jobrunner-entrypoint.sh
volumes_from:
- wikibase
depends_on:
wikibase:
condition: service_healthy
restart: always
volumes_from:
- wikibase
environment:
IS_JOBRUNNER: true

mysql:
image: mariadb:10.11
Expand Down Expand Up @@ -148,7 +149,7 @@ services:
QUICKSTATEMENTS_PUBLIC_URL: https://quickstatements.example
WIKIBASE_PUBLIC_URL: https://wikibase.example
healthcheck:
test: curl --silent --fail localhost
test: /healthcheck.sh
interval: 10s
start_period: 2m

Expand Down Expand Up @@ -215,6 +216,7 @@ Hooking into the internal filesystem can extend the functionality of this image.

| Directory | Description |
| ------------------------------------------- | ------------------------------ |
| `/healthcheck.sh` | Optional healthcheck script |
| `/var/www/html/quickstatements` | Base QuickStatements directory |
| `/var/www/html/quickstatements/public_html` | The Apache root folder |
| `/var/www/html/magnustools` | Base magnustools directory |
Expand Down
10 changes: 10 additions & 0 deletions build/quickstatements/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Perform the health check using curl
if curl --silent --fail "http://localhost" > /dev/null; then
echo "Health check passed."
exit 0
else
echo "Health check failed."
exit 1
fi
1 change: 1 addition & 0 deletions build/wdqs-frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ WORKDIR /usr/share/nginx/html
COPY --from=builder /tmp/wikidata-query-gui/build /usr/share/nginx/html
RUN echo "" > style.css
COPY entrypoint.sh /entrypoint.sh
COPY healthcheck.sh /healthcheck.sh
COPY custom-config.json /templates/custom-config.json
COPY default.conf /templates/default.conf

Expand Down
9 changes: 5 additions & 4 deletions build/wdqs-frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,20 @@ services:
DB_USER: "mariadb-user"
DB_PASS: "change-this-password"
healthcheck:
test: curl --silent --fail localhost/wiki/Main_Page
test: /healthcheck.sh
interval: 10s
start_period: 5m

wikibase-jobrunner:
image: wikibase/wikibase
command: /jobrunner-entrypoint.sh
depends_on:
wikibase:
condition: service_healthy
restart: always
volumes_from:
- wikibase
environment:
IS_JOBRUNNER: true

mysql:
image: mariadb:10.11
Expand Down Expand Up @@ -126,7 +127,7 @@ services:
volumes:
- wdqs-data:/wdqs/data
healthcheck:
test: curl --silent --fail localhost:9999/bigdata/namespace/wdq/sparql
test: /healthcheck.sh
interval: 10s
start_period: 2m

Expand Down Expand Up @@ -157,7 +158,7 @@ services:
environment:
WDQS_HOST: wdqs-proxy
healthcheck:
test: curl --silent --fail localhost
test: /healthcheck.sh
interval: 10s
start_period: 2m

Expand Down
10 changes: 10 additions & 0 deletions build/wdqs-frontend/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Perform the health check using curl
if curl --silent --fail "http://localhost" > /dev/null; then
echo "Health check passed."
exit 0
else
echo "Health check failed."
exit 1
fi
11 changes: 6 additions & 5 deletions build/wdqs-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ services:
DB_USER: "mariadb-user"
DB_PASS: "change-this-password"
healthcheck:
test: curl --silent --fail localhost/wiki/Main_Page
test: /healthcheck.sh
interval: 10s
start_period: 5m

wikibase-jobrunner:
image: wikibase/wikibase
command: /jobrunner-entrypoint.sh
volumes_from:
- wikibase
depends_on:
wikibase:
condition: service_healthy
restart: always
volumes_from:
- wikibase
environment:
IS_JOBRUNNER: true

mysql:
image: mariadb:10.11
Expand Down Expand Up @@ -109,7 +110,7 @@ services:
volumes:
- wdqs-data:/wdqs/data
healthcheck:
test: curl --silent --fail localhost:9999/bigdata/namespace/wdq/sparql
test: /healthcheck.sh
interval: 10s
start_period: 2m

Expand Down
2 changes: 1 addition & 1 deletion build/wdqs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ENV MEMORY=""\

WORKDIR /wdqs

COPY --chown=blazegraph:blazegraph wait-for-it.sh entrypoint.sh runBlazegraph.sh runUpdate.sh /
COPY --chown=blazegraph:blazegraph wait-for-it.sh healthcheck.sh entrypoint.sh runBlazegraph.sh runUpdate.sh /
COPY --chown=blazegraph:blazegraph mwservices.json /templates/mwservices.json
COPY --chown=blazegraph:blazegraph RWStore.properties allowlist.txt logback.xml /wdqs/

Expand Down
8 changes: 5 additions & 3 deletions build/wdqs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,20 @@ services:
DB_USER: "mariadb-user"
DB_PASS: "change-this-password"
healthcheck:
test: curl --silent --fail localhost/wiki/Main_Page
test: /healthcheck.sh
interval: 10s
start_period: 5m

wikibase-jobrunner:
image: wikibase/wikibase
command: /jobrunner-entrypoint.sh
depends_on:
wikibase:
condition: service_healthy
restart: always
volumes_from:
- wikibase
environment:
IS_JOBRUNNER: true

mysql:
image: mariadb:10.11
Expand Down Expand Up @@ -129,7 +130,7 @@ services:
volumes:
- wdqs-data:/wdqs/data
healthcheck:
test: curl --silent --fail localhost:9999/bigdata/namespace/wdq/sparql
test: /healthcheck.sh
interval: 10s
start_period: 2m

Expand Down Expand Up @@ -197,6 +198,7 @@ Hooking into the internal filesystem can extend the functionality of this image.

| File | Description |
| ---------------------------- | ---------------------------------------------------------------------------------------------- |
| `/healthcheck.sh` | Optional healthcheck script |
| `/wdqs/allowlist.txt` | SPARQL endpoints allowed for federation |
| `/wdqs/RWStore.properties` | Properties for the service |
| `/templates/mwservices.json` | Template for MediaWiki services (populated and placed into `/wdqs/mwservices.json` at runtime) |
Expand Down
10 changes: 10 additions & 0 deletions build/wdqs/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Perform the health check using curl
if curl --silent --fail "http://localhost:9999/bigdata/namespace/wdq/sparql" > /dev/null; then
echo "Health check passed."
exit 0
else
echo "Health check failed."
exit 1
fi
8 changes: 6 additions & 2 deletions build/wikibase/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ RUN set -x; \
ls -la && pwd && \
composer install --no-dev -vv -n


# ###########################################################################
# hadolint ignore=DL3006
FROM mediawiki AS wikibase
Expand All @@ -194,9 +195,11 @@ RUN chmod o-w /var/www/html && \
ln -s /var/www/html/ /var/www/html/w && \
chown www-data /var/www/html/images -R

COPY wikibase-php.ini /usr/local/etc/php/conf.d/wikibase-php.ini
COPY entrypoint.sh /entrypoint.sh
COPY mediawiki-entrypoint.sh /mediawiki-entrypoint.sh
COPY jobrunner-entrypoint.sh /jobrunner-entrypoint.sh
COPY healthcheck.sh /healthcheck.sh
COPY wikibase-php.ini /usr/local/etc/php/conf.d/wikibase-php.ini
COPY htaccess /var/www/html/.htaccess
COPY LocalSettings.d LocalSettings.d
COPY default-extra-install.sh /default-extra-install.sh
Expand All @@ -206,7 +209,8 @@ COPY LocalSettings.wbs.php /templates/LocalSettings.wbs.php
ENV DB_NAME=my_wiki \
MW_WG_SITENAME=wikibase \
MW_WG_LANGUAGE_CODE=en \
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_PORT=9200 \
IS_JOBRUNNER=false

ENTRYPOINT ["/bin/bash"]
CMD ["/entrypoint.sh"]
15 changes: 9 additions & 6 deletions build/wikibase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Variables in **bold** are required on first launch without `LocalSettings.php` i

| Variable | Default | Description |
| ---------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`IS_JOBRUNNER`** | false | If set to true the container will only run `maintenance/runJobs.php` instead of MediaWiki |
rti marked this conversation as resolved.
Show resolved Hide resolved
| **`DB_SERVER`** | undefined | Hostname and port for the MySQL server to use for MediaWiki & Wikibase |
| **`DB_USER`** | undefined | Username to use for the MySQL server |
| **`DB_PASS`** | undefined | Password to use for the MySQL server |
Expand All @@ -61,7 +62,7 @@ Variables in **bold** are required on first launch without `LocalSettings.php` i

MediaWiki/Wikibase depends on [jobs being run in the background](https://www.mediawiki.org/wiki/Manual:Job_queue). This can be either done on HTTP request or by a dedicated job runner. The default configuration of this image requires an external job runner like this.

To set up an external job runner, use this image for a second container, overwrite the command to `/jobrunner-entrypoint.sh` and share the same configuration volume with it.
To set up an external job runner, use this image for a second container, set the environment variable `IS_JOBRUNNER` to "true" and share the same configuration volume with it.

## Example

Expand All @@ -85,24 +86,25 @@ services:
DB_NAME: "my_wiki"
DB_USER: "mariadb-user"
DB_PASS: "change-this-password"
healthcheck:
test: curl --silent --fail localhost/wiki/Main_Page
interval: 10s
start_period: 5m
depends_on:
mysql:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: /healthcheck.sh
interval: 10s
start_period: 5m

wikibase-jobrunner:
image: wikibase/wikibase
volumes_from:
- wikibase
command: /jobrunner-entrypoint.sh
depends_on:
wikibase:
condition: service_healthy
restart: always
environment:
IS_JOBRUNNER: true

mysql:
image: mariadb:10.11
Expand Down Expand Up @@ -158,6 +160,7 @@ Hooking into the internal filesystem can extend the functionality of this image.

| File | Description |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/healthcheck.sh` | Optional healthcheck script |
| `/default-extra-install.sh` | Script for automatically creating Elasticsearch indices and creating OAuth consumer for QuickStatements |
| `/extra-install.sh` | Optional script for custom functionality to be ran with MediaWiki install (when generating LocalSettings.php) |
| `/templates/LocalSettings.wbs.php` | Wikibase-specific settings appended to the MediaWiki install generated `LocalSettings.php`. Specifically, this loads the Wikibase repo and client as well as all the other bundled extensions. |
Expand Down
Loading