Deploying WordPress Using the API
This tutorial demonstrates how to deploy the official WordPress Docker image to the Apcera Platform using the Apcera Docker API.
Prerequisites
The tutorial assumes that the cluster you are targeting has the MySQL and NFS providers registered with the system:
- MYSQL provider FQN:
/apcera/providers::mysql
- NFS provider FQN:
/apcera/providers::apcfs
To use the commands and requests as written, update all FQNs and UUIDs accordingly.
Instructions
Complete these instructions to install the official WordPress Docker image using the Apcera Docker API.
1. Install JQ.
This tutorial uses cURL to make API calls. To make the JSON response output easier to read, install the jq command-line JSON processor and include the | jq
suffix with your cURL commands.
To install jq on MacOS:
brew install jq
To install jq on Linux:
sudo apt-get install jq
2. Create APC_TOKEN envar.
Open the .apc
file and copy the entire Bearer <token>
string for the target cluster to the clipboard or a text file.
Create the variable:
export APC_TOKEN=”Bearer <token>”
3. Create request payloads.
Create the following three JSON files containing request payloads. Use http://jsonlint.com/ to validate the syntax.
mysql-srvc-binding.json
{
"job_fqn":"job::/sandbox/apcerauser::wordpress",
"name":"mysql-srvc-binding",
"service_fqn":"service::/sandbox/apcerauser::mysql-service"
}
mysql-srvc.json
{
"description":"MySQL DB service for WordPress",
"fqn":"service::/sandbox/apcerauser::mysql-service",
"name":"mysql-service",
"provider_fqn":"provider::/apcera/providers::mysql"
}
wordpress.json
{
"allow_egress":true,
"exposed_ports":[
80
],
"image_url":"https://registry-1.docker.io/library/wordpress:latest",
"job_fqn":"job::/sandbox/apcerauser::wordpress",
"resources":{
"cpu":0,
"disk":1073741824,
"memory":268435456,
"netmax":0,
"network":5000000
},
"restart_config":{
"maximum_attempts":0,
"restart_mode":"no"
},
"routes":{
"http://apcerauser.wordpress.kiso.io":80
},
"env":{
"WORDPRESS_DB_HOST": "{{ (binding_service \"mysql-service\").URI.Host }}:3306",
"WORDPRESS_DB_USER": "{{ (binding_service \"mysql-service\").URI.User }}",
"WORDPRESS_DB_PASSWORD": "{{ (binding_service \"mysql-service\").URI.Password }}",
"WORDPRESS_DB_NAME": "{{ (binding_service \"mysql-service\").URI.TrimmedPath }}"
},
"volume_provider_fqn":"provider::/apcera/providers::apcfs",
"start":false
}
4. Create mysql-service.
Request endpoint: POST /services
curl -X POST --data "@mysql-srvc.json" -H "Content-Type: application/json" -H "Authorization: $APC_TOKEN" "http://api.kiso.io/v1/services" | jq
Formatted response:
{
"uuid": "db1441c5-08b6-4d82-8df0-6a9745de6491",
"fqn": "service::/sandbox/apcerauser::mysql-service",
"provider_fqn": "provider::/apcera/providers::mysql",
"type": "mysql",
"name": "mysql-service",
"description": "MySQL DB service for WordPress",
"created_by": "apcerauser",
"created_at": "2016-08-13T17:25:36.810714322Z",
"status": "created",
"extended_status": {}
}
5. Verify mysql-service.
Request endpoint: GET /services
curl -X GET -H "Content-Type: application/json" -H "Authorization: $APC_TOKEN" "http://api.kiso.io/v1/services" | jq
Formatted response:
{
"uuid": "db1441c5-08b6-4d82-8df0-6a9745de6491",
"fqn": "service::/sandbox/apcerauser::mysql-service",
"provider_fqn": "provider::/apcera/providers::mysql",
"type": "mysql",
"name": "mysql-service",
"description": "MySQL DB service for WordPress",
"created_by": "apcerauser",
"created_at": "2016-08-13T17:25:36.810714322Z",
"status": "created",
"extended_status": {}
}
6. Deploy WordPress.
Request endpoint: POST /jobs/docker
curl -X POST --data "@wordpress.json" -H "Content-Type: application/json" -H "Authorization: $APC_TOKEN" "http://api.kiso.io/v1/jobs/docker" | jq
Formatted response:
{
"location": "http://api.kiso.io/v1/tasks/1b76a4c1-48ba-4f34-8ffd-6112dadf9511"
}
7. Verify wordpress job.
Request endpoint: GET /tasks/{UUID}
curl -X GET -H "Content-Type: application/json" -H "Authorization: $APC_TOKEN" "http://api.kiso.io/v1/tasks/1b76a4c1-48ba-4f34-8ffd-6112dadf9511" | jq
Formatted response:
{
"uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"time_started": 1471109536250584800,
"time_completed": 1471109546235307500,
"state": "complete",
"errored": "unerrored",
"events": [
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109536346545700,
"thread": "wordpress",
"stage": "Pulling Docker image",
"subtask": {
"name": "checking policy",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109536362714600,
"thread": "wordpress",
"stage": "Pulling Docker image",
"subtask": {
"name": "checking if package FQN is taken",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109536376204500,
"thread": "wordpress",
"stage": "Pulling Docker image",
"subtask": {
"name": "fetching image metadata",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109545257612300,
"thread": "wordpress",
"stage": "Pulling Docker image",
"subtask": {
"name": "creating package",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109545473513000,
"thread": "wordpress",
"stage": "Pulling Docker image",
"subtask": {
"name": "all layers downloaded",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109545498799900,
"thread": "wordpress",
"stage": "Creating job",
"subtask": {
"name": "",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109545667955000,
"thread": "wordpress",
"stage": "Configuring job",
"subtask": {
"name": "tagging package",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109545721002000,
"thread": "wordpress",
"stage": "Configuring job",
"subtask": {
"name": "provisioning volumes",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109546004576000,
"thread": "wordpress",
"stage": "Configuring job",
"subtask": {
"name": "volumes provisioned",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "event",
"time": 1471109546038583300,
"thread": "wordpress",
"stage": "Configuring job",
"subtask": {
"name": "adding egress binding",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
},
{
"task_uuid": "1b76a4c1-48ba-4f34-8ffd-6112dadf9511",
"task_event_type": "eos",
"time": 1471109546235309000,
"thread": "wordpress",
"stage": "",
"subtask": {
"name": "",
"index": 0,
"total": 0,
"progress": {
"current": 0,
"total": 0
}
},
"tags": null,
"payload": null
}
]
}
8. Create binding.
Request endpoint: POST /bindings
curl -X POST --data "@mysql-srvc-binding.json" -H "Content-Type: application/json" -H "Authorization: $APC_TOKEN" "http://api.kiso.io/v1/bindings" | jq
Formatted response:
{
"uuid": "8de96202-e408-4e84-8455-d2278efa5b4e",
"name": "mysql_srvc_binding",
"fqn": "binding::/::868e9f37-7972-4102-8785-459996940180",
"job_fqn": "job::/sandbox/apcerauser::wordpress",
"env_var": [
"JDBC_MYSQL_URI",
"MYSQL_SRVC_BINDING_URI",
"MYSQL_URI"
],
"service_fqn": "service::/sandbox/apcerauser::mysql-service"
}
9. Start the job.
To test the WordPress deployment, start the wordpress job using the web console or APC.
apc job start wordpress
10. Going further.
To apply what you learned:
- Get all available jobs using the
GET /jobs
endpoint. - Get the
wordpress
job object using theGET /jobs/{UUID}
endpoint. - Copy the response to a JSON file named
wordpress-update.json
. - Change the job state from "started" to "stopped."
- Update the job using the
PUT /jobs/{UUID}
endpoint.