Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
48bef53
add master playbook
amandayclee Jun 28, 2024
6d8eab2
add roles/wordpress
amandayclee Jun 28, 2024
5175d3d
remove wordpress related configs in web/Dockerfile
amandayclee Jun 28, 2024
0fa821d
add step: Create the wp directory and set permissions
amandayclee Jun 28, 2024
4aa7cef
add play: Ensure wp directory exists and has correct permissions in w…
amandayclee Jun 28, 2024
b5e0f30
update the main.yml
Shafiya-Heena Jul 3, 2024
b920d34
update the directory structure of web
Shafiya-Heena Jul 3, 2024
c971fff
setup default path, updated playbook to isntall wpcli
Shafiya-Heena Jul 3, 2024
57b1884
update to set the permissions
Shafiya-Heena Jul 3, 2024
d066b51
update to align the spacing
Shafiya-Heena Jul 3, 2024
b1ecdbd
fix typo in ansible.cfg
amandayclee Jul 4, 2024
d17ad10
add wp_version arg when using WP_CLI to install wordpress
amandayclee Jul 6, 2024
318e778
add if condition to check wp installation but fail due to premission
amandayclee Jul 6, 2024
9900171
remove extra site.yml
amandayclee Jul 6, 2024
6215ef9
remove db/Dockerfile for connecting to db in ansible playbook, previo…
amandayclee Jul 9, 2024
ba7d22f
site and role moved into ansible-config
Shafiya-Heena Jul 9, 2024
ad36817
fixed wordpress site reverting db changes
Shafiya-Heena Jul 9, 2024
e72d329
add db/dockerfile
Shafiya-Heena Jul 9, 2024
b92510e
removed condition to check wp installed
Shafiya-Heena Jul 9, 2024
41175d8
update to read 000_default.conf
Shafiya-Heena Jul 9, 2024
d1e2e2f
add Wordpress Installation check task in main.yml
amandayclee Jul 10, 2024
d68f59c
add db/startupservice.sh to initialize db
amandayclee Jul 11, 2024
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 ansible/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ RUN python3 -m venv /opt/ansible-venv --system-site-packages && \

# Create a directory for Ansible configuration
RUN mkdir /etc/ansible/
WORKDIR /etc/ansible/

# Set environment variables for Ansible
ENV PATH="/opt/ansible-venv/bin:$PATH"
Expand Down
8 changes: 6 additions & 2 deletions ansible/etc-ansible-config/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[defaults]
inventory = /etc/ansible/hosts
remote_user = sysadmin
host_key_checking = True
host_key_checking = False
retry_files_enabled = False
private_key_file = /home/sysadmin/.ssh/id_rsa

[privilege_escalation]
become=True
become_password=''

[web:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_python_interpreter=/usr/bin/python3
79 changes: 79 additions & 0 deletions ansible/etc-ansible-config/roles/wordpress/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
- name: Add Apache2's www-data user to sudo group
user:
name: www-data
groups: sudo
append: yes

- name: Enable passwordless startup for www-data
copy:
dest: /etc/sudoers.d/www-data_startupservice
content: "www-data ALL=(ALL) NOPASSWD:ALL"
mode: '0440' # Correct mode for sudoers file

- name: Ensure wp directory exists and has correct permissions
file:
path: /usr/local/bin/wp
state: directory
owner: www-data
group: www-data
mode: '0755'

- name: Install WordPress CLI (WP-CLI)
get_url:
url: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
dest: /usr/local/bin/wp
mode: '0755'


- name: Create WP-CLI directory for www-data
file:
path: /var/www/.wp-cli
state: directory
owner: www-data
group: www-data
mode: '0755'

- name: Create the WordPress directory and set permissions
file:
path: /var/www/dev/wp-content/uploads
state: directory
owner: www-data
group: www-data
mode: '0755'

- name: Check Wordpress installed
stat:
path: /var/www/dev/wp-config.php
register: wp_config

- name: Use WP_CLI to install WordPress
shell: sudo -u www-data /usr/local/bin/wp/wp-cli.phar core download --version={{wp_version}}
when: not wp_config.stat.exists
args:
chdir: /var/www/dev
vars:
wp_version: 6.3.4

# Download wp-config-docker.php for use as wp-config.php
- name: WordPress basic configuration
get_url:
url: https://raw.githubusercontent.com/docker-library/wordpress/master/latest/php8.2/apache/wp-config-docker.php
dest: /var/www/dev/wp-config.php
owner: www-data
group: www-data
mode: '0644'

- name: Use awk to replace all instances of "put your unique phrase here" with a unique string
shell: |
awk '
/put your unique phrase here/ {
cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\\\ -f1";
cmd | getline str;
close(cmd);
gsub("put your unique phrase here", str);
}
{ print }
' /var/www/dev/wp-config.php > /var/www/dev/wp-config.tmp \
&& mv /var/www/dev/wp-config.tmp /var/www/dev/wp-config.php
args:
chdir: /var/www/dev
3 changes: 3 additions & 0 deletions ansible/etc-ansible-config/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- hosts: web
roles:
- wordpress
9 changes: 7 additions & 2 deletions db/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ RUN mkdir -p /run/sshd

# Expose SSH port
EXPOSE 22
EXPOSE 3306

# Start SSH service
CMD ["/usr/sbin/sshd", "-D"]
# Add mariadb service startup script
COPY ./db/startupservice.sh /startupservice.sh
RUN chmod +x /startupservice.sh

ENTRYPOINT ["/startupservice.sh"]
CMD ["mariadbd"]
15 changes: 15 additions & 0 deletions db/startupservice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -o errexit
set -o nounset

# https://en.wikipedia.org/wiki/ANSI_escape_code
E0="$(printf "\e[0m")" # reset
E1="$(printf "\e[1m")" # bold

echo "${E1}Starting mariadb: http://127.0.0.1:3306${E0}"

# Start mariadb in the background
docker-entrypoint.sh "$@"

# Start SSH service
/usr/sbin/sshd -D
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ services:
- '22002:22'
restart: on-failure
volumes:
- ./web/etc-apache2-sites-available:/etc/apache2/sites-available
- wp-data:/var/www/dev
- ./sysadmin-ssh-keys/rsa_sysadmin:/home/sysadmin/.ssh/id_rsa:ro
- ./sysadmin-ssh-keys/rsa_sysadmin.pub:/home/sysadmin/.ssh/id_rsa.pub:ro
Expand Down
55 changes: 10 additions & 45 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# https://docs.docker.com/engine/reference/builder/
# https://hub.docker.com/_/debian
# Use the Debian Bookworm Slim base image
FROM debian:bookworm-slim

# Configure apt not to prompt during docker build
Expand Down Expand Up @@ -47,6 +46,9 @@ RUN useradd -m -s /bin/bash sysadmin && \
echo "sysadmin:sysadmin" | chpasswd && \
usermod -aG sudo sysadmin

# Copy the sudoers file for sysadmin user to the appropriate directory
COPY ./web/etc-sudoers.d/sysadmin_all_nopass /etc/sudoers.d/sysadmin_all_nopass

# Ensure SSH directory exists with correct permissions
RUN mkdir -p /home/sysadmin/.ssh && \
chown sysadmin:sysadmin /home/sysadmin/.ssh && \
Expand All @@ -57,10 +59,10 @@ RUN mkdir -p /run/sshd

# Add Apache2's www-data user to sudo group and enable passwordless startup
RUN adduser www-data sudo
COPY web/config-web/www-data_startupservice /etc/sudoers.d/www-data_startupservice
COPY ./web/etc-sudoers.d/www-data_startupservice /etc/sudoers.d/www-data_startupservice

# Add Apache2 service startup script
COPY web/config-web/startupservice.sh /startupservice.sh
COPY ./web/startupservice.sh /startupservice.sh
RUN chmod +x /startupservice.sh
CMD ["sudo", "--preserve-env", "/startupservice.sh"]

Expand All @@ -76,50 +78,13 @@ RUN a2enmod php8.2
RUN a2enmod rewrite

# Configure PHP
COPY web/config-web/90-local.ini /etc/php/8.2/apache2/conf.d/

# Install WordPress CLI (WP-CLI)
# https://wp-cli.org/#installing
RUN curl -L \
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
-o wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp
COPY ./web/etc-php-8.2-apache2-conf.d/90-local.ini /etc/php/8.2/apache2/conf.d/

# Create WP-CLI directory for www-data
RUN mkdir /var/www/.wp-cli
RUN chown -R www-data:www-data /var/www/.wp-cli
# Create the wp directory and set permissions
RUN mkdir -p /usr/local/bin/wp/
RUN chown -R www-data:www-data /usr/local/bin/wp/

# Create the dev directory and set permissions
RUN mkdir -p /var/www/dev/wp-content/uploads
RUN chown -R www-data:www-data /var/www/dev

# Use WP-CLI to install WordPress
USER www-data
WORKDIR /var/www/dev
ARG WP_VERSION
RUN wp core download --version=$WP_VERSION

# Add WordPress basic configuration
# 1) Download wp-config-docker.php for use as wp-config.php. Friendly view at:
# https://github.com/docker-library/wordpress/blob/master/latest/php8.2/apache/wp-config-docker.php
RUN curl -L \
https://raw.githubusercontent.com/docker-library/wordpress/master/latest/php8.2/apache/wp-config-docker.php \
-o /var/www/dev/wp-config.php

# 2) Use awk to replace all instances of "put your unique phrase here" with a
# properly unique string (for AUTH_KEY and friends to have safe defaults if
# they aren't specified with environment variables)
# Based on:
# https://github.com/docker-library/wordpress/blob/master/latest/php8.2/apache/docker-entrypoint.sh
RUN awk ' \
/put your unique phrase here/ { \
cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\ -f1"; \
cmd | getline str; \
close(cmd); \
gsub("put your unique phrase here", str); \
} \
{ print } \
' /var/www/dev/wp-config.php > /var/www/dev/wp-config.tmp \
&& mv /var/www/dev/wp-config.tmp /var/www/dev/wp-config.php

Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ ServerName localhost:8080

</VirtualHost>

# vim: ft=apache ts=4 sw=4 sts=4 sr et
# vim: ft=apache ts=4 sw=4 sts=4 sr et
5 changes: 5 additions & 0 deletions web/etc-sudoers.d/sysadmin_all_nopass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# vim: ft=sudoers
#
# This file MUST be edited with `/usr/sbin/visudo -sf FILENAME`.

%sudo ALL =(ALL) NOPASSWD:ALL
File renamed without changes.