diff --git a/.github/workflows/integration_test.yaml b/.github/workflows/integration_test.yaml index 045c4aa6..1188ad43 100644 --- a/.github/workflows/integration_test.yaml +++ b/.github/workflows/integration_test.yaml @@ -14,7 +14,7 @@ jobs: --openstack-rc=${GITHUB_WORKSPACE}/openrc --kube-config=${GITHUB_WORKSPACE}/kube-config --screenshot-dir=/tmp - modules: '["test_addon", "test_core", "test_ingress", "test_cos_grafana", "test_cos_loki", "test_cos_prometheus"]' + modules: '["test_addon", "test_core", "test_external", "test_ingress", "test_cos_grafana", "test_cos_loki", "test_cos_prometheus"]' pre-run-script: | -c "sudo microk8s enable hostpath-storage sudo microk8s kubectl -n kube-system rollout status -w deployment/hostpath-provisioner diff --git a/.gitignore b/.gitignore index f02053e7..95977754 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build .tox .coverage __pycache__ +**/*.rock diff --git a/src/charm.py b/src/charm.py index 34d9e988..321b5b82 100755 --- a/src/charm.py +++ b/src/charm.py @@ -62,8 +62,8 @@ class _ReplicaRelationNotReady(Exception): _WP_CONFIG_PATH = "/var/www/html/wp-config.php" _CONTAINER_NAME = "wordpress" _SERVICE_NAME = "wordpress" - _WORDPRESS_USER = "www-data" - _WORDPRESS_GROUP = "www-data" + _WORDPRESS_USER = "_daemon_" + _WORDPRESS_GROUP = "_daemon_" _WORDPRESS_DB_CHARSET = "utf8mb4" _DATABASE_RELATION_NAME = "database" diff --git a/wordpress.Dockerfile b/wordpress.Dockerfile deleted file mode 100644 index f8ada686..00000000 --- a/wordpress.Dockerfile +++ /dev/null @@ -1,141 +0,0 @@ -# Copyright 2023 Canonical Ltd. -# See LICENSE file for licensing details. -FROM ubuntu:20.04 - -ARG VERSION=5.9.3 -ENV APACHE_CONFDIR=/etc/apache2 -ENV APACHE_ENVVARS=/etc/apache2/envvars - -LABEL maintainer="wordpress-charmers@lists.launchpad.net" - -# Update all packages, remove cruft, install required packages, configure apache -RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \ - apt-get update \ - && apt-get --purge autoremove -y \ - && apt-get install -y apache2 \ - bzr \ - curl \ - git \ - libapache2-mod-php \ - libgmp-dev \ - php \ - php-curl \ - php-gd \ - php-gmp \ - php-mysql \ - php-symfony-yaml \ - php-xml \ - pwgen \ - python3 \ - python3-yaml \ - unzip && \ - 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 u=rwx,g=rx,o=rx "$dir"; \ - done && \ - 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 and apache2 - mod_php requires us to use mpm_prefork -COPY ./files/docker-php.conf $APACHE_CONFDIR/conf-available/docker-php.conf -COPY ./files/docker-php-swift-proxy.conf $APACHE_CONFDIR/conf-available/docker-php-swift-proxy.conf -# Configure apache 2 to enable /server-status endpoint -COPY ./files/apache2.conf $APACHE_CONFDIR/apache2.conf -# To allow logging to container and logfile -COPY ./files/000-default.conf $APACHE_CONFDIR/sites-available/000-default.conf - -RUN a2enconf docker-php && \ - a2dismod mpm_event && \ - a2enmod headers && \ - a2enmod mpm_prefork && \ - a2enmod proxy && \ - a2enmod proxy_http && \ - a2enmod rewrite && \ - a2enmod ssl - -RUN curl -sSOL https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \ - chmod +x wp-cli.phar && \ - mv wp-cli.phar /usr/local/bin/wp && \ - mkdir /var/www/.wp-cli && \ - chown www-data:www-data /var/www/.wp-cli - -RUN chown -R www-data:www-data /var/www/html - -USER www-data:www-data - -WORKDIR /var/www/html - -RUN wp core download --version=${VERSION} - -RUN set -e; \ - cd ./wp-content/plugins; \ - for plugin in \ - 404page \ - all-in-one-event-calendar \ - coschedule-by-todaymade \ - elementor \ - essential-addons-for-elementor-lite \ - favicon-by-realfavicongenerator \ - feedwordpress \ - genesis-columns-advanced \ - line-break-shortcode \ - no-category-base-wpml \ - post-grid \ - powerpress \ - redirection \ - relative-image-urls \ - rel-publisher \ - safe-svg \ - show-current-template \ - simple-301-redirects \ - simple-custom-css \ - so-widgets-bundle \ - svg-support \ - syntaxhighlighter \ - wordpress-importer \ - wp-font-awesome \ - wp-lightbox-2 \ - wp-markdown \ - wp-mastodon-share \ - wp-polls \ - wp-statistics ;\ - do \ - curl -sSL "https://downloads.wordpress.org/plugin/${plugin}.latest-stable.zip" -o "${plugin}.zip"; \ - unzip "${plugin}.zip"; \ - rm "${plugin}.zip"; \ - done; \ - curl -sSL "https://downloads.wordpress.org/plugin/openid.3.5.0.zip" -o "openid.zip"; \ - unzip "openid.zip"; \ - rm "openid.zip"; \ - # Latest YoastSEO does not support 5.9.3 version of WordPress. - curl -sSL "https://downloads.wordpress.org/plugin/wordpress-seo.18.9.zip" -o "wordpress-seo.zip"; \ - unzip "wordpress-seo.zip"; \ - rm "wordpress-seo.zip"; \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress-launchpad-integration/+git/wordpress-launchpad-integration wordpress-launchpad-integration; \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/openstack-objectstorage-k8s openstack-objectstorage-k8s; \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress-teams-integration/+git/wordpress-teams-integration wordpress-teams-integration; \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-plugin-xubuntu-team-members xubuntu-team-members; \ - rm -rf */.git - -RUN cd ./wp-content/themes && \ - git clone https://git.launchpad.net/~canonical-sysadmins/ubuntu-community-webthemes/+git/light-wordpress-theme light-wordpress-theme && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-mscom mscom && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-thematic thematic && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-twentyeleven twentyeleven && \ - git clone https://git.launchpad.net/~canonical-sysadmins/ubuntu-cloud-website/+git/ubuntu-cloud-website ubuntu-cloud-website && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntu-community ubuntu-community && \ - git clone https://git.launchpad.net/~canonical-sysadmins/ubuntu-community-wordpress-theme/+git/ubuntu-community-wordpress-theme ubuntu-community-wordpress-theme && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntu-fi ubuntu-fi && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntu-light ubuntu-light && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntustudio-wp ubuntustudio-wp && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-launchpad launchpad && \ - git clone https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-xubuntu-website xubuntu-website && \ - bzr branch lp:resource-centre && \ - rm -rf */.git - -EXPOSE 80 diff --git a/files/apache2.conf b/wordpress_rock/files/etc/apache2/apache2.conf similarity index 100% rename from files/apache2.conf rename to wordpress_rock/files/etc/apache2/apache2.conf diff --git a/files/docker-php-swift-proxy.conf b/wordpress_rock/files/etc/apache2/conf-available/docker-php-swift-proxy.conf similarity index 100% rename from files/docker-php-swift-proxy.conf rename to wordpress_rock/files/etc/apache2/conf-available/docker-php-swift-proxy.conf diff --git a/files/docker-php.conf b/wordpress_rock/files/etc/apache2/conf-available/docker-php.conf similarity index 100% rename from files/docker-php.conf rename to wordpress_rock/files/etc/apache2/conf-available/docker-php.conf diff --git a/files/000-default.conf b/wordpress_rock/files/etc/apache2/sites-available/000-default.conf similarity index 100% rename from files/000-default.conf rename to wordpress_rock/files/etc/apache2/sites-available/000-default.conf diff --git a/wordpress_rock/rockcraft.yaml b/wordpress_rock/rockcraft.yaml new file mode 100644 index 00000000..bac10b83 --- /dev/null +++ b/wordpress_rock/rockcraft.yaml @@ -0,0 +1,311 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. + +name: wordpress +summary: Wordpress rock +description: Wordpress OCI image for the Wordpress charm +base: ubuntu:20.04 +run-user: _daemon_ +license: Apache-2.0 +version: "1.0" +platforms: + amd64: +parts: + apache2: + plugin: dump + source: files + build-packages: + - apache2 + - php + - rsync + overlay-packages: + - apache2 + - libapache2-mod-php + - libgmp-dev + - php + - php-curl + - php-gd + - php-gmp + - php-mysql + - php-symfony-yaml + - php-xml + - pwgen + - python3 + - python3-yaml + - ca-certificates + build-environment: + # Required to source $CRAFT_OVERLAY/etc/apache2/envvars + - APACHE_CONFDIR: /etc/apache2 + - IMAGE_RUN_USER: _daemon_ + - IMAGE_RUN_GROUP: _daemon_ + - IMAGE_RUN_USER_ID: 584792 + - IMAGE_RUN_GROUP_ID: 584792 + overlay-script: | + craftctl default + sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' $CRAFT_OVERLAY/etc/apache2/envvars + sed -ri 's/\{APACHE_RUN_(USER|GROUP):=.+\}/\{APACHE_RUN_\1:=_daemon_\}/' $CRAFT_OVERLAY/etc/apache2/envvars + . $CRAFT_OVERLAY/etc/apache2/envvars + for dir in "$CRAFT_OVERLAY$APACHE_LOCK_DIR" "$CRAFT_OVERLAY$APACHE_RUN_DIR" "$CRAFT_OVERLAY$APACHE_LOG_DIR"; + do + rm -rvf "$dir"; + mkdir -p "$dir"; + chown "$IMAGE_RUN_USER_ID:$IMAGE_RUN_GROUP_ID" "$dir"; + chmod u=rwx,g=rx,o=rx "$dir"; + done + chown -R --no-dereference "$IMAGE_RUN_USER_ID:$IMAGE_RUN_GROUP_ID" "$CRAFT_OVERLAY$APACHE_LOG_DIR" + ln -sfT ../../../dev/stdout "$CRAFT_OVERLAY$APACHE_LOG_DIR/other_vhosts_access.log" + rsync -abP $CRAFT_PART_SRC/etc/apache2/ $CRAFT_OVERLAY/etc/apache2 + + # Enable apache2 modules + chroot $CRAFT_OVERLAY /bin/sh -x <<'EOF' + a2enconf docker-php + a2enmod headers + a2enmod mpm_prefork + a2enmod proxy + a2enmod proxy_http + a2enmod rewrite + a2enmod ssl + EOF + wordpress: + after: + - apache2 + plugin: nil + build-environment: + - WP_VERSION: 5.9.3 + build-packages: + - curl + override-build: | + curl -sSL --create-dirs https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -o wp + chmod +x wp + + mkdir -p wordpress_install_dir + (cd wordpress_install_dir; $CRAFT_PART_BUILD/wp core download --version=${WP_VERSION} --allow-root) + + cp -R . $CRAFT_PART_INSTALL + organize: + wordpress_install_dir: /var/www/html + wp: /usr/local/bin/wp + # Wordpress plugins + get-wordpress-plugins: + plugin: nil + after: + - wordpress + build-packages: + - curl + - unzip + build-environment: + - WP_PLUGINS: >- + 404page + all-in-one-event-calendar + coschedule-by-todaymade + elementor + essential-addons-for-elementor-lite + favicon-by-realfavicongenerator + feedwordpress + genesis-columns-advanced + line-break-shortcode + no-category-base-wpml + post-grid + powerpress + redirection + relative-image-urls + rel-publisher + safe-svg + show-current-template + simple-301-redirects + simple-custom-css + so-widgets-bundle + svg-support + syntaxhighlighter + wordpress-importer + wp-font-awesome + wp-lightbox-2 + wp-markdown + wp-mastodon-share + wp-polls + wp-statistics + override-build: | + for plugin in $WP_PLUGINS; + do + curl -sSL "https://downloads.wordpress.org/plugin/${plugin}.latest-stable.zip" -o "${plugin}.zip" + unzip -q "${plugin}.zip" + rm "${plugin}.zip" + done + curl -sSL "https://downloads.wordpress.org/plugin/openid.3.5.0.zip" -o "openid.zip" + unzip -q "openid.zip" + rm "openid.zip" + # Latest YoastSEO does not support 5.9.3 version of WordPress. + curl -sSL "https://downloads.wordpress.org/plugin/wordpress-seo.18.9.zip" -o "wordpress-seo.zip" + unzip -q "wordpress-seo.zip" + rm "wordpress-seo.zip" + cp -R . $CRAFT_PART_INSTALL + organize: + "*": /var/www/html/wp-content/plugins/ + ## Plugins fetched via git + get-wordpress-launchpad-integration: + after: + - get-wordpress-plugins + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress-launchpad-integration/+git/wordpress-launchpad-integration + source-type: git + organize: + "*": /var/www/html/wp-content/plugins/wordpress-launchpad-integration/ + get-wordpress-teams-integration: + after: + - get-wordpress-plugins + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress-teams-integration/+git/wordpress-teams-integration + source-type: git + organize: + "*": /var/www/html/wp-content/plugins/wordpress-teams-integration/ + get-openstack-objectstorage-k8s: + after: + - get-wordpress-plugins + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/openstack-objectstorage-k8s + source-type: git + organize: + "*": /var/www/html/wp-content/plugins/openstack-objectstorage-k8s/ + get-wp-plugin-xubuntu-team-members: + after: + - get-wordpress-plugins + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-plugin-xubuntu-team-members + source-type: git + organize: + "*": /var/www/html/wp-content/plugins/xubuntu-team-members/ + # Wordpress themes + get-light-wordpress-theme: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/ubuntu-community-webthemes/+git/light-wordpress-theme + source-type: git + organize: + "*": /var/www/html/wp-content/themes/light-wordpress-theme/ + get-wp-theme-mscom: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-mscom + source-type: git + organize: + "*": /var/www/html/wp-content/themes/mscom/ + get-wp-theme-thematic: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-thematic + source-type: git + organize: + "*": /var/www/html/wp-content/themes/thematic/ + get-wp-theme-twentyeleven: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-twentyeleven + source-type: git + organize: + "*": /var/www/html/wp-content/themes/twentyeleven/ + get-ubuntu-cloud-website: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/ubuntu-cloud-website/+git/ubuntu-cloud-website + source-type: git + organize: + "*": /var/www/html/wp-content/themes/ubuntu-cloud-website/ + get-wp-theme-ubuntu-community: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntu-community + source-type: git + organize: + "*": /var/www/html/wp-content/themes/ubuntu-community/ + get-ubuntu-community-wordpress-theme: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/ubuntu-community-wordpress-theme/+git/ubuntu-community-wordpress-theme + source-type: git + organize: + "*": /var/www/html/wp-content/themes/ubuntu-community-wordpress-theme/ + get-wp-theme-ubuntu-fi: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntu-fi + source-type: git + organize: + "*": /var/www/html/wp-content/themes/ubuntu-fi/ + get-wp-theme-ubuntu-light: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntu-light + source-type: git + organize: + "*": /var/www/html/wp-content/themes/ubuntu-light/ + get-wp-theme-ubuntustudio-wp: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-ubuntustudio-wp + source-type: git + organize: + "*": /var/www/html/wp-content/themes/ubuntustudio-wp/ + get-wp-theme-launchpad: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-launchpad + source-type: git + organize: + "*": /var/www/html/wp-content/themes/launchpad/ + get-wp-theme-xubuntu-website: + after: + - wordpress + plugin: dump + source: https://git.launchpad.net/~canonical-sysadmins/wordpress/+git/wp-theme-xubuntu-website + source-type: git + organize: + "*": /var/www/html/wp-content/themes/xubuntu-website/ + get-resource-centre: + after: + - wordpress + plugin: nil + build-packages: [bzr] + override-build: | + bzr branch lp:resource-centre + cp -R . $CRAFT_PART_INSTALL + organize: + resource-centre: /var/www/html/wp-content/themes/resource-centre/ + # Post-install configuration + wordpress-configure: + plugin: nil + after: + - get-wordpress-launchpad-integration + - get-wordpress-teams-integration + - get-openstack-objectstorage-k8s + - get-wp-plugin-xubuntu-team-members + - get-light-wordpress-theme + - get-wp-theme-mscom + - get-wp-theme-thematic + - get-wp-theme-twentyeleven + - get-ubuntu-cloud-website + - get-wp-theme-ubuntu-community + - get-wp-theme-ubuntu-fi + - get-wp-theme-ubuntu-light + - get-wp-theme-ubuntustudio-wp + - get-wp-theme-launchpad + - get-wp-theme-xubuntu-website + - get-resource-centre + - get-ubuntu-community-wordpress-theme + build-environment: + - IMAGE_RUN_USER_ID: 584792 + - IMAGE_RUN_GROUP_ID: 584792 + override-prime: | + craftctl default + rm -rf **/.git + chown $IMAGE_RUN_USER_ID:$IMAGE_RUN_GROUP_ID -R --no-dereference "$CRAFT_PRIME/var/www/html"