Skip to content

Commit 6cab763

Browse files
committed
#3: Refactor everything into RKD
1 parent 6e90f62 commit 6cab763

File tree

11 files changed

+181
-108
lines changed

11 files changed

+181
-108
lines changed

Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ MAINTAINER RiotKit <[email protected]>
77

88
ARG RIOTKIT_IMAGE_VERSION=""
99

10+
# The credentials does not need to be top secret, at least those credentials needs to protect against automatic bots
11+
# default basic auth credentials: riotkit, riotkit
12+
# to change credentials just replace file "/opt/htpsswd" using volume mount or customized image
13+
1014
ENV AUTO_UPDATE_CRON="0 5 * * SAT" \
15+
BASIC_AUTH_ENABLED=true \
16+
BASIC_AUTH_USER=riotkit \
17+
BASIC_AUTH_PASSWORD=riotkit \
1118
PHP_DISPLAY_ERRORS="Off" \
1219
PHP_ERROR_REPORTING="E_ALL & ~E_DEPRECATED & ~E_STRICT" \
1320
PHP_POST_MAX_SIZE="32M" \
@@ -16,19 +23,18 @@ ENV AUTO_UPDATE_CRON="0 5 * * SAT" \
1623
RKD_PATH="/opt/.rkd" \
1724
PYTHONUNBUFFERED=1
1825

19-
ADD ./opt/.rkd /opt/.rkd
26+
ADD ./container-files/opt/.rkd /opt/.rkd
2027

21-
RUN apk --update add nginx supervisor python3 py3-pip \
28+
RUN apk --update add nginx supervisor python3 py3-pip nano apache2-utils \
2229
&& curl "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" --output /usr/bin/wp \
2330
&& mkdir -p /var/tmp/nginx/ /var/lib/nginx/tmp/ \
2431
&& chown www-data:www-data /var/tmp/nginx/ /var/lib/nginx/tmp/ -R \
2532
&& chmod +x /usr/bin/wp \
2633
&& pip3 install -r /opt/.rkd/requirements.txt
2734

28-
ADD etc/supervisor.conf /etc/supervisor.conf
29-
ADD etc/nginx/nginx.conf /etc/nginx/nginx.conf
3035
ADD ./wp-config-sample.php /usr/src/wordpress/wp-config-sample.php
3136
ADD ./wp-config-riotkit.php /usr/src/wordpress/wp-config-riotkit.php
32-
ADD ./usr /templates/usr
37+
ADD ./container-files /templates
38+
ADD htpasswd /opt/htpasswd
3339

3440
ENTRYPOINT ["rkd", ":entrypoint"]

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ Patched version of official Wordpress container.
77
- Scheduled updates via wp-cli
88
- **NGINX instead of Apache**
99
- Support for RiotKit Harbor and NGINX-PROXY (VIRTUAL_HOST environment variable)
10+
- Basic Auth enabled by default to protect wp-login and wp-admin against bots (default user: `riotkit`, password: `riotkit`)
11+
12+
Changing basic auth password or disabling it at all
13+
===================================================
14+
15+
**Disabling:**
16+
17+
```bash
18+
-e BASIC_AUTH_ENABLED=false
19+
```
20+
21+
**Changing password:**
22+
23+
```bash
24+
-e BASIC_AUTH_USER=some-user -e BASIC_AUTH_PASSWORD=some-password
25+
```
1026

1127
Versions
1228
========
@@ -39,6 +55,11 @@ services:
3955
WORDPRESS_DB_PASSWORD: "${DB_PASSWORD_THERE}"
4056
WORDPRESS_DB_NAME: "your_app"
4157
AUTO_UPDATE_CRON: "0 5 * * SAT"
58+
59+
# basic auth on administrative endpoints
60+
BASIC_AUTH_ENABLED=true
61+
BASIC_AUTH_USER: john
62+
BASIC_AUTH_PASSWORD: secret
4263

4364
# main page URL
4465
WP_PAGE_URL: "zsp.net.pl"
@@ -48,6 +69,19 @@ services:
4869

4970
```
5071

72+
Building and debugging image
73+
----------------------------
74+
75+
**Build and run a snapshot locally:**
76+
77+
```bash
78+
# build
79+
rkd :boat-ci:specific-release -v 1.0 --app-version 5.5 --dir . --dest-docker-repo="quay.io/riotkit/wp-auto-update" --docker-build-opts="" --become=root
80+
81+
# run
82+
docker run -p 8001:80 --rm --name wp quay.io/riotkit/wp-auto-update:1.0
83+
```
84+
5185
From authors
5286
============
5387

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
user www-data;
2+
daemon off;
3+
worker_processes 3;
4+
pid /var/run/nginx.pid;
5+
6+
events {
7+
worker_connections 768;
8+
}
9+
10+
http {
11+
sendfile on;
12+
tcp_nopush on;
13+
tcp_nodelay on;
14+
keepalive_timeout 65;
15+
types_hash_max_size 4096;
16+
17+
client_max_body_size 512M;
18+
client_body_temp_path /tmp 1 2;
19+
client_body_buffer_size 256k;
20+
client_body_in_file_only off;
21+
22+
server_tokens off;
23+
max_ranges 1;
24+
25+
include /etc/nginx/mime.types;
26+
default_type application/octet-stream;
27+
28+
fastcgi_temp_file_write_size 20m;
29+
fastcgi_busy_buffers_size 786k;
30+
fastcgi_buffer_size 512k;
31+
fastcgi_buffers 16 512k;
32+
33+
access_log /dev/stdout;
34+
error_log /dev/stderr info;
35+
36+
# should be enabled on gateway
37+
gzip off;
38+
39+
server {
40+
listen 80 default_server;
41+
root /var/www/html;
42+
index index.html index.php;
43+
server_name _;
44+
45+
index index.php;
46+
47+
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
48+
fastcgi_param SERVER_SOFTWARE Nginx;
49+
fastcgi_param QUERY_STRING $query_string;
50+
fastcgi_param REQUEST_METHOD $request_method;
51+
fastcgi_param CONTENT_TYPE $content_type;
52+
fastcgi_param CONTENT_LENGTH $content_length;
53+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
54+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
55+
fastcgi_param REQUEST_URI $request_uri;
56+
fastcgi_param DOCUMENT_URI $document_uri;
57+
fastcgi_param DOCUMENT_ROOT $document_root;
58+
fastcgi_param SERVER_PROTOCOL $server_protocol;
59+
fastcgi_param REMOTE_ADDR $remote_addr;
60+
fastcgi_param REMOTE_PORT $remote_port;
61+
fastcgi_param SERVER_ADDR $server_addr;
62+
fastcgi_param SERVER_PORT $server_port;
63+
fastcgi_param SERVER_NAME $server_name;
64+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
65+
66+
67+
set $path_info $fastcgi_path_info;
68+
fastcgi_param PATH_INFO $path_info;
69+
fastcgi_index index.php;
70+
fastcgi_read_timeout 60s;
71+
72+
location = /favicon.ico {
73+
log_not_found off;
74+
access_log off;
75+
}
76+
77+
location = /robots.txt {
78+
allow all;
79+
log_not_found off;
80+
access_log off;
81+
}
82+
83+
{% if BASIC_AUTH_ENABLED %}
84+
location ^~ /wp-login.php {
85+
auth_basic "Access secured";
86+
auth_basic_user_file /opt/htpasswd;
87+
88+
try_files $fastcgi_script_name =404;
89+
fastcgi_pass localhost:9000;
90+
91+
break;
92+
}
93+
94+
location ~ /wp-admin {
95+
auth_basic "Access secured";
96+
auth_basic_user_file /opt/htpasswd;
97+
98+
try_files $fastcgi_script_name =404;
99+
fastcgi_pass localhost:9000;
100+
101+
break;
102+
}
103+
{% endif %}
104+
105+
location / {
106+
# This is cool because no php is touched for static content.
107+
# include the "?$args" part so non-default permalinks doesn't break when using query string
108+
try_files $uri $uri/ /index.php?$args;
109+
}
110+
111+
location ~ \.php$ {
112+
try_files $fastcgi_script_name =404;
113+
fastcgi_pass localhost:9000;
114+
}
115+
116+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
117+
expires max;
118+
log_not_found off;
119+
}
120+
121+
location ~ /\.ht {
122+
deny all;
123+
}
124+
}
125+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

opt/.rkd/makefile.yaml renamed to container-files/opt/.rkd/makefile.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ tasks:
1111
%RKD% :setup:crontab \
1212
:setup:configs \
1313
:setup:wordpress-files \
14+
:setup:basicauth \
1415
:run:supervisor
1516
17+
:setup:basicauth:
18+
steps: |
19+
if [[ "${BASIC_AUTH_USER}" ]] && [[ "${BASIC_AUTH_PASSWORD}" ]]; then
20+
echo " >> Writing to basic auth file - /opt/htpasswd"
21+
htpasswd -b -c /opt/htpasswd "${BASIC_AUTH_USER}" "${BASIC_AUTH_PASSWORD}"
22+
else
23+
echo " >> No user or password set, skipping writing to /opt/htpasswd"
24+
fi
25+
1626
:run:supervisor:
1727
description: Run supervisor with applications
1828
steps: supervisord -c /etc/supervisor.conf
@@ -28,7 +38,6 @@ tasks:
2838
%RKD% :j2:directory-to-directory \
2939
--source=/templates \
3040
--target=/ \
31-
--delete-source-files \
3241
--pattern="(.*).j2" \
3342
--copy-not-matching-files
3443
File renamed without changes.

etc/nginx/nginx.conf

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

htpasswd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
riotkit:$apr1$UmjxQSi2$0YCrneUIpiAjetzQrhqoj.

0 commit comments

Comments
 (0)