Skip to content

Commit 60e3a13

Browse files
authored
feat: enhance Docker setup with SSL configuration (#5)
1 parent a796dff commit 60e3a13

8 files changed

Lines changed: 79 additions & 209 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
.DS_Store
2+
tests/volumes
3+
tests/ssl
4+
tests/www
5+
tests/nginx

Dockerfile

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ ARG PHP_VERSION=7.4.33
33

44
FROM php:$PHP_VERSION-fpm-$DEBIAN_VERSION
55

6-
ENV SSL_ENABLED="false";
7-
RUN mkdir "/var/ssl";
6+
# Add environment variables for domain and port
7+
ENV SERVER_NAME="example.com"
8+
ENV SSL_ENABLED="false"
9+
10+
ENV WP_DB_HOST="db"
11+
ENV WP_DB_USER="root"
12+
ENV WP_DB_PASSWORD="password"
13+
ENV WP_DB_NAME="wordpress"
814

915
# Add Debian Bookworm repositories and install necessary tools
1016
# persistent dependencies
@@ -107,6 +113,14 @@ RUN set -ex; \
107113
; \
108114
rm -rf /var/lib/apt/lists/*
109115

116+
# Install Certbot using the package manager
117+
RUN set -eux; \
118+
apt-get update; \
119+
apt-get install -y --no-install-recommends certbot python3-certbot-nginx cron
120+
121+
# Add a cron job for Certbot auto-renewal
122+
RUN echo "0 0,12 * * * certbot renew --quiet" | crontab -
123+
110124
# Update Nginx to run as www-data
111125
RUN sed -i 's/user nginx;/user www-data;/' /etc/nginx/nginx.conf
112126
RUN usermod -a -G nginx www-data
@@ -115,15 +129,20 @@ RUN usermod -a -G nginx www-data
115129
RUN mkdir /usr/src/nginx-defaults
116130
COPY ./nginx/default.conf /usr/src/nginx-defaults/default.conf
117131
COPY ./nginx/wordpress.conf.include /usr/src/nginx-defaults/wordpress.conf.include
118-
COPY ./nginx/default_ssl.conf /usr/src/nginx-defaults/default_ssl.conf
119-
COPY ./nginx/options-ssl-nginx.conf /usr/src/nginx-defaults/options-ssl-nginx.conf
132+
# COPY ./nginx/default_ssl.conf /usr/src/nginx-defaults/default_ssl.conf
133+
# COPY ./nginx/options-ssl-nginx.conf /usr/src/nginx-defaults/options-ssl-nginx.conf
134+
# RUN mkdir "/var/ssl";
120135

121136
# Expose the default Nginx port
122137
EXPOSE 80
123-
EXPOSE 443
138+
# Expose the default Nginx SSL port if SSL is enabled
139+
RUN if [ "$SSL_ENABLED" = "true" ]; then \
140+
echo "EXPOSE 443"; \
141+
fi
124142

125143
COPY ./entrypoint.sh /entrypoint.sh
126144
RUN chmod +x /entrypoint.sh
145+
127146
ENTRYPOINT ["/entrypoint.sh"]
128147

129148

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@ Example of docker-compose, using this image and mysql image:
1414
version: '3'
1515
services:
1616
web:
17-
image: augwit/wordpress:7.4.33-ALPHA.2
17+
image: augwit/wordpress:7.4.33-BETA.1
1818
restart: always
1919
container_name: wordpress
2020
ports:
2121
- 80:80
2222
- 443:443
2323
environment:
24+
- SERVER_NAME=localhost
2425
- SSL_ENABLED=false
26+
- WP_DB_HOST=db
27+
- WP_DB_USER=root
28+
- WP_DB_PASSWORD=password
29+
- WP_DB_NAME=wordpress
2530
volumes:
2631
- ./www:/var/www/html
2732
- ./nginx/log:/var/log/nginx
2833
- ./ssl:/var/ssl
2934
db:
3035
image: mysql/mysql-server:8.0.30
31-
container_name: mysql
3236
restart: always
3337
environment:
3438
MYSQL_USER: root

entrypoint.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,34 @@
22
cp /usr/src/nginx-defaults/wordpress.conf.include /etc/nginx/conf.d/;
33
cp /usr/src/nginx-defaults/default.conf /etc/nginx/conf.d/;
44

5-
if [ "$SSL_ENABLED" = "true" ]; then
6-
cp /usr/src/nginx-defaults/options-ssl-nginx.conf /var/ssl;
7-
cp /usr/src/nginx-defaults/default_ssl.conf /etc/nginx/conf.d/;
5+
# if [ "$SSL_ENABLED" = "true" ]; then
6+
# cp /usr/src/nginx-defaults/options-ssl-nginx.conf /var/ssl;
7+
# cp /usr/src/nginx-defaults/default_ssl.conf /etc/nginx/conf.d/;
8+
# fi
9+
10+
# Update entrypoint to configure Nginx and acquire SSL certificates
11+
sed -i "s/server_name localhost;/server_name $SERVER_NAME;/" /etc/nginx/conf.d/default.conf
12+
13+
if [ "$SSL_ENABLED" = "true" ]; then
14+
certbot --nginx -d $SERVER_NAME --non-interactive --agree-tos --register-unsafely-without-email -m admin@$SERVER_NAME
15+
service nginx stop
816
fi
917

1018
# Download the latest wordpress
11-
curl https://wordpress.org/latest.zip -o /var/www/wordpress_latest.zip
12-
unzip /var/www/wordpress_latest.zip -d /var/www/
13-
rm -f /var/www/wordpress_latest.zip
14-
cp -r /var/www/wordpress/* /var/www/html/
15-
rm -rf /var/www/wordpress
19+
if [ ! -f /var/www/html/index.php ]; then
20+
curl https://wordpress.org/latest.zip -o /var/www/wordpress_latest.zip
21+
unzip /var/www/wordpress_latest.zip -d /var/www/
22+
rm -f /var/www/wordpress_latest.zip
23+
cp -r /var/www/wordpress/* /var/www/html/
24+
rm -rf /var/www/wordpress
25+
fi
26+
27+
# Copy wp-config-sample.php to wp-config.php and update database configuration
28+
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
29+
sed -i "s/database_name_here/${WP_DB_NAME}/" /var/www/html/wp-config.php
30+
sed -i "s/username_here/${WP_DB_USER}/" /var/www/html/wp-config.php
31+
sed -i "s/password_here/${WP_DB_PASSWORD}/" /var/www/html/wp-config.php
32+
sed -i "s/localhost/${WP_DB_HOST}/" /var/www/html/wp-config.php
1633

1734
# Change owner of the web folder
1835
chown -R www-data /var/www/html

nginx/default.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
server {
2-
listen 80 default_server;
2+
server_name localhost;
3+
listen 80;
34
root /var/www/html/;
45

56
include conf.d/wordpress.conf.include;

tests/docker-compose.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
version: '3'
21
services:
3-
# db:
4-
# image: mysql/mysql-server:8.0.30
5-
# container_name: mysql8
6-
# restart: always
7-
# environment:
8-
# MYSQL_USER: root
9-
# MYSQL_ALLOW_EMPTY_PASSWORD: 'no'
10-
# MYSQL_PASSWORD: QWE123rt!
11-
# ports:
12-
# - 3306:3306
13-
# volumes:
14-
# - ./volumes/mysql/data:/var/lib/mysql
152
web:
16-
image: augwit/wordpress:7.4.33-ALPHA.1
3+
image: augwit/wordpress:7.4.33-BETA.1
174
restart: always
185
container_name: wordpress
196
ports:
207
- 80:80
218
- 443:443
229
environment:
10+
- SERVER_NAME=localhost
2311
- SSL_ENABLED=false
12+
- WP_DB_HOST=db
13+
- WP_DB_USER=root
14+
- WP_DB_PASSWORD=QWE123rt!
15+
- WP_DB_NAME=wordpress
2416
volumes:
2517
- ./www:/var/www/html
2618
- ./nginx/log:/var/log/nginx
2719
- ./ssl:/var/ssl
20+
db:
21+
image: mysql/mysql-server:8.0.30
22+
restart: always
23+
environment:
24+
MYSQL_USER: root
25+
MYSQL_ALLOW_EMPTY_PASSWORD: 'no'
26+
MYSQL_PASSWORD: QWE123rt!
27+
MYSQL_DATABASE: wordpress
28+
ports:
29+
- 3306:3306
30+
volumes:
31+
- ./volumes/mysql/data:/var/lib/mysql
2832

tests/nginx/log/access.log

Whitespace-only changes.

tests/nginx/log/error.log

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

0 commit comments

Comments
 (0)