This tutorial shows how to deploy a scalable WordPress site in the IBM Code Engine.
Prereqs
-
IBM Cloud account
-
ibmcloud cli utility
-
mysql cli utility
-
docker cli utility
Objectives
-
Create an instance of IBM Cloud Databases for MySQL.
-
Create a custom Wordpress Container Image in IBM Container registry
-
Create a Code Engine Project and deploy the WordPress site
Create an instance of IBM Cloud Databases for MySQL.
-
Log in to IBM Cloud
-
Navigate to the catalog, search for “Databases for MySQL” and click on the service to open its details page.
-
Configure your MySQL instance:
- Provide a name for your MySQL instance.
- Choose the region and resource group where you want to create the instance.
- Select the Resource Allocation plan that suits your needs
- Set the database version to 8.0
- Set the Endpoint Type to Both Public and Private endpoints”.
- Optionally configure the encryption.
-
Review your configuration settings and click on the "Create" button to initiate the creation of your MySQL instance.
-
The deployment process may take some time. Wait for the instance to be provisioned.
-
Once the instance is provisioned, from the Resource list page , you can open to the instance to find further details on how to access your MySQL database, including connection strings, credentials.
-
Navigate to the overview page of the mysql instance and from the Endpoints section download the ca certificate for connection.
-
Next navigate to the Service credentials page for the mysql instance, and create a new credential. Once created, capture the following details.
host:port
|
5c86f6bd-f2fd-4968-aca8-46b0bfb6295d.c0v4phir0ah9ul9trho0.private.databases.appdomain.cloud:32409
|
username
|
someusername
|
password
|
somepassword
|
-
From the Overview page , again under the Endpoints section, in CLI tab, use the command to login to mysql and create the database for Wordpress
# Example:
MYSQL_PWD=<password> mysql \
--host=5c86f6bd-f2fd-4968-aca8-46b0bfb6295d.c0v4phir0ah9ul9trho0.private.databases.appdomain.cloud \
--port=32409 --user=<username> --ssl-mode=VERIFY_IDENTITY --ssl-ca=286a39f3-e1b8-4381-a83b-08ca9153eae0 ibmclouddb
mysql> CREATE DATABASE WORDPRESS;
Create a custom Wordpress Container Image in IBM Container registry
-
Create a local folder as a docker workspace
-
Copy the ca certificate file to this folder.
-
Create the Dockerfile in the same folder as follows
FROM wordpress:latest
COPY <ca-certificate-file> /usr/local/share/ca-certificates/icd-mysql.crt # eg : COPY 286a39f3-e1b8-4381-a83b-08ca9153eae0 /usr/local/share/ca-certificates/icd-mysql.crt
RUN cat /usr/local/share/ca-certificates/icd-mysql.crt >> /etc/ssl/certs/ca-certificates.crt
-
Log in to ibm cloud from you command-line follow the instructions to log into ibm container registry.
$ ibmcloud login --apikey "${APIKEY}"
# Target a resource group and region : ibmcloud target -g RESOURCE_GROUP -r REGION
$ ibmcloud target -g priyank -r ca-tor
# Install IBM Container Registry plugin
$ ibmcloud plugin install container-registry -r 'IBM Cloud'
# Target the correct IBM Cloud Container Registry region: ibmcloud cr region-set REGION
$ ibmcloud cr region-set ca-tor
# Create a namespace : ibmcloud cr namespace-add <my_namespace>
$ ibmcloud cr namespace-add priyank
# Log your local Docker daemon into the IBM Cloud Container Registry.
ibmcloud cr login
-
Build the Docker container and push to ICR
# build the docker image tagged in the format "<region>.icr.io/<my_namespace>/<my_repository>:<my_tag>"
$ docker build -t ca.icr.io/priyank/wordpress:latest .
# push the image to icr
$ docker push ca.icr.io/priyank/wordpress:latest
Create a Code Engine Project and deploy the WordPress site
-
Navigate to Code Engine Projects on IBM Cloud Web Console - https://cloud.ibm.com/codeengine/overview
-
Click “Create” to create a new project in the appropriate region.
-
Navigate to the “Applications” tab
-
Click the “Create” button
-
Provide the name for the application
-
Choose container Image for Code and Click on Configure Image button to select the previously pushed image to ICR.
-
Choose the Instance resources configuration and auto scaling configurations
-
Configure the Environment variables as follows based on the database connection details captured earlier:
WORDPRESS_DB_HOST
|
5c86f6bd-f2fd-4968-aca8-46b0bfb6295d.c0v4phir0ah9ul9trho0.private.databases.appdomain.cloud:32409
|
WORDPRESS_DB_USER
|
someuser
|
WORDPRESS_DB_PASSWORD
|
somepassword
|
WORDPRESS_DB_NAME
|
WORDPRESS
|
WORDPRESS_CONFIG_EXTRA
|
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
|
-
In the Image start options, configure the Listening port to port 80.
-
Click Create.
-
Once the application is deployed and healthy, optionally to setup custom domain, navigate to the Domain Mappings tab,
-
Under the “Custom domain mappings” Click create and follow the instructions to setup your own domain to point to the hosted wordpress.
-
Finally navigate to the custom domain or the FQDN showed in the “public” property of “Custom domain mappings”. The Wordpress site will be up and running.