Mattermost
In this example, we'll deploy the Mattermost tool with its PostgreSQL database.
In a second step, we will add the backup options
1. Create shared variables
Go to "Environment variables" menu and create 3 variables.
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD (don't forget to check the "hide value" box)
You can also create shared environment variables directly from the API:
curl -X 'POST' \
'https://api.layerops.com/v1/environments/c9eee4c7-1a31-471b-81f4-d7f128fe5a09/sharedVariables' \
-H 'accept: application/json' \
-H 'X-API-KEY: LYP7FBC7J8CMM68NYUPWSMYX3:8ee75797-7fa5-4f9f-9522-537dfd3e89b7' \
-H 'Content-Type: application/json' \
-d '{
"key": "POSTGRES_DB",
"value": "mattermost",
"isSensitive": false
}'
2. Create PostgreSQL service
Import this service:
services:
- id: postgres
name: postgres
dockerConfiguration:
image: postgres
imageVersion: 16.0-alpine3.18
countMin: 1
countMax: 1
ports:
- listeningPort: 5432
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
cooldownMinutes: 5
cpuLimit: 512 # MHz
cpuLimitHigh: 120
cpuLimitLow: 100
cpuDurationMinutes: 15
cpuWindowMinutes: 5
memoryLimitMiB: 512
memoryLimitHigh: 120
memoryLimitLow: 100
memoryDurationMinutes: 15
memoryWindowMinutes: 5
allocationQueuedMinutes: 2
This block is used to import previously created variables and inject them into the service:
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
3. Create Mattermost service
Import this service:
services:
- id: mattermost
name: mattermost
dockerConfiguration:
image: mattermost/mattermost-team-edition
imageVersion: latest
countMin: 1
countMax: 1
ports:
- listeningPort: 8065
loadBalancerRules:
- publicPort: 443
healthCheck:
healthCheckType: HTTP
healthCheckMethod: GET
healthCheckEnabled: true
healthCheckTimeoutSeconds: 30
healthCheckPath: /
healthCheckIntervalSeconds: 60
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
environmentVariables:
- key: TZ
value: UTC
- key: MM_SQLSETTINGS_DRIVERNAME
value: postgres
- key: MM_SQLSETTINGS_DATASOURCE
value: "postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@%POSTGRES_ADDR%/%POSTGRES_DB%?sslmode=disable&connect_timeout=10"
links:
- toServiceId: postgres
toServicePort: 5432
variableHost: POSTGRES_HOST
variablePort: POSTGRES_PORT
variableAddress: POSTGRES_ADDR
cooldownMinutes: 5
cpuLimit: 512 # MHz
cpuLimitHigh: 120
cpuLimitLow: 100
cpuDurationMinutes: 15
cpuWindowMinutes: 5
memoryLimitMiB: 512
memoryLimitHigh: 120
memoryLimitLow: 100
memoryDurationMinutes: 15
memoryWindowMinutes: 5
allocationQueuedMinutes: 2
We have added an environment variable which is made up of several other environment variables thanks to the %%
.
- key: MM_SQLSETTINGS_DATASOURCE
value: "postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@%POSTGRES_ADDR%/%POSTGRES_DB%?sslmode=disable&connect_timeout=10"
We want this service to have a public endpoint, so we've added the following block:
ports:
- listeningPort: 8065
loadBalancerRules:
- publicPort: 443
You can now access the URL that was automatically associated with port 8065.
4. Backup
In this example, we'll use scaleway's S3 to send backups, but this example is compatible with any S3.
Create shared variables
Go to "Environment variables" menu and create 3 variables.
- BACKUP_S3_ACCESS_KEY: get this info from your S3 provider
- BACKUP_S3_SECRET_KEY: get this info from your S3 provider (don't forget to check the "hide value" box)
- BACKUP_ENCRYPT_KEY: can be anything (don't forget to check the "hide value" box)
- BACKUP_S3_PROVIDER (Scaleway, AWS, ...)
- BACKUP_S3_ENDPOINT (e.g: s3.fr-par.scw.cloud for fr-par in Scaleway)
- BACKUP_S3_BUCKET (the name of your bucket)
- BACKUP_S3_REGION (e.g.: fr-par)
- BACKUP_S3_PATH (e.g.: backup)
Backup database
This job will be responsible for creating a backup of the database every hour and sending it to the configured S3.
services:
- id: backup
name: postgres-backup
dockerConfiguration:
image: registry.nimeops.net/layerops-public/marketplace/backup-sql
imageVersion: 2.0.0
countMin: 1
countMax: 1
environmentVariables:
- key: DB_ENGINE
value: postgres
- key: DB_HOST
value: "%POSTGRES_HOST%"
- key: DB_USER
value: "%POSTGRES_USER%"
- key: DB_PASSWORD
value: "%POSTGRES_PASSWORD%"
- key: DB_NAMES
value: "%POSTGRES_DB%"
- key: DB_PORT
value: "%POSTGRES_PORT%"
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
- BACKUP_S3_ACCESS_KEY
- BACKUP_S3_SECRET_KEY
- BACKUP_ENCRYPT_KEY
- BACKUP_S3_PROVIDER
- BACKUP_S3_ENDPOINT
- BACKUP_S3_BUCKET
- BACKUP_S3_REGION
- BACKUP_S3_PATH
links:
- toServiceId: postgres
toServicePort: 5432
variableHost: POSTGRES_HOST
variablePort: POSTGRES_PORT
variableAddress: POSTGRES_ADDR
cronExpression: 0 * * * *
cronAllowOverlap: false
cooldownMinutes: 5
cpuLimit: 512 # MHz
cpuLimitHigh: 120
cpuLimitLow: 100
cpuDurationMinutes: 15
cpuWindowMinutes: 5
memoryLimitMiB: 512
memoryLimitHigh: 120
memoryLimitLow: 100
memoryDurationMinutes: 15
memoryWindowMinutes: 5
allocationQueuedMinutes: 2
Restore database
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.
services:
- id: restore
name: restore-postgres
dockerConfiguration:
image: registry.nimeops.net/layerops-public/marketplace/backup-sql
imageVersion: 2.0.0
command:
- /usr/local/bin/restore
countMin: 1
countMax: 1
cronExpression: "* * * * *"
cronAllowOverlap: false
isPaused: true
cpuLimit: 512 # MHz
memoryLimitMiB: 512
environmentVariables:
- key: DB_ENGINE
value: postgres
- key: DB_HOST
value: "%POSTGRES_HOST%"
- key: DB_USER
value: "%POSTGRES_USER%"
- key: DB_PASSWORD
value: "%POSTGRES_PASSWORD%"
- key: DB_NAMES
value: "%POSTGRES_DB%"
- key: DB_PORT
value: "%POSTGRES_PORT%"
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
- BACKUP_S3_ACCESS_KEY
- BACKUP_S3_SECRET_KEY
- BACKUP_ENCRYPT_KEY
- BACKUP_S3_PROVIDER
- BACKUP_S3_ENDPOINT
- BACKUP_S3_BUCKET
- BACKUP_S3_REGION
- BACKUP_S3_PATH
links:
- toServiceId: postgres
toServicePort: 5432
variableHost: POSTGRES_HOST
variablePort: POSTGRES_PORT
variableAddress: POSTGRES_ADDR
Import all services at once
With the "import service" option, you can import several services at the same time. Here is the YML file used to create all services: Mattermost, Postgres and postgres backup.
services:
- id: mattermost
name: mattermost
dockerConfiguration:
image: mattermost/mattermost-team-edition
imageVersion: latest
countMin: 1
countMax: 1
ports:
- listeningPort: 8065
loadBalancerRules:
- publicPort: 443
healthCheck:
healthCheckType: HTTP
healthCheckMethod: GET
healthCheckEnabled: true
healthCheckTimeoutSeconds: 30
healthCheckPath: /
healthCheckIntervalSeconds: 60
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
- BACKUP_S3_ACCESS_KEY
- BACKUP_S3_SECRET_KEY
- BACKUP_ENCRYPT_KEY
- BACKUP_S3_PROVIDER
- BACKUP_S3_ENDPOINT
- BACKUP_S3_BUCKET
- BACKUP_S3_REGION
- BACKUP_S3_PATH
environmentVariables:
- key: TZ
value: UTC
- key: MM_SQLSETTINGS_DRIVERNAME
value: postgres
- key: MM_SQLSETTINGS_DATASOURCE
value: "postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@%POSTGRES_ADDR%/%POSTGRES_DB%?sslmode=disable&connect_timeout=10"
- key: DB_ENGINE
value: postgres
- key: DB_HOST
value: "%POSTGRES_HOST%"
- key: DB_PORT
value: "%POSTGRES_PORT%"
- key: DB_USER
value: "%POSTGRES_USER%"
- key: DB_PASSWORD
value: "%POSTGRES_PASSWORD%"
- key: DB_NAMES
value: "%POSTGRES_DB%"
links:
- toServiceId: postgres
toServicePort: 5432
variableHost: POSTGRES_HOST
variablePort: POSTGRES_PORT
variableAddress: POSTGRES_ADDR
cooldownMinutes: 5
cpuLimit: 512 # MHz
cpuLimitHigh: 120
cpuLimitLow: 100
cpuDurationMinutes: 15
cpuWindowMinutes: 5
memoryLimitMiB: 512
memoryLimitHigh: 120
memoryLimitLow: 100
memoryDurationMinutes: 15
memoryWindowMinutes: 5
allocationQueuedMinutes: 2
- id: postgres
name: postgres
dockerConfiguration:
image: postgres
imageVersion: 13-alpine
countMin: 1
countMax: 1
ports:
- listeningPort: 5432
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
cooldownMinutes: 5
cpuLimit: 512 # MHz
cpuLimitHigh: 120
cpuLimitLow: 100
cpuDurationMinutes: 15
cpuWindowMinutes: 5
memoryLimitMiB: 512
memoryLimitHigh: 120
memoryLimitLow: 100
memoryDurationMinutes: 15
memoryWindowMinutes: 5
allocationQueuedMinutes: 2
- id: backup
name: postgres-backup
dockerConfiguration:
image: registry.nimeops.net/layerops-public/marketplace/backup-sql
imageVersion: 2.0.0
countMin: 1
countMax: 1
environmentVariables:
- key: DB_ENGINE
value: postgres
- key: DB_HOST
value: "%POSTGRES_HOST%"
- key: DB_USER
value: "%POSTGRES_USER%"
- key: DB_PASSWORD
value: "%POSTGRES_PASSWORD%"
- key: DB_NAMES
value: "%POSTGRES_DB%"
- key: DB_PORT
value: "%POSTGRES_PORT%"
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
- BACKUP_S3_ACCESS_KEY
- BACKUP_S3_SECRET_KEY
- BACKUP_ENCRYPT_KEY
- BACKUP_S3_PROVIDER
- BACKUP_S3_ENDPOINT
- BACKUP_S3_BUCKET
- BACKUP_S3_REGION
- BACKUP_S3_PATH
links:
- toServiceId: postgres
toServicePort: 5432
variableHost: POSTGRES_HOST
variablePort: POSTGRES_PORT
variableAddress: POSTGRES_ADDR
cronExpression: 0 * * * *
cronAllowOverlap: false
cooldownMinutes: 5
cpuLimit: 512 # MHz
cpuLimitHigh: 120
cpuLimitLow: 100
cpuDurationMinutes: 15
cpuWindowMinutes: 5
memoryLimitMiB: 512
memoryLimitHigh: 120
memoryLimitLow: 100
memoryDurationMinutes: 15
memoryWindowMinutes: 5
allocationQueuedMinutes: 2
- id: restore
name: restore-postgres
dockerConfiguration:
image: registry.nimeops.net/layerops-public/marketplace/backup-sql
imageVersion: 2.0.0
command:
- /usr/local/bin/restore
countMin: 1
countMax: 1
cronExpression: "* * * * *"
cronAllowOverlap: false
isPaused: true
cpuLimit: 512 # MHz
memoryLimitMiB: 512
environmentVariables:
- key: DB_ENGINE
value: postgres
- key: DB_HOST
value: "%POSTGRES_HOST%"
- key: DB_USER
value: "%POSTGRES_USER%"
- key: DB_PASSWORD
value: "%POSTGRES_PASSWORD%"
- key: DB_NAMES
value: "%POSTGRES_DB%"
- key: DB_PORT
value: "%POSTGRES_PORT%"
sharedEnvironmentVariables:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
- BACKUP_S3_ACCESS_KEY
- BACKUP_S3_SECRET_KEY
- BACKUP_ENCRYPT_KEY
- BACKUP_S3_PROVIDER
- BACKUP_S3_ENDPOINT
- BACKUP_S3_BUCKET
- BACKUP_S3_REGION
- BACKUP_S3_PATH
links:
- toServiceId: postgres
toServicePort: 5432
variableHost: POSTGRES_HOST
variablePort: POSTGRES_PORT
variableAddress: POSTGRES_ADDR