Merge ~barryprice/wordpress-k8s-image-builder/+git/wordpress-k8s-image-builder:master into ~barryprice/wordpress-k8s-image-builder:master

Proposed by Barry Price
Status: Superseded
Proposed branch: ~barryprice/wordpress-k8s-image-builder/+git/wordpress-k8s-image-builder:master
Merge into: ~barryprice/wordpress-k8s-image-builder:master
Diff against target: 285 lines (+255/-0)
5 files modified
.gitignore (+3/-0)
Dockerfile (+57/-0)
Makefile (+27/-0)
fetcher.py (+136/-0)
tox.ini (+32/-0)
Reviewer Review Type Date Requested Status
Barry Price Pending
Review via email: mp+377428@code.launchpad.net

This proposal supersedes a proposal from 2020-01-10.

Commit message

Create a Docker image to run the latest Wordpress, with our whitelisted plugins (upstream .zip and LP branches) and themes (LP branches only) already included.

To post a comment you must log in.

Unmerged commits

122294d... by Barry Price

Use .latest-stable plugin URLs, drop BS/requests

967a385... by Barry Price

Add progress indicators to fetcher

93454b1... by Barry Price

Cleaner Makefile, strip historical wp-plugin- or wp-theme- prefixes

133eef4... by Barry Price

Use bzr/git directly instead of charmhelpers.fetch, clean up Makefile, add deps

fefc781... by Barry Price

Add tox/Makefile support (n.b. fetcher is currently failing to run 'bzr' via tox...

2aac1f5... by Barry Price

Initial commit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/.gitignore b/.gitignore
0new file mode 1006440new file mode 100644
index 0000000..ac6bb88
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
1plugins/
2themes/
3.tox/
diff --git a/Dockerfile b/Dockerfile
0new file mode 1006444new file mode 100644
index 0000000..2a67c50
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,57 @@
1FROM ubuntu:bionic
2
3RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
4
5RUN apt-get update && apt-get -y dist-upgrade \
6 && apt-get --purge remove -y ${pks_to_purge}
7
8ENV APACHE_CONFDIR=/etc/apache2
9ENV APACHE_ENVVARS=/etc/apache2/envvars
10
11RUN apt-get update \
12 && apt-get install -y --no-install-recommends apache2 \
13 && rm -rf /var/lib/apt/lists/* \
14 && sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" \
15 && . "$APACHE_ENVVARS" \
16 && for dir in "$APACHE_LOCK_DIR" "$APACHE_RUN_DIR" "$APACHE_LOG_DIR"; do rm -rvf "$dir"; mkdir -p "$dir"; chown "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"; chmod 777 "$dir"; done \
17 && ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
18 && ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
19 && ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" \
20 && chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
21
22RUN echo '<FilesMatch \.php$>' > "$APACHE_CONFDIR/conf-available/docker-php.conf" \
23 && echo '\tSetHandler application/x-httpd-php' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
24 && echo '</FilesMatch>' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
25 && echo >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
26 && echo 'DirectoryIndex disabled' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
27 && echo 'DirectoryIndex index.php index.html' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
28 && echo >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
29 && echo '<Directory /var/www/>' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
30 && echo '\tOptions -Indexes' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
31 && echo '\tAllowOverride All' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
32 && echo '</Directory>' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
33 && a2enconf docker-php
34
35RUN apt-get update && apt-get install -y curl php libapache2-mod-php php-mysql php-gd \
36 && apt-get clean \
37 && rm -rf /var/lib/apt/lists/*
38
39RUN a2dismod mpm_event \
40 && a2enmod mpm_prefork
41
42ENV WORDPRESS_VERSION=5.3.2
43ENV WORDPRESS_SHA1=fded476f112dbab14e3b5acddd2bcfa550e7b01b
44
45RUN curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \
46 && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
47 && tar -xzf wordpress.tar.gz -C /usr/src/ \
48 && rm wordpress.tar.gz \
49 && chown -R www-data:www-data /usr/src/wordpress \
50 && rm -rf /var/www/html \
51 && mv /usr/src/wordpress /var/www/html
52
53COPY --chown=www-data:www-data ./plugins/ /var/www/html/wp-content/plugins/
54COPY --chown=www-data:www-data ./themes/ /var/www/html/wp-content/themes/
55
56EXPOSE 80
57CMD apachectl -D FOREGROUND
diff --git a/Makefile b/Makefile
0new file mode 10064458new file mode 100644
index 0000000..14a5b83
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,27 @@
1build: lint deps
2 @echo "Fetching plugins and themes."
3 @tox -e fetch
4 @echo "Building the image."
5 @docker build . -t wordpress
6
7deps:
8 @echo "Checking dependencies are present"
9 which bzr || sudo apt-get install -y bzr
10 which git || sudo apt-get install -y git
11
12lint: clean
13 @echo "Normalising python layout with black."
14 @tox -e black
15 @echo "Running flake8"
16 @tox -e lint
17
18clean:
19 @echo "Cleaning files"
20 @rm -rf ./.tox
21 @rm -rf ./.pytest_cache
22 @rm -rf ./plugins/*
23 @rm -rf ./themes/*
24 @mkdir -p plugins
25 @mkdir -p themes
26
27.PHONY: build lint clean
diff --git a/fetcher.py b/fetcher.py
0new file mode 10075528new file mode 100755
index 0000000..2fe005c
--- /dev/null
+++ b/fetcher.py
@@ -0,0 +1,136 @@
1#!/usr/bin/env python3
2
3import os
4import shutil
5import subprocess
6import urllib.request
7import zipfile
8
9
10zip_plugins_to_get = {
11 # please keep these in alphabetical order
12 '404page',
13 'all-in-one-event-calendar',
14 'coschedule-by-todaymade',
15 'elementor',
16 'essential-addons-for-elementor-lite',
17 'favicon-by-realfavicongenerator',
18 'feedwordpress',
19 'fruitful-shortcodes',
20 'genesis-columns-advanced',
21 'line-break-shortcode',
22 'no-category-base-wpml',
23 'openid',
24 'post-grid',
25 'powerpress',
26 'redirection',
27 'relative-image-urls',
28 'rel-publisher',
29 'safe-svg',
30 'show-current-template',
31 'simple-301-redirects',
32 'simple-custom-css',
33 'social-media-buttons-toolbar',
34 'so-widgets-bundle',
35 'svg-support',
36 'syntaxhighlighter',
37 'wordpress-importer',
38 'wordpress-seo',
39 'wp-font-awesome',
40 'wp-lightbox-2',
41 'wp-markdown',
42 'wp-mastodon-share',
43 'wp-polls',
44 'wp-statistics',
45}
46
47branch_plugins_to_get = {
48 # please keep these in alphabetical order
49 'launchpad-integration': {'url': 'lp:wordpress-launchpad-integration'},
50 'openstack-objectstorage': {'url': 'lp:~canonical-sysadmins/wordpress/openstack-objectstorage'},
51 'teams-integration': {'url': 'lp:wordpress-teams-integration'},
52 'xubuntu-team-members': {'url': 'lp:~canonical-sysadmins/wordpress/wp-plugin-xubuntu-team-members'},
53}
54
55branch_themes_to_get = {
56 # please keep these in alphabetical order
57 'fruitful': {'url': 'https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-fruitful'},
58 'light-wordpress-theme': {'url': 'lp:ubuntu-community-webthemes/light-wordpress-theme'},
59 'mscom': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-mscom'},
60 'twentyeleven': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-twentyeleven'},
61 'ubuntu-cloud-website': {'url': 'lp:ubuntu-cloud-website'},
62 'ubuntu-community': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-community'},
63 'ubuntu-community-wordpress-theme': {'url': 'lp:ubuntu-community-wordpress-theme'},
64 'ubuntu-fi-new': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-fi'},
65 'ubuntu-light': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-light'},
66 'ubuntustudio-wp': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntustudio-wp'},
67 'wordpress_launchpad': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-launchpad'},
68 'xubuntu-theme': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-xubuntu-website'},
69}
70
71
72def get_plugins(zip_plugins, branch_plugins):
73 total_zips = len(zip_plugins)
74 current_zip = 0
75 for zip_plugin in zip_plugins:
76 current_zip = current_zip + 1
77 print('Downloading zipped plugin {} of {}...'.format(current_zip, total_zips), end="\r")
78 url = 'https://downloads.wordpress.org/plugin/{}.latest-stable.zip'.format(zip_plugin)
79 file_name = os.path.join(os.getcwd(), 'plugins', os.path.basename(url))
80 with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
81 shutil.copyfileobj(response, out_file)
82 with zipfile.ZipFile(file_name, 'r') as zip_ref:
83 zip_ref.extractall(os.path.join(os.getcwd(), 'plugins'))
84 os.remove(file_name)
85 print()
86
87 total_branches = len(branch_plugins)
88 current_branch = 0
89 for branch_plugin in branch_plugins:
90 current_branch = current_branch + 1
91 print('Downloading branched plugin {} of {}...'.format(current_branch, total_branches), end="\r")
92 url = branch_plugins[branch_plugin].get('url')
93 basename = os.path.basename(url)
94 if basename.startswith('lp:'):
95 basename = basename[3:]
96 if basename.startswith('wp-plugin-'):
97 basename = basename[10:]
98 dest = os.path.join(os.getcwd(), 'plugins/', basename)
99 if url.startswith('lp:'):
100 cmd = ['bzr', 'branch', url, dest]
101 elif url.startswith('https://git'):
102 cmd = ['git', 'clone', url, dest]
103 else:
104 print("ERROR: Don't know how to clone {}".format(url))
105 exit(1)
106 _ = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.PIPE)
107 print()
108
109
110def get_themes(branch_themes):
111 total_branches = len(branch_themes)
112 current_branch = 0
113 for branch_theme in branch_themes:
114 current_branch = current_branch + 1
115 print('Downloading branched theme {} of {}...'.format(current_branch, total_branches), end="\r")
116 url = branch_themes[branch_theme].get('url')
117 basename = os.path.basename(url)
118 if basename.startswith('lp:'):
119 basename = basename[3:]
120 if basename.startswith('wp-theme-'):
121 basename = basename[9:]
122 dest = os.path.join(os.getcwd(), 'themes/', basename)
123 if url.startswith('lp:'):
124 cmd = ['bzr', 'branch', url, dest]
125 elif url.startswith('https://git'):
126 cmd = ['git', 'clone', url, dest]
127 else:
128 print("ERROR: Don't know how to clone {}".format(url))
129 exit(1)
130 _ = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.PIPE)
131 print()
132
133
134if __name__ == '__main__':
135 get_plugins(zip_plugins_to_get, branch_plugins_to_get)
136 get_themes(branch_themes_to_get)
diff --git a/tox.ini b/tox.ini
0new file mode 100644137new file mode 100644
index 0000000..92befc4
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,32 @@
1[tox]
2skipsdist=True
3envlist = build
4skip_missing_interpreters = True
5
6[testenv]
7basepython = python3
8setenv =
9 PYTHONPATH = .
10
11[testenv:black]
12commands = {envbindir}/black --skip-string-normalization --line-length=120 .
13deps = black
14
15[testenv:lint]
16commands = {envbindir}/flake8
17deps = flake8
18
19[testenv:fetch]
20commands = ./fetcher.py
21setenv =
22 BZR_HOME = /tmp
23
24[flake8]
25exclude =
26 .git,
27 __pycache__,
28 .tox,
29 plugins/
30 themes/
31max-line-length = 120
32max-complexity = 10

Subscribers

People subscribed via source and target branches

to all changes: