Skip to content

Commit

Permalink
Add ability to supply settings file via volume
Browse files Browse the repository at this point in the history
- means we only do the default settings file stuff if no file is detected
  • Loading branch information
louise-davies committed Nov 6, 2024
1 parent 712281d commit 1f4b278
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ README.md
.env.development.local
.env.test.local
.env.production.local
**/public/*settings*.json
!**/public/*settings.example.json
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ RUN set -eux; \
# Set the React production variable which holds reference to the path of the plugin build \
sed -i "s#VITE_APP_OPERATIONS_GATEWAY_BUILD_DIRECTORY=.*#VITE_APP_OPERATIONS_GATEWAY_BUILD_DIRECTORY=/operationsgateway/#" .env.production; \
\
cp public/operationsgateway-settings.example.json public/operationsgateway-settings.json; \
\
yarn build;

# Run stage
Expand Down Expand Up @@ -56,8 +54,8 @@ RUN set -eux; \
# Change ownership of logs directory \
chown www-data:www-data /usr/local/apache2/logs; \
\
# Change ownership of settings file \
chown www-data:www-data /usr/local/apache2/htdocs/operationsgateway/operationsgateway-settings.json;
# Change ownership of settings location \
chown www-data:www-data -R /usr/local/apache2/htdocs/operationsgateway;

# Switch to non-root user defined in httpd image
USER www-data
Expand Down
11 changes: 10 additions & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#!/bin/sh -eu

if [ ! -e /usr/local/apache2/htdocs/operationsgateway/operationsgateway-settings.json ]

then

# file doesn't exist, so go with default settings file with env variable substitution
# if file exists, we skip this code as that means we've been supplied one from a mount

# Use a tempfile instead of sed -i so that only the file, not the directory needs to be writable
TEMPFILE="$(mktemp)"

# Set values in operationsgateway-settings.json from environment variables
sed -e "s|\"apiUrl\": \".*\"|\"apiUrl\": \"$API_URL\"|" \
-e "s|\"pluginHost\": \".*\"|\"pluginHost\": \"/operationsgateway\"|" \
/usr/local/apache2/htdocs/operationsgateway/operationsgateway-settings.json > "$TEMPFILE"
/usr/local/apache2/htdocs/operationsgateway/operationsgateway-settings.example.json > "$TEMPFILE"

cat "$TEMPFILE" > /usr/local/apache2/htdocs/operationsgateway/operationsgateway-settings.json

rm "$TEMPFILE"

fi

# Run the CMD instruction
exec "$@"

0 comments on commit 1f4b278

Please sign in to comment.