Deploying WordPress to OpenShift

TIP

Before any of the commands are executed, you will need to sign in to OpenShift by copying your login command and logging in via the terminal

Updating Build Configs

Changes to the build configs are required when ever an update to a base image is changed. This means anytime the WordPress core, MariaDB, Nginx or other base images need to be updated.

  • Ensure all base images are updated in the build configsopen in new window.
  • Sync these changes to OpenShift using the oc apply -k command to ensure the buildconfig's are up to date and ensure you change the namespace to your namespace.
# update the namespace to your namespace
oc apply -k ./deployments/kustomize/image-builds --namespace='123456-tools'

WARNING

Currently there isn't any automation that deploys these changes to OpenShift, which requires a manual process to sync the image buildconfig's to your tools namespace.

Building Images

Once image buildconfig's have been updated, these images will need to be re-build, and then deployed.

  • for all image updates you will need to re-build the image, usually this will be just be the core WordPress, and this will be the example we use.
  • Once an image is created, it will add the dev tag, as determined by the buildconfig file.

Building Images VIA OpenShift Application

  • Sign in to the OpenShift web application
  • Choose your projects tools namespace, and go to 123456-tools project
  • Go to the Builds - BuildConfigs sidebar menu
  • choose the BuildConfig wordpress-wordpress-run and right mouse click on three horizontal dots to the right, then click Start build

openShiftBuild

Building Images VIA OC command

# update the namespace to your namespace
oc start-build --namespace='123456-tools' wordpress-wordpress-run

Promoting the Images to test and prod namespaces.

  • Once the image has been created, the dev tag automatically gets assigned.
  • Any deployments in the dev namespace should automatically re-deploy
  • Test a WordPress site in the dev instance to ensure it was successful in updating
  • Take notes if the Network databases need to be updated, as this will be indicated by a message in the WordPress admin.
  • Once confirmation of the new image deployment has been done, then promoted to test and prod
  • promote the image to test.
# update the namespace to your namespace
oc tag --namespace='123456-tools' wordpress-wordpress-run:dev wordpress-wordpress-run:test
  • follow same checks as you did with the dev namespace
  • promote image to production (only if instructed to do so)
# update the namespace to your namespace
oc tag --namespace='123456-tools' wordpress-wordpress-run:dev wordpress-wordpress-run:prod
  • follow same checks as you did with the dev namespace

Deploying Plugins / Themes

The plugins and themes requires a Kubernetes Job to be run to update the plugins and themes directories. A composer.json manifest file is used as part of the deployment which deploys the respective plugins and themes to that namespace, and therefor this file might be in a tenant repository.

  • update the composer.json file to the correct versions and dependencies
  • run the oc apply -k command
oc apply -k --namespace='123456-dev' ./deployments/kustomize/base/plugins_themes
  • if an overlay is created, then run a similar command using a kustomize overlay file and composer.json file.
oc apply -k --namespace='123456-dev' ./wordpress/kustomize/overlays/dev/plugins_themes

Sample plugins/themes kustomize overlay file

# tenant repo
# ./wordpress/kustomize/overlays/dev/plugins_themes
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- github.com/bcgov/wordpress/deployments/base/plugins_themes
# Update to your license plate in the dev|test|prod namespace.
namespace: 123456-dev
images:
  - name: wordpress-plugins-themes-run
    newName: image-registry.openshift-image-registry.svc:5000/123456-tools/wordpress-plugins-themes-run
    newTag: dev
configMapGenerator:
- name: wordpress-plugins-themes-config
  behavior: replace
  files:
  - composer.json

Sample composer.json file

{
    "name": "wordpress-plugins-themes/base",
    "type": "project",
    "license": "MIT",
    "description": "Plugin and theme installer for WordPress",
    "repositories": [
        {
          "type": "composer",
          "url": "https://wpackagist.org",
          "only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
        },
        {
          "type": "composer",
          "url": "https://blog.gov.bc.ca/satis/"
        }
      ],
    "require": {
        "wpackagist-plugin/advanced-custom-fields": "^6.2",
        "wpackagist-plugin/custom-post-type-ui": "^1.17",
        "wpackagist-theme/twentytwentythree": "^1",
        "bcgov-theme/bcgov-wordpress-block-theme": "dev-development"
    },
    "config": {
      "php": "8.3",
      "allow-plugins": {
        "composer/installers": true
      }
    }
}

TIP

The plugins and themes deployment should be included into a tenant repo in order to account for different deployment considerations for each environment.

Deploy WordPress

WordPress deployments need to be setup using ArgoCD and Vault Secrets.

Base Image versions

TIP

The version of the images below reflect the versions of the actual buildconfig's. ./deployments/kustomize/image-builds

Nginx Base Image

wordpress-nginx-run - The base image used for the nginx container. Nginx web server, used to serve WordPress / PHP

          name: nginx:1.26.2

WordPress Base Image

wordpress-wordpress-run - The base image used for the wordpress container

        name: wordpress:6.7.1-php8.3-fpm-alpine

MariaDB Base Image

wordpress-mariadb-run - MariaDB version that gets build in base-images via Dockerfile. Dependent on the Alpine versionopen in new window

          name: alpine:3.20.3

Sidecar Base Image

wordpress-sidecar-run - The base image used for the sidecar image

        name: ubuntu:22.04

Plugin/Themes Base Image

wordpress-plugins-themes-run - The base image used for the plugins/themes image

        name: php:8.3

WARNING

OpenShift template deployments are deprecated Use of the OpenShift templates including image builds and deployments will be deprecated in favour of using Kustomize deployments. Refer to OpenShift Template Deploymentopen in new window

Resources

Contributors: Shawn