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+377426@code.launchpad.net

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

This proposal has been superseded by 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
1diff --git a/.gitignore b/.gitignore
2new file mode 100644
3index 0000000..ac6bb88
4--- /dev/null
5+++ b/.gitignore
6@@ -0,0 +1,3 @@
7+plugins/
8+themes/
9+.tox/
10diff --git a/Dockerfile b/Dockerfile
11new file mode 100644
12index 0000000..2a67c50
13--- /dev/null
14+++ b/Dockerfile
15@@ -0,0 +1,57 @@
16+FROM ubuntu:bionic
17+
18+RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
19+
20+RUN apt-get update && apt-get -y dist-upgrade \
21+ && apt-get --purge remove -y ${pks_to_purge}
22+
23+ENV APACHE_CONFDIR=/etc/apache2
24+ENV APACHE_ENVVARS=/etc/apache2/envvars
25+
26+RUN apt-get update \
27+ && apt-get install -y --no-install-recommends apache2 \
28+ && rm -rf /var/lib/apt/lists/* \
29+ && sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" \
30+ && . "$APACHE_ENVVARS" \
31+ && 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 \
32+ && ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
33+ && ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
34+ && ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" \
35+ && chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
36+
37+RUN echo '<FilesMatch \.php$>' > "$APACHE_CONFDIR/conf-available/docker-php.conf" \
38+ && echo '\tSetHandler application/x-httpd-php' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
39+ && echo '</FilesMatch>' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
40+ && echo >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
41+ && echo 'DirectoryIndex disabled' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
42+ && echo 'DirectoryIndex index.php index.html' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
43+ && echo >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
44+ && echo '<Directory /var/www/>' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
45+ && echo '\tOptions -Indexes' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
46+ && echo '\tAllowOverride All' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
47+ && echo '</Directory>' >> "$APACHE_CONFDIR/conf-available/docker-php.conf" \
48+ && a2enconf docker-php
49+
50+RUN apt-get update && apt-get install -y curl php libapache2-mod-php php-mysql php-gd \
51+ && apt-get clean \
52+ && rm -rf /var/lib/apt/lists/*
53+
54+RUN a2dismod mpm_event \
55+ && a2enmod mpm_prefork
56+
57+ENV WORDPRESS_VERSION=5.3.2
58+ENV WORDPRESS_SHA1=fded476f112dbab14e3b5acddd2bcfa550e7b01b
59+
60+RUN curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \
61+ && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
62+ && tar -xzf wordpress.tar.gz -C /usr/src/ \
63+ && rm wordpress.tar.gz \
64+ && chown -R www-data:www-data /usr/src/wordpress \
65+ && rm -rf /var/www/html \
66+ && mv /usr/src/wordpress /var/www/html
67+
68+COPY --chown=www-data:www-data ./plugins/ /var/www/html/wp-content/plugins/
69+COPY --chown=www-data:www-data ./themes/ /var/www/html/wp-content/themes/
70+
71+EXPOSE 80
72+CMD apachectl -D FOREGROUND
73diff --git a/Makefile b/Makefile
74new file mode 100644
75index 0000000..14a5b83
76--- /dev/null
77+++ b/Makefile
78@@ -0,0 +1,27 @@
79+build: lint deps
80+ @echo "Fetching plugins and themes."
81+ @tox -e fetch
82+ @echo "Building the image."
83+ @docker build . -t wordpress
84+
85+deps:
86+ @echo "Checking dependencies are present"
87+ which bzr || sudo apt-get install -y bzr
88+ which git || sudo apt-get install -y git
89+
90+lint: clean
91+ @echo "Normalising python layout with black."
92+ @tox -e black
93+ @echo "Running flake8"
94+ @tox -e lint
95+
96+clean:
97+ @echo "Cleaning files"
98+ @rm -rf ./.tox
99+ @rm -rf ./.pytest_cache
100+ @rm -rf ./plugins/*
101+ @rm -rf ./themes/*
102+ @mkdir -p plugins
103+ @mkdir -p themes
104+
105+.PHONY: build lint clean
106diff --git a/fetcher.py b/fetcher.py
107new file mode 100755
108index 0000000..2fe005c
109--- /dev/null
110+++ b/fetcher.py
111@@ -0,0 +1,136 @@
112+#!/usr/bin/env python3
113+
114+import os
115+import shutil
116+import subprocess
117+import urllib.request
118+import zipfile
119+
120+
121+zip_plugins_to_get = {
122+ # please keep these in alphabetical order
123+ '404page',
124+ 'all-in-one-event-calendar',
125+ 'coschedule-by-todaymade',
126+ 'elementor',
127+ 'essential-addons-for-elementor-lite',
128+ 'favicon-by-realfavicongenerator',
129+ 'feedwordpress',
130+ 'fruitful-shortcodes',
131+ 'genesis-columns-advanced',
132+ 'line-break-shortcode',
133+ 'no-category-base-wpml',
134+ 'openid',
135+ 'post-grid',
136+ 'powerpress',
137+ 'redirection',
138+ 'relative-image-urls',
139+ 'rel-publisher',
140+ 'safe-svg',
141+ 'show-current-template',
142+ 'simple-301-redirects',
143+ 'simple-custom-css',
144+ 'social-media-buttons-toolbar',
145+ 'so-widgets-bundle',
146+ 'svg-support',
147+ 'syntaxhighlighter',
148+ 'wordpress-importer',
149+ 'wordpress-seo',
150+ 'wp-font-awesome',
151+ 'wp-lightbox-2',
152+ 'wp-markdown',
153+ 'wp-mastodon-share',
154+ 'wp-polls',
155+ 'wp-statistics',
156+}
157+
158+branch_plugins_to_get = {
159+ # please keep these in alphabetical order
160+ 'launchpad-integration': {'url': 'lp:wordpress-launchpad-integration'},
161+ 'openstack-objectstorage': {'url': 'lp:~canonical-sysadmins/wordpress/openstack-objectstorage'},
162+ 'teams-integration': {'url': 'lp:wordpress-teams-integration'},
163+ 'xubuntu-team-members': {'url': 'lp:~canonical-sysadmins/wordpress/wp-plugin-xubuntu-team-members'},
164+}
165+
166+branch_themes_to_get = {
167+ # please keep these in alphabetical order
168+ 'fruitful': {'url': 'https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-fruitful'},
169+ 'light-wordpress-theme': {'url': 'lp:ubuntu-community-webthemes/light-wordpress-theme'},
170+ 'mscom': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-mscom'},
171+ 'twentyeleven': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-twentyeleven'},
172+ 'ubuntu-cloud-website': {'url': 'lp:ubuntu-cloud-website'},
173+ 'ubuntu-community': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-community'},
174+ 'ubuntu-community-wordpress-theme': {'url': 'lp:ubuntu-community-wordpress-theme'},
175+ 'ubuntu-fi-new': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-fi'},
176+ 'ubuntu-light': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-light'},
177+ 'ubuntustudio-wp': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntustudio-wp'},
178+ 'wordpress_launchpad': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-launchpad'},
179+ 'xubuntu-theme': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-xubuntu-website'},
180+}
181+
182+
183+def get_plugins(zip_plugins, branch_plugins):
184+ total_zips = len(zip_plugins)
185+ current_zip = 0
186+ for zip_plugin in zip_plugins:
187+ current_zip = current_zip + 1
188+ print('Downloading zipped plugin {} of {}...'.format(current_zip, total_zips), end="\r")
189+ url = 'https://downloads.wordpress.org/plugin/{}.latest-stable.zip'.format(zip_plugin)
190+ file_name = os.path.join(os.getcwd(), 'plugins', os.path.basename(url))
191+ with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
192+ shutil.copyfileobj(response, out_file)
193+ with zipfile.ZipFile(file_name, 'r') as zip_ref:
194+ zip_ref.extractall(os.path.join(os.getcwd(), 'plugins'))
195+ os.remove(file_name)
196+ print()
197+
198+ total_branches = len(branch_plugins)
199+ current_branch = 0
200+ for branch_plugin in branch_plugins:
201+ current_branch = current_branch + 1
202+ print('Downloading branched plugin {} of {}...'.format(current_branch, total_branches), end="\r")
203+ url = branch_plugins[branch_plugin].get('url')
204+ basename = os.path.basename(url)
205+ if basename.startswith('lp:'):
206+ basename = basename[3:]
207+ if basename.startswith('wp-plugin-'):
208+ basename = basename[10:]
209+ dest = os.path.join(os.getcwd(), 'plugins/', basename)
210+ if url.startswith('lp:'):
211+ cmd = ['bzr', 'branch', url, dest]
212+ elif url.startswith('https://git'):
213+ cmd = ['git', 'clone', url, dest]
214+ else:
215+ print("ERROR: Don't know how to clone {}".format(url))
216+ exit(1)
217+ _ = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.PIPE)
218+ print()
219+
220+
221+def get_themes(branch_themes):
222+ total_branches = len(branch_themes)
223+ current_branch = 0
224+ for branch_theme in branch_themes:
225+ current_branch = current_branch + 1
226+ print('Downloading branched theme {} of {}...'.format(current_branch, total_branches), end="\r")
227+ url = branch_themes[branch_theme].get('url')
228+ basename = os.path.basename(url)
229+ if basename.startswith('lp:'):
230+ basename = basename[3:]
231+ if basename.startswith('wp-theme-'):
232+ basename = basename[9:]
233+ dest = os.path.join(os.getcwd(), 'themes/', basename)
234+ if url.startswith('lp:'):
235+ cmd = ['bzr', 'branch', url, dest]
236+ elif url.startswith('https://git'):
237+ cmd = ['git', 'clone', url, dest]
238+ else:
239+ print("ERROR: Don't know how to clone {}".format(url))
240+ exit(1)
241+ _ = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.PIPE)
242+ print()
243+
244+
245+if __name__ == '__main__':
246+ get_plugins(zip_plugins_to_get, branch_plugins_to_get)
247+ get_themes(branch_themes_to_get)
248diff --git a/tox.ini b/tox.ini
249new file mode 100644
250index 0000000..92befc4
251--- /dev/null
252+++ b/tox.ini
253@@ -0,0 +1,32 @@
254+[tox]
255+skipsdist=True
256+envlist = build
257+skip_missing_interpreters = True
258+
259+[testenv]
260+basepython = python3
261+setenv =
262+ PYTHONPATH = .
263+
264+[testenv:black]
265+commands = {envbindir}/black --skip-string-normalization --line-length=120 .
266+deps = black
267+
268+[testenv:lint]
269+commands = {envbindir}/flake8
270+deps = flake8
271+
272+[testenv:fetch]
273+commands = ./fetcher.py
274+setenv =
275+ BZR_HOME = /tmp
276+
277+[flake8]
278+exclude =
279+ .git,
280+ __pycache__,
281+ .tox,
282+ plugins/
283+ themes/
284+max-line-length = 120
285+max-complexity = 10

Subscribers

People subscribed via source and target branches

to all changes: