← Back to team overview

wordpress-charmers team mailing list archive

[Merge] ~mthaddon/charm-k8s-wordpress/+git/print-plugin-names:master into charm-k8s-wordpress:master

 

Tom Haddon has proposed merging ~mthaddon/charm-k8s-wordpress/+git/print-plugin-names:master into charm-k8s-wordpress:master.

Commit message:
Print the names of plugins as we download them



Requested reviews:
  Wordpress Charmers (wordpress-charmers)

For more details, see:
https://code.launchpad.net/~mthaddon/charm-k8s-wordpress/+git/print-plugin-names/+merge/377638

Print the names of plugins as we download them
-- 
Your team Wordpress Charmers is requested to review the proposed merge of ~mthaddon/charm-k8s-wordpress/+git/print-plugin-names:master into charm-k8s-wordpress:master.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e0f7f96
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+files/plugins/
+files/themes/
+.tox/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..a6bed91
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,56 @@
+FROM ubuntu:bionic
+
+ARG http_proxy
+ARG https_proxy
+
+# Avoid interactive prompts
+RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
+
+# Update all packages, remove cruft
+RUN apt-get update && apt-get -y dist-upgrade \
+    && apt-get --purge autoremove -y \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists/*
+
+# install and configure apache2 (--no-install-recommends as we don't need ssl-cert)
+ENV APACHE_CONFDIR=/etc/apache2
+ENV APACHE_ENVVARS=/etc/apache2/envvars
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends apache2 \
+    && rm -rf /var/lib/apt/lists/* \
+    && sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" \
+    && . "$APACHE_ENVVARS" \
+    && 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 \
+    && ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
+    && ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
+    && ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" \
+    && chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
+
+# Configure PHP
+COPY ./files/docker-php.conf $APACHE_CONFDIR/conf-available/docker-php.conf
+RUN a2enconf docker-php
+
+# Install PHP
+RUN apt-get update && apt-get install -y curl php libapache2-mod-php php-mysql php-gd \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists/*
+
+# mod_php requires us to use mpm_prefork
+RUN a2dismod mpm_event \
+    && a2enmod mpm_prefork
+
+# Install the main Wordpress code, this will be our only site so /var/www/html is fine
+RUN curl -o wordpress.tar.gz -fSL "https://wordpress.org/latest.tar.gz"; \
+    && tar -xzf wordpress.tar.gz -C /usr/src/ \
+    && rm wordpress.tar.gz \
+    && chown -R www-data:www-data /usr/src/wordpress \
+    && rm -rf /var/www/html \
+    && mv /usr/src/wordpress /var/www/html
+
+# Copy our collected themes and plugins into the appropriate paths
+COPY --chown=www-data:www-data ./files/plugins/ /var/www/html/wp-content/plugins/
+COPY --chown=www-data:www-data ./files/themes/ /var/www/html/wp-content/themes/
+
+# Port 80 only, TLS will terminate elsewhere
+EXPOSE 80
+CMD apachectl -D FOREGROUND
diff --git a/Makefile b/Makefile
index a46c2e2..cb2d8c6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+<<<<<<< Makefile
 lint:
 	@echo "Normalising python layout with black."
 	@tox -e black
@@ -11,13 +12,41 @@ test: lint unittest
 
 build: lint
 	charm build
+=======
+build: lint deps
+	@echo "Fetching plugins and themes."
+	@tox -e fetch
+	@echo "Building the image."
+	@docker build . -t wordpress:latest --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg HTTPS_PROXY=$(HTTPS_PROXY)
+	@echo "Pushing to the prod-is-external registry."
+	@docker tag wordpress:latest prod-is-external.docker-registry.canonical.com/wordpress:latest
+	@docker push prod-is-external.docker-registry.canonical.com/wordpress:latest
+
+deps:
+	@echo "Checking dependencies are present"
+	@command -v bzr >/dev/null 2>&1 || { echo "I require bzr but it's not installed. Aborting." >&2; exit 1; }
+	@command -v git >/dev/null 2>&1 || { echo "I require git but it's not installed. Aborting." >&2; exit 1; }
+
+lint: clean
+	@echo "Running flake8"
+	@tox -e lint
+>>>>>>> Makefile
 
 clean:
 	@echo "Cleaning files"
 	@rm -rf ./.tox
 	@rm -rf ./.pytest_cache
+<<<<<<< Makefile
 	@rm -rf ./tests/unit/__pycache__ ./reactive/__pycache__ ./lib/__pycache__
 	@rm -rf ./.coverage ./.unit-state.db
 
 
 .PHONY: lint test unittest build clean
+=======
+	@rm -rf ./files/plugins/*
+	@rm -rf ./files/themes/*
+	@mkdir -p ./files/plugins
+	@mkdir -p ./files/themes
+
+.PHONY: build lint clean
+>>>>>>> Makefile
diff --git a/fetcher.py b/fetcher.py
new file mode 100755
index 0000000..9f93073
--- /dev/null
+++ b/fetcher.py
@@ -0,0 +1,133 @@
+#!/usr/bin/env python3
+
+import os
+import shutil
+import subprocess
+import urllib.request
+import zipfile
+
+
+zip_plugins_to_get = {
+    # please keep these in alphabetical order
+    '404page',
+    'all-in-one-event-calendar',
+    'coschedule-by-todaymade',
+    'elementor',
+    'essential-addons-for-elementor-lite',
+    'favicon-by-realfavicongenerator',
+    'feedwordpress',
+    'fruitful-shortcodes',
+    'genesis-columns-advanced',
+    'line-break-shortcode',
+    'no-category-base-wpml',
+    'openid',
+    'post-grid',
+    'powerpress',
+    'redirection',
+    'relative-image-urls',
+    'rel-publisher',
+    'safe-svg',
+    'show-current-template',
+    'simple-301-redirects',
+    'simple-custom-css',
+    'social-media-buttons-toolbar',
+    'so-widgets-bundle',
+    'svg-support',
+    'syntaxhighlighter',
+    'wordpress-importer',
+    'wordpress-seo',
+    'wp-font-awesome',
+    'wp-lightbox-2',
+    'wp-markdown',
+    'wp-mastodon-share',
+    'wp-polls',
+    'wp-statistics',
+}
+
+branch_plugins_to_get = {
+    # please keep these in alphabetical order
+    'launchpad-integration': {'url': 'lp:wordpress-launchpad-integration'},
+    'openstack-objectstorage': {'url': 'lp:~canonical-sysadmins/wordpress/openstack-objectstorage'},
+    'teams-integration': {'url': 'lp:wordpress-teams-integration'},
+    'xubuntu-team-members': {'url': 'lp:~canonical-sysadmins/wordpress/wp-plugin-xubuntu-team-members'},
+}
+
+branch_themes_to_get = {
+    # please keep these in alphabetical order
+    'fruitful': {'url': 'https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-fruitful'},
+    'light-wordpress-theme': {'url': 'lp:ubuntu-community-webthemes/light-wordpress-theme'},
+    'mscom': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-mscom'},
+    'twentyeleven': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-twentyeleven'},
+    'ubuntu-cloud-website': {'url': 'lp:ubuntu-cloud-website'},
+    'ubuntu-community': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-community'},
+    'ubuntu-community-wordpress-theme': {'url': 'lp:ubuntu-community-wordpress-theme'},
+    'ubuntu-fi-new': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-fi'},
+    'ubuntu-light': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntu-light'},
+    'ubuntustudio-wp': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-ubuntustudio-wp'},
+    'wordpress_launchpad': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-launchpad'},
+    'xubuntu-theme': {'url': 'lp:~canonical-sysadmins/wordpress/wp-theme-xubuntu-website'},
+}
+
+
+def get_plugins(zip_plugins, branch_plugins):
+    total_zips = len(zip_plugins)
+    current_zip = 0
+    for zip_plugin in zip_plugins:
+        current_zip = current_zip + 1
+        print('Downloading {} of {} zipped plugins: {} ...'.format(current_zip, total_zips, zip_plugin))
+        url = 'https://downloads.wordpress.org/plugin/{}.latest-stable.zip'.format(zip_plugin)
+        file_name = os.path.join(os.getcwd(), 'files/plugins', os.path.basename(url))
+        with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
+            shutil.copyfileobj(response, out_file)
+        with zipfile.ZipFile(file_name, 'r') as zip_ref:
+            zip_ref.extractall(os.path.join(os.getcwd(), 'files/plugins'))
+        os.remove(file_name)
+
+    total_branches = len(branch_plugins)
+    current_branch = 0
+    for branch_plugin in branch_plugins:
+        current_branch = current_branch + 1
+        print('Downloading {} of {} branched plugins: {} ...'.format(current_branch, total_branches, branch_plugin))
+        url = branch_plugins[branch_plugin].get('url')
+        basename = os.path.basename(url)
+        if basename.startswith('lp:'):
+            basename = basename[3:]
+        if basename.startswith('wp-plugin-'):
+            basename = basename[10:]
+        dest = os.path.join(os.getcwd(), 'files/plugins', basename)
+        if url.startswith('lp:'):
+            cmd = ['bzr', 'branch', url, dest]
+        elif url.startswith('https://git'):
+            cmd = ['git', 'clone', url, dest]
+        else:
+            print("ERROR: Don't know how to clone {}".format(url))
+            exit(1)
+        _ = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.PIPE)
+
+
+def get_themes(branch_themes):
+    total_branches = len(branch_themes)
+    current_branch = 0
+    for branch_theme in branch_themes:
+        current_branch = current_branch + 1
+        print('Downloading branched theme {} of {}...'.format(current_branch, total_branches))
+        url = branch_themes[branch_theme].get('url')
+        basename = os.path.basename(url)
+        if basename.startswith('lp:'):
+            basename = basename[3:]
+        if basename.startswith('wp-theme-'):
+            basename = basename[9:]
+        dest = os.path.join(os.getcwd(), 'files/themes/', basename)
+        if url.startswith('lp:'):
+            cmd = ['bzr', 'branch', url, dest]
+        elif url.startswith('https://git'):
+            cmd = ['git', 'clone', url, dest]
+        else:
+            print("ERROR: Don't know how to clone {}".format(url))
+            exit(1)
+        _ = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.PIPE)
+
+
+if __name__ == '__main__':
+    get_plugins(zip_plugins_to_get, branch_plugins_to_get)
+    get_themes(branch_themes_to_get)
diff --git a/files/docker-php.conf b/files/docker-php.conf
new file mode 100644
index 0000000..af22747
--- /dev/null
+++ b/files/docker-php.conf
@@ -0,0 +1,11 @@
+<FilesMatch \.php$>
+	SetHandler application/x-httpd-php
+</FilesMatch>
+
+DirectoryIndex disabled
+DirectoryIndex index.php index.html
+
+<Directory /var/www/>
+	Options -Indexes
+	AllowOverride All
+</Directory>
diff --git a/tox.ini b/tox.ini
index 7b45934..4ae8148 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,10 @@
 [tox]
 skipsdist=True
+<<<<<<< tox.ini
 envlist = unit, functional
+=======
+envlist = build
+>>>>>>> tox.ini
 skip_missing_interpreters = True
 
 [testenv]
@@ -8,6 +12,7 @@ basepython = python3
 setenv =
   PYTHONPATH = .
 
+<<<<<<< tox.ini
 [testenv:unit]
 commands =
     pytest --ignore {toxinidir}/tests/functional \
@@ -36,10 +41,30 @@ deps = black
 commands = flake8
 deps = flake8
 
+=======
+[testenv:black]
+commands = {envbindir}/black --skip-string-normalization --line-length=120 .
+deps = black
+
+[testenv:lint]
+commands = {envbindir}/flake8
+deps = flake8
+
+[testenv:fetch]
+commands = ./fetcher.py
+passenv = HTTP_PROXY HTTPS_PROXY
+setenv =
+  BZR_HOME = /tmp
+
+>>>>>>> tox.ini
 [flake8]
 exclude =
     .git,
     __pycache__,
     .tox,
+<<<<<<< tox.ini
+=======
+    files/
+>>>>>>> tox.ini
 max-line-length = 120
 max-complexity = 10