Skip to content

Commit cc2e05d

Browse files
committed
Merge pull request #12 from wisemen-digital/feature/env-based-config
ENV-based config
2 parents dbab031 + 8dcadc0 commit cc2e05d

File tree

21 files changed

+157
-58
lines changed

21 files changed

+157
-58
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@ This is a collection of Docker images, both for development purposes, use during
55
# Development
66

77
Changes to this repository will trigger a build and push to GitHub packages automatically.
8+
9+
# Configuration
10+
11+
## nginx
12+
13+
Images with `nginx` can be configured using the following environment variables.
14+
15+
### Robots
16+
17+
| Environment Key | Applied | Description | Default |
18+
|-----------------|---------|-------------|---------|
19+
| NGINX_ROBOTS_TAG | Every run | `X-Robots-Tag` value | `none` |
20+
| NGINX_ROBOTS_TXT | Every run | Content of `robots.txt` | `Disallow: /` |

common/config/nginx/site-mods-available.d/no-robots.conf

Lines changed: 0 additions & 2 deletions
This file was deleted.

common/config/nginx/site-mods-enabled.d/no-robots.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
# Configure nginx robots rules based on ENV vars
6+
#
7+
# Inputs:
8+
# - NGINX_ROBOTS_TAG: defaults to 'none'
9+
# - NGINX_ROBOTS_TXT: defaults to 'Disallow: /'
10+
11+
# Set defaults
12+
NGINX_ROBOTS_TAG="${NGINX_ROBOTS_TAG:-none}"
13+
NGINX_ROBOTS_TXT="${NGINX_ROBOTS_TXT:-Disallow: /}"
14+
15+
if [ -d /etc/nginx/site-mods-enabled.d/ ]; then
16+
# robots tag header
17+
echo "Nginx: configuring robots tag header with '${NGINX_ROBOTS_TAG}'…"
18+
cat <<EOF > /etc/nginx/site-mods-enabled.d/generated-robots.conf
19+
# Configure indexing
20+
add_header 'X-Robots-Tag' '${NGINX_ROBOTS_TAG}';
21+
EOF
22+
23+
# robots.txt file
24+
echo "Nginx: configuring robots.txt with '${NGINX_ROBOTS_TXT}'…"
25+
cat <<EOF >> /etc/nginx/site-mods-enabled.d/generated-robots.conf
26+
# Configure crawlers
27+
location = /robots.txt {
28+
add_header 'Content-Type' 'text/plain';
29+
return 200 "User-agent: *\n${NGINX_ROBOTS_TXT}\n";
30+
}
31+
EOF
32+
fi

matomo/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ COPY common/config/supervisor/supervisord.conf /etc/supervisor/
1515
COPY common/config/supervisor/conf.d/nginx.conf /etc/supervisor/conf.d/
1616
COPY matomo/config/supervisor/conf.d/ /etc/supervisor/conf.d/
1717
# - init
18-
COPY matomo/scripts/ /
18+
COPY common/scripts/ matomo/scripts/ /scripts/
1919

2020
# Configure cron
2121
RUN echo "*/30 * * * * /usr/local/bin/php /var/www/html/console core:archive --verbose --no-interaction" > /etc/crontabs/www-data
@@ -25,5 +25,5 @@ WORKDIR /var/www/html
2525
EXPOSE 8080
2626

2727
# Start supervisord by default
28-
ENTRYPOINT ["/docker-entrypoint.sh"]
28+
ENTRYPOINT ["/scripts/docker-entrypoint.sh"]
2929
CMD ["serve"]

matomo/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ Docker will default to the `serve` command.
1414
- `init`: initialize the project, such as executing migrations.
1515
- fallback: execute the provided command.
1616

17+
## Info
18+
19+
Serves content on port `8080`.
20+
1721
## Configuration
1822

23+
Check the [general readme](../README.md) for configuring common settings.
24+
1925
This image can be configured using the following environment variables:
2026

2127
| Environment Key | Applied | Description |
@@ -38,10 +44,6 @@ This image can be configured using the following environment variables:
3844
| MATOMO_DATABASE_USER | Every run | Database user |
3945
| MATOMO_DATABASE_PASSWORD | Every run | Database password |
4046

41-
## Info
42-
43-
Serves content on port `8080`.
44-
4547
# Initialization
4648

4749
Using an init container (that invokes `init` command above), the container will be prepared for use. This entails:

matomo/scripts/docker-entrypoint.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22

33
set -euo pipefail
44

5-
65
## Bootstrap
76

8-
9-
if [ ! -e matomo.php ]; then
10-
tar cf - --one-file-system -C /usr/src/matomo . | tar xf -
11-
fi
12-
7+
for script in /scripts/startup/*.sh; do
8+
$script
9+
done
1310

1411
## Commands ##
1512

16-
1713
# Helper to serve all services
1814
if [ "$1" = 'serve' ]; then
1915
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
2016

2117
# Init script, for use in initContainers (for example)
2218
elif [ "$1" = 'init' ]; then
23-
exec /bootstrap.sh
19+
exec /scripts/bootstrap.sh
2420

2521
# Fallback: just execute given command
2622
else
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
if [ ! -e matomo.php ]; then
6+
tar cf - --one-file-system -C /usr/src/matomo . | tar xf -
7+
fi

nuxt-base/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ COPY common/config/supervisor/supervisord.conf /etc/supervisor/
2020
COPY common/config/supervisor/conf.d/nginx.conf /etc/supervisor/conf.d/
2121
COPY nuxt-base/config/supervisor/conf.d/ /etc/supervisor/conf.d/
2222
# - init
23-
COPY nuxt-base/scripts/docker-entrypoint.sh /
23+
COPY common/scripts/ nuxt-base/scripts/ /scripts/
2424

2525
# Clean Up
2626
WORKDIR /app/www
27-
RUN chown -R nobody:nobody /docker-entrypoint.sh /app/www /run /var/lib/nginx /var/log/nginx \
27+
RUN chown -R nobody:nobody /scripts /app/www /run /var/lib/nginx /var/log/nginx /etc/nginx/site-mods-enabled.d \
2828
&& addgroup nobody tty
2929
EXPOSE 8080
3030

3131
# Start supervisord by default
32-
ENTRYPOINT ["/docker-entrypoint.sh"]
32+
ENTRYPOINT ["/scripts/docker-entrypoint.sh"]
3333
CMD ["serve"]
3434

3535
#

nuxt-base/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ Docker will default to the `serve` command.
1616
## Info
1717

1818
Serves content on port `8080`.
19+
20+
## Configuration
21+
22+
Check the [general readme](../README.md) for configuring common settings.

0 commit comments

Comments
 (0)