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

Proposed by Barry Price
Status: Rejected
Rejected by: Barry Price
Proposed branch: ~barryprice/wordpress-k8s-image-builder/+git/wordpress-k8s-image-builder:master
Merge into: wordpress-k8s-image-builder:master
Diff against target: 283 lines (+253/-0)
5 files modified
.gitignore (+3/-0)
Dockerfile (+55/-0)
Makefile (+27/-0)
fetcher.py (+136/-0)
tox.ini (+32/-0)
Reviewer Review Type Date Requested Status
Barry Price Needs Resubmitting
Canonical IS Reviewers Pending
Review via email: mp+377431@code.launchpad.net

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.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

Some comments inline.

e0f49dc... by Barry Price

Always use the latest Wordpress, don't purge any packages for now

Revision history for this message
Barry Price (barryprice) wrote :

Retargetted to a new repository under the charm-k8s-wordpress project:

https://code.launchpad.net/~barryprice/charm-k8s-wordpress/+git/wordpress-k8s-image-builder/+merge/377498

review: Needs Resubmitting

Unmerged commits

e0f49dc... by Barry Price

Always use the latest Wordpress, don't purge any packages for now

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

Subscribers

People subscribed via source and target branches