Wordpress

In this example, we'll deploy Wordpress tool with its MariaDB database.

1. Create shared variables

Go to "Environment variables" menu and create this variable.

  • MY_WORDPRESS_DB_PASSWORD (don't forget to check the "hide value" box)

2. Create Wordpress and MariaDB services

Classic environment
services:
  - id: mywp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        healthCheck:
          healthCheckEnabled: true
        loadBalancerRules:
          - publicPort: 443
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
    volumes:
      - name: wpcontent
        path: /var/www/html/wp-content
  - id: mydb
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
Kubernetes environment
services:
  - id: mywp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        loadBalancerRules:
          - publicPort: 443
    healthCheck:
      enabled: true
      path: "/"
      port: 80
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
    volumes:
      - name: wpcontent
        path: /var/www/html/wp-content
  - id: mydb
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
In this example, we create both services with a single import, but you can import them in several steps.

Here is the section allowing communication between services:

links:
  - toServiceId: mydb
    toServicePort: 3306
    variableHost: MY_DB_HOST
    variablePort: MY_DB_PORT
    variableAddress: MY_DB_ADDRESS

This block instructs LayerOps that our WordPress service should be able to communicate with another service with id "mydb" on port 3306. In addition to creating the link, this block is used to inject environment variables into our wordpress service:

  • MY_DB_HOST: will contains the host to access service mydb (example: 127.0.0.1)
  • MY_DB_PORT: will contains the port to access service mydb (example: 9000)
  • MY_DB_ADDRESS: will contains the address to access service mydb (example: 127.0.0.1:9000)

Then, to indicate which address our Wordpress should use to communicate with the database, we add the WORDPRESS_DB_HOST environment variable.

environmentVariables:
  - key: WORDPRESS_DB_HOST
    value: "%MY_DB_ADDRESS%"
Check WORDPRESS_DB_HOST and other environment variables documentation

3. Use SideTasks for backups

This configuration is just an example, you will probably want to create your own backup container and processes.
Rclone is used is these examples, with Scaleway Provider You can use your favorite provider available with Rclone.

3.1 Backup & Auto-restore persistent volume

Here's an example of how containers can be used in SideTasks to perform external backups to S3 storage. LayerOps provides an example image that compresses a folder and sends it to an S3 account. registry.nimeops.net/layerops-public/marketplace/backup-volumes

YOU MUST create a persistent volume, which will be backuped

volumes:
  - name: wpcontent
    path: /var/www/html/wp-content

In this example, we'll use the Scaleway provider

First, we need to create shared Environment Variables:

  • MY_BACKUP_S3_ACCESS_KEY (don't forget to check the "hide value" box)
  • MY_BACKUP_S3_SECRET_KEY (don't forget to check the "hide value" box)

then, we can add to the service definition, environment Variables:

environmentVariables:
(... existing variables ...)
  - key: BACKUP_SERVICE_NAME
    value: "WORDPRESS_APP" # give name you want
  - key: BACKUP_SOURCES
    value: "/var/www/html/wp-content" # path to backup, the same as persistent volume path
  - key: BACKUP_S3_BUCKET
    value: "poc-layerops" # S3 Bucket Name
  - key: BACKUP_S3_PATH
    value: "DEMO_BACKUP_VOLUME" # S3 sub path
  - key: BACKUP_S3_PROVIDER
    value: "Scaleway" # specify cloud provider
  - key: BACKUP_S3_ENDPOINT
    value: "s3.fr-par.scw.cloud" # cloud provider endpoint
  - key: BACKUP_S3_REGION
    value: "fr-par" # cloud provider region
  - key: BACKUP_S3_ACCESS_KEY
    value: "%MY_BACKUP_S3_ACCESS_KEY%" # shared Environment Variables created before
  - key: BACKUP_S3_SECRET_KEY
    value: "%MY_BACKUP_S3_SECRET_KEY%" # shared Environment Variables created before
  - key: BACKUP_CRON_PERIOD
    value: "0 * * * *" # Cron syntax -> every hour at x:00
  - key: BACKUP_COMPRESSION 
    value: "targz" # compression type
  - key: BACKUP_RETENTION
    value: "7" # in days

Add sideTasks to the service:

Classic environment
sideTasks:
  - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
      image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
      imageVersion: 2.0.0
      command:
        - /usr/local/bin/restore
    type: preStart
    isLongLived: false
  - dockerConfiguration: # Backup - run as cron after main service launched, with $BACKUP_CRON_PERIOD definition
      image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
      imageVersion: 2.0.0
    type: postStart
    isLongLived: true
Kubernetes environment
sideTasks:
  - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
      image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
      imageVersion: 2.0.0
      command: 
        - /entrypoint.sh
      args:
        - /usr/local/bin/restore
    type: preStart
    isLongLived: false
  - dockerConfiguration: # Backup - run as cron after main service launched, with $BACKUP_CRON_PERIOD definition
      image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
      imageVersion: 2.0.0
    type: postStart
    isLongLived: true

Below full service definition:

Classic environment
services:
  - id: mywp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        healthCheck:
          healthCheckEnabled: true
        loadBalancerRules:
          - publicPort: 443
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_APP" # give name you want
      - key: BACKUP_SOURCES
        value: "/var/www/html/wp-content" # path to backup, the same as persistant volume path
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops" # S3 Bucket Name
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME" # S3 sub path
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway" # specify cloud provider
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud" # cloud provider endpoint
      - key: BACKUP_S3_REGION
        value: "fr-par" # cloud provider region
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%" # shared Environment Variables created before
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%" # shared Environment Variables created before
      - key: BACKUP_CRON_PERIOD
        value: "0 * * * *" # Cron syntax -> every hour at x:00
      - key: BACKUP_COMPRESSION 
        value: "targz" # compression type
      - key: BACKUP_RETENTION
        value: "7" # in days
    volumes:
      - name: wpcontent
        path: /var/www/html/wp-content
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists or not, in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
          command:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
      - dockerConfiguration: # Backup - run as cron after main service launched, with $BACKUP_CRON_PERIOD definition
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
        type: postStart
        isLongLived: true
Kubernetes environment
services:
  - id: mywp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        loadBalancerRules:
          - publicPort: 443
    healthCheck:
      enabled: true
      path: "/"
      port: 80
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_APP" # give name you want
      - key: BACKUP_SOURCES
        value: "/var/www/html/wp-content" # path to backup, the same as persistant volume path
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops" # S3 Bucket Name
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME" # S3 sub path
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway" # specify cloud provider
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud" # cloud provider endpoint
      - key: BACKUP_S3_REGION
        value: "fr-par" # cloud provider region
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%" # shared Environment Variables created before
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%" # shared Environment Variables created before
      - key: BACKUP_CRON_PERIOD
        value: "0 * * * *" # Cron syntax -> every hour at x:00
      - key: BACKUP_COMPRESSION 
        value: "targz" # compression type
      - key: BACKUP_RETENTION
        value: "7" # in days
    volumes:
      - name: wpcontent
        path: /var/www/html/wp-content
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists or not, in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
          command:
            - /entrypoint.sh
          args:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
      - dockerConfiguration: # Backup - run as cron after main service launched, with $BACKUP_CRON_PERIOD definition
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
        type: postStart
        isLongLived: true

3.2 Auto-restore Mariadb Database from last backup

Here's an example of how containers can be used in SideTasks to perform external backups to S3 storage. LayerOps provides an example image that compresses a folder and sends it to an S3 account. registry.nimeops.net/layerops-public/marketplace/backup-sql

Always with Scaleway provider, so we'll use the same credentials in shared Environment Variables:

  • MY_BACKUP_S3_ACCESS_KEY (don't forget to check the "hide value" box)
  • MY_BACKUP_S3_SECRET_KEY (don't forget to check the "hide value" box)

Variables used with backup-sql service

  • BACKUP_S3_PROVIDER : must be a S3 provider supported by rclone's S3 storage provider plugin (see https://rclone.org/s3/ )- example: Scaleway
  • BACKUP_S3_ENDPOINT: the S3 remote endpoint url - example s3.fr-par.scw.cloud
  • BACKUP_S3_BUCKET: the S3 bucket name - example: my-backup-bucket
  • BACKUP_S3_PATH (optionnal): the S3 subdirectory inside the bucket - example: nextcloud
  • BACKUP_S3_REGION: the S3 remote region - example: fr-par
  • BACKUP_S3_ACCESS_KEY (sensitive)
  • BACKUP_S3_SECRET_KEY (sensitive)
  • BACKUP_ENCRYPT_KEY (optionnal): if set, the backup will be encrypted using the given encrypt key

  • BACKUP_REMOTE_DIR (optionnal): if set, Remote dir name (default to sql)
  • BACKUP_RETENTION (optionnal): if set, Backup retention in days (default to 7)
  • BACKUP_COMPRESSION (optionnal): if set, Compression type: zstd (default) and targz
  • BACKUP_RESTORE_DATE (optionnal): if set, specify the date ie 2022_12_26_142528 (for 2022_12_26_142528_var_www_titi.tar.gz)
  • BACKUP_SERVICE_NAME (optionnal): if set, specify the service Name (default mysql)
  • BACKUP_LOCAL_RESTORE_DIR (optionnal): if set to yes, only restore dump file in /docker-entrypoint-initdb.d

YOU MUST create a persistent volume /docker-entrypoint-initdb.d, which will be backuped

volumes:
  - name: mariadb_initdb
    path: /docker-entrypoint-initdb.d

add environment Variables in service:

environmentVariables:
(... existing variables ...)
  - key: BACKUP_SERVICE_NAME
    value: "WORDPRESS_DB"     
  - key: BACKUP_S3_BUCKET
    value: "poc-layerops"
  - key: BACKUP_S3_PATH
    value: "DEMO_BACKUP_VOLUME"
  - key: BACKUP_S3_PROVIDER
    value: "Scaleway"
  - key: BACKUP_S3_ENDPOINT
    value: "s3.fr-par.scw.cloud"
  - key: BACKUP_S3_REGION
    value: "fr-par"
  - key: BACKUP_S3_ACCESS_KEY
    value: "%MY_BACKUP_S3_ACCESS_KEY%"
  - key: BACKUP_S3_SECRET_KEY
    value: "%MY_BACKUP_S3_SECRET_KEY%"
  - key: BACKUP_COMPRESSION
    value: "targz"
  - key: BACKUP_RETENTION
    value: "1"
  - key: BACKUP_LOCAL_RESTORE_DIR
    value: "yes"
  - key: MYSQL_RANDOM_ROOT_PASSWORD
    value: "yes"
  - key: MYSQL_USER
    value: "wp"
  - key: MYSQL_PASSWORD
    value: "%MY_WORDPRESS_DB_PASSWORD%"
  - key: MYSQL_DATABASE
    value: "wp"
  - key: DB_NAMES # used by backup-sql container
    value: "%MYSQL_USER%" 
  - key: DB_USER # used by backup-sql container
    value: "%MYSQL_USER%" 
  - key: DB_PASSWORD # used by backup-sql container
    value: "%MYSQL_PASSWORD%"
  - key: DB_HOST # used by backup-sql container -> linked service
    value: "127.0.0.1"

Add sideTasks to the service:

Classic environment
sideTasks:
  - dockerConfiguration: # Restore
      image: registry.nimeops.net/layerops-public/marketplace/backup-sql
      imageVersion: 2.0.0
      command:
        - /usr/local/bin/restore
    type: preStart
    isLongLived: false
Kubernetes environment
sideTasks:
  - dockerConfiguration: # Restore
      image: registry.nimeops.net/layerops-public/marketplace/backup-sql
      imageVersion: 2.0.0
      command: 
        - /entrypoint.sh
      args:
        - /usr/local/bin/restore
    type: preStart
    isLongLived: false

Below full service definition:

Classic environment
services:
  - id: mydb
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "1"
      - key: BACKUP_LOCAL_RESTORE_DIR # restore locally, in /docker-entrypoint-initdb.d mounted as persistent volume
        value: "yes"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MY_WORDPRESS_DB_PASSWORD%" 
      - key: DB_HOST # used by backup-sql container -> linked service
        value: "127.0.0.1"
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-sql
          imageVersion: 2.0.0
          command:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
    volumes:
      - name: mariadb-initdb
        path: /docker-entrypoint-initdb.d
Kubernetes environment
services:
  - id: mydb
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: DB_HOST # used by backup-sql container -> linked service
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "1"
      - key: BACKUP_LOCAL_RESTORE_DIR # restore locally, in /docker-entrypoint-initdb.d mounted as persistent volume
        value: "yes"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MY_WORDPRESS_DB_PASSWORD%" 
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-sql
          imageVersion: 2.0.0
          command: 
            - /entrypoint.sh
          args:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
    volumes:
      - name: mariadb-initdb
        path: /docker-entrypoint-initdb.d

3.3 Full YAML services (Wordpress + MariaDB + SideTasks Backup container ) example

Classic environment
services:
  - id: mywp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        healthCheck:
         healthCheckEnabled: true
        loadBalancerRules:
          - publicPort: 443
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_APP" # give name you want
      - key: BACKUP_SOURCES
        value: "/var/www/html/wp-content" # path to backup, the same as persistant volume path
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops" # S3 Bucket Name
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME" # S3 sub path
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway" # specify cloud provider
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud" # cloud provider endpoint
      - key: BACKUP_S3_REGION
        value: "fr-par" # cloud provider region
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%" # shared Environment Variables created before
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%" # shared Environment Variables created before
      - key: BACKUP_CRON_PERIOD
        value: "0 * * * *" # Cron syntax -> every hour at x:00
      - key: BACKUP_COMPRESSION 
        value: "targz" # compression type
      - key: BACKUP_RETENTION
        value: "7" # in days
    volumes:
      - name: wpcontent
        path: /var/www/html/wp-content
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
          command:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
      - dockerConfiguration: # Backup - run as cron after main service launched, with $BACKUP_CRON_PERIOD definition
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
        type: postStart
        isLongLived: true   
  - id: mydb
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "1"
      - key: BACKUP_LOCAL_RESTORE_DIR # restore locally, in /docker-entrypoint-initdb.d
        value: "yes"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: DB_HOST # used by backup-sql container -> linked service
        value: "127.0.0.1"
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-sql
          imageVersion: 2.0.0
          command:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
    volumes:
      - name: mariadb-initdb
        path: /docker-entrypoint-initdb.d
Kubernetes environment
services:
  - id: mywp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        loadBalancerRules:
          - publicPort: 443
    healthCheck:
      enabled: true
      path: "/"
      port: 80
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_APP" # give name you want
      - key: BACKUP_SOURCES
        value: "/var/www/html/wp-content" # path to backup, the same as persistant volume path
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops" # S3 Bucket Name
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME" # S3 sub path
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway" # specify cloud provider
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud" # cloud provider endpoint
      - key: BACKUP_S3_REGION
        value: "fr-par" # cloud provider region
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%" # shared Environment Variables created before
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%" # shared Environment Variables created before
      - key: BACKUP_CRON_PERIOD
        value: "0 * * * *" # Cron syntax -> every hour at x:00
      - key: BACKUP_COMPRESSION 
        value: "targz" # compression type
      - key: BACKUP_RETENTION
        value: "7" # in days
    volumes:
      - name: wpcontent
        path: /var/www/html/wp-content
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
          command: 
            - /entrypoint.sh
          args:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
      - dockerConfiguration: # Backup - run as cron after main service launched, with $BACKUP_CRON_PERIOD definition
          image: registry.nimeops.net/layerops-public/marketplace/backup-volumes
          imageVersion: 2.0.0
        type: postStart
        isLongLived: true   
  - id: mydb
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
    links:
      - toServiceId: mydb
        toServicePort: 3306
        variableHost: DB_HOST # used by backup-sql container -> linked service
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "1"
      - key: BACKUP_LOCAL_RESTORE_DIR # restore locally, in /docker-entrypoint-initdb.d
        value: "yes"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MYSQL_PASSWORD%"
    sideTasks:
      - dockerConfiguration: # Restore - check before main service launched, if data exists in $BACKUP_SOURCES vars
          image: registry.nimeops.net/layerops-public/marketplace/backup-sql
          imageVersion: 2.0.0
          command: 
            - /entrypoint.sh
          args:
            - /usr/local/bin/restore
        type: preStart
        isLongLived: false
    volumes:
      - name: mariadb-initdb
        path: /docker-entrypoint-initdb.d

4. Use Cron function for backups / restore jobs

4.1 Create backup mysqldump job (cron and manal run)

Classic environment
services:
  - id: backupmywp
    name: Backup-myWP
    dockerConfiguration:
      image: registry.nimeops.net/layerops-public/marketplace/backup-sql
      imageVersion: 2.0.0
    countMin: 1
    countMax: 1
    cronExpression: "@daily"
    cronAllowOverlap: false
    cpuLimit: 512 # MHz 
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        localExposedPort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: BACKUP_LOCAL_RESTORE_DIR
        value: "no"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "7"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MYSQL_PASSWORD%" 
      - key: DB_HOST # used by backup-sql container -> linked service
        value: "%MY_DB_HOST%"
      - key: DB_PORT # used by backup-sql container -> linked service
        value: "%MY_DB_PORT%"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
Kubernetes environment
services:
  - id: backupmywp
    name: Backup-myWP
    dockerConfiguration:
      image: registry.nimeops.net/layerops-public/marketplace/backup-sql
      imageVersion: 2.0.0
    countMin: 1
    countMax: 1
    cronExpression: "@daily"
    cronAllowOverlap: false
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        localExposedPort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: BACKUP_LOCAL_RESTORE_DIR
        value: "no"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "7"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MYSQL_PASSWORD%" 
      - key: DB_HOST # used by backup-sql container -> linked service
        value: "%MY_DB_HOST%"
      - key: DB_PORT # used by backup-sql container -> linked service
        value: "%MY_DB_PORT%"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"

4.2 Create restore mysqldump job (manual run)

This job, which is imported stopped (isPaused: true), will have to be triggered manually. It will check that the database is empty, and if so, will import it by retrieving the backup from S3.

Classic environment
services:
  - id: restoremywp
    name: Restore-myWP
    dockerConfiguration:
      image: registry.nimeops.net/layerops-public/marketplace/backup-sql
      command:
        - /usr/local/bin/restore
      imageVersion: 2.0.0
    countMin: 1
    countMax: 1
    cronExpression: "* * * * *"
    cronAllowOverlap: false
    isPaused: true
    cpuLimit: 512 # MHz
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        localExposedPort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: BACKUP_LOCAL_RESTORE_DIR
        value: "no"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "7"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MYSQL_PASSWORD%" 
      - key: DB_HOST # used by backup-sql container -> linked service
        value: "%MY_DB_HOST%"
      - key: DB_PORT # used by backup-sql container -> linked service
        value: "%MY_DB_PORT%"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
Kubernetes environment
services:
  - id: restoremywp
    name: Restore-myWP
    dockerConfiguration:
      image: registry.nimeops.net/layerops-public/marketplace/backup-sql
      command: 
        - /entrypoint.sh
      args:
        - /usr/local/bin/restore
      imageVersion: 2.0.0
    countMin: 1
    countMax: 1
    cronExpression: "* * * * *"
    cronAllowOverlap: false
    isPaused: true
    cpuLimit: 1000 # = 1 CPU
    memoryLimitMiB: 512
    links:
      - toServiceId: mydb
        toServicePort: 3306
        localExposedPort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_BACKUP_S3_ACCESS_KEY
      - MY_BACKUP_S3_SECRET_KEY
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: BACKUP_LOCAL_RESTORE_DIR
        value: "no"
      - key: BACKUP_SERVICE_NAME
        value: "WORDPRESS_DB"     
      - key: BACKUP_S3_BUCKET
        value: "poc-layerops"
      - key: BACKUP_S3_PATH
        value: "DEMO_BACKUP_VOLUME"
      - key: BACKUP_S3_PROVIDER
        value: "Scaleway"
      - key: BACKUP_S3_ENDPOINT
        value: "s3.fr-par.scw.cloud"
      - key: BACKUP_S3_REGION
        value: "fr-par"
      - key: BACKUP_S3_ACCESS_KEY
        value: "%MY_BACKUP_S3_ACCESS_KEY%"
      - key: BACKUP_S3_SECRET_KEY
        value: "%MY_BACKUP_S3_SECRET_KEY%"
      - key: BACKUP_COMPRESSION
        value: "targz"
      - key: BACKUP_RETENTION
        value: "7"
      - key: DB_NAMES # used by backup-sql container
        value: "%MYSQL_DATABASE%" 
      - key: DB_USER # used by backup-sql container
        value: "%MYSQL_USER%" 
      - key: DB_PASSWORD # used by backup-sql container
        value: "%MYSQL_PASSWORD%" 
      - key: DB_HOST # used by backup-sql container -> linked service
        value: "%MY_DB_HOST%"
      - key: DB_PORT # used by backup-sql container -> linked service
        value: "%MY_DB_PORT%"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"