Examples
Dockerfile based app
This example shows how to deploy the popular open-source CMS Strapi. It utilizes these areas of infrastructure:
- hosting an app built from Dockerfile
- database (PostgreSQL)
- storage (dedicated bucket for Strapi to keep media files)
Configuration principles:
- build an app from a Docker file
- automatically create SSL certificates
- configure dependencies (database and storage)
- use Gatsby-friendly routing
The whole configuration is in three files in the root folder of your project:
- dev.outblocks.yaml - environment configuration (environment-specific variables)
- project.outblocks.yaml - project configuration (global project configuration)
- app.outblocks.yaml - application configuration (app-specific configuration)
Setting up secrets
Strapi requires two variables that should stay secret, and you should not keep them in your code:
- ADMIN_JWT_SECRET
- API_TOKEN_SALT
- APP_KEYS
To set them use CLI secrets command:
ok secret set admin_jwt_secret <string>
ok secret set api_token_salt <string>
ok secret set app_keys <string>
Now you can reference them using the adequate string in a config file. You can use them in app configuration (app.outblocks.yaml), y setting up variables that are going to be visible during the image-building process:
env:
  ADMIN_JWT_SECRET: ${secret.jwt_secret}
  API_TOKEN_SALT: ${secret.api_token_salt}
  APP_KEYS: ${secret.strapi_app_keys}
  ...
Environment variables
dev.outblocks.yaml:
base_url: my-strapi-project.com
gcp_project: my_strapi_project
gcp_region: europe-west3
strapi_database: postgres
Project config
project.outblocks.yaml:
# Project config.
# You can use ${var.*} expansion to source it from values.yaml per environment,
# e.g. domain: ${var.base_url}
# Name of the project.
name: my_strapi_project
# State - where project state will be stored.
state:
  type: gcp
# Main base domain for apps - loaded from values.yaml for easy override per environment.
dns:
  - domains:
      - '*.${var.base_url}'
      - ${var.base_url}
# Project dependencies.
dependencies:
  database:
    type: postgresql
    name: strapi
    database: strapi
  media:
    type: storage
    name: strapi-media-bucket-${env}
    location: eu
# Plugins that will be used for running, deployment etc.
plugins:
  - name: gcp
    version: ^0.1.62
    project: ${var.gcp_project}
    region: ${var.gcp_region}
  - name: docker
    version: ^0.1.16
# Default settings and plugins used for applications.
defaults:
  run:
    plugin: docker
  deploy:
    plugin: gcp
Static app config
app.outblocks.yaml:
name: strapi
type: service
url: ${var.base_url}
deploy:
  memory_limit: 512
  min_scale: 1
container:
  port: 3333
env:
  DATABASE_HOST: '%{dep.database.host}'
  DATABASE_USERNAME: '%{dep.database.user}'
  DATABASE_PASSWORD: '%{dep.database.password}'
  DATABASE_NAME: '%{dep.database.database}'
  DATABASE_CLIENT: postgres
  DATABASE_PORT: '5432'
  WEB_HOST: https://www.${var.base_url}
  GOOGLE_MEDIA_BUCKET_NAME: '%{dep.media.name}'
  GOOGLE_MEDIA_BUCKET_URL: '%{dep.media.url}'
  # Secrets
  ADMIN_JWT_SECRET: ${secret.jwt_secret}
  API_TOKEN_SALT: ${secret.api_token_salt}
  APP_KEYS: ${secret.strapi_app_keys}
needs:
  database:
    user: my_strapi-${env}
    database: strapi
  media: {}
build:
  dockerfile: Dockerfile
run:
  command: yarn develop
Dockerfile
FROM strapi/strapi
WORKDIR /strapi
COPY ./package.json ./
COPY ./yarn.lock ./
RUN yarn config set network-timeout 300000
RUN yarn install
COPY . .
ENV NODE_ENV production
RUN yarn build
EXPOSE 1337
CMD ["sh", "-c", "./start.sh"]