Silta examples
#
silta.yml configuration examplesThe default values are documented here:
- Drupal chart: https://github.com/wunderio/charts/blob/master/drupal/values.yaml
- Frontend chart: https://github.com/wunderio/charts/blob/master/frontend/values.yaml
- Simple chart: https://github.com/wunderio/charts/blob/master/simple/values.yaml
Below is a list of examples for common needs.
All examples are meant to be used in the silta.yml
file of your project. Most of the examples work with both drupal chart and frontend chart, unless name is explicitly mentioned above the code snippet. Double-check with default value files for each chart - drupal and frontend.
Also note that increasing resources will result in increased costs, so use sensible values.
#
Allocate more storage for your database.Drupal chart:
Note that storage can only be increased, not decreased.
Note 2: If you change it for existing deployment, You'll need to run special comands in cluster to expand the storage or deployment will fail (see Mariadb or Elasticsearch running out of disk space in troubleshooting page).
#
Using different version of MariaDB than provided in chart defaults.While it's normally not advised, it's possible to adjust MariaDB image version -
Drupal chart and Frontend chart:
It's highly suggested to create mysql data backup before image change.
Note: Do not change image to an earlier version, it may break the data.
#
Mount Drupal public files to a different locationDrupal chart:
#
Enabling private files for drupalThere is a pre-built mount template for drupal private file storage in silta (check values.yaml), you just have to enable it
Drupal chart:
Enabling this will mount shared storage to /app/private
and set $settings['file_private_path']
accordingly. See chart values for override parameters.
#
Change how often the standard Drupal cron is executedDrupal chart:
#
Deploy a custom service using frontend chartWhile Frontend chart was originally meant to host NodeJS frontend projects, it also allows running custom docker images and optionally exposing them via nginx reverse proxy. These containers are called "services" in Frontend chart.
In this example, we are setting up two custom services - "mynodeservice" that will use a custom built image (see circleci configuration below) and "mongo" that will use prebuilt mongodb docker imageservice.
Note: This ".Values.services.mongo" service is not the same as ".Values.mongodb", it's just an example.
Frontend chart:
See .Values.serviceDefaults
for service default values.
Service images are built at .circleci/config.yaml
:
It is very important to understand kubernetes containers are stateless, the moment container gets restarted, it will reset the storage to contents of docker image. To persist some particular filesystem path, you need to define persistent storage at .Values.mounts
and attach it to the service (this only applies to containers defined at .Values.services
since other applications (.Values.mongodb
, .Values.mariadb
, etc.) have default configurations in chart that persist data).
In this example, we are setting up a custom "mongo" service that will use prebuilt mongodb docker imageservice.
Note: This ".Values.services.mongo" service is not the same as ".Values.mongodb", it's just an example.
Frontend chart:
storageClassName
is only available on GKE. AWS and other cloud providers have different storageclasses, so it depends on cloud provider. There are several options and they differ by access (read / write) speed.standard
is a safe choice.accessModes
depends on storageClass.standard
on GKE providesReadWriteOnce
. See https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes for more information.Values.services.mongo.strategy.type: Recreate
is required for "read write once" type storage mounts, because they only allow mounting storage once, but default strategy for services isRollingUpdate
and it would fail deployment. See https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy for more information.
#
Run a custom cron jobDrupal chart:
Frontend chart:
#
Add additional environment variablesDrupal chart:
Frontend chart:
#
Change basic auth username and passwordDrupal chart and Frontend chart:
#
Enable elasticsearchDrupal chart and Frontend chart:
#
Using plugins with ElasticsearchCreate a custom elasticsearch dockerfile to silta/elasticsearch.Dockerfile:
Build the custom Elasticsearch image in CircleCI:
When using silta/drupal-build-deploy
:
When using silta/frontend-build-deploy
:
Use the custom elasticsearch image in your silta helm charts file:
The container URL could be found in the CircleCI container build information.
#
Enable memcachedDrupal chart:
Adjust resources and arguments as needed
Modify settings.php file (example is from D9)
For D7 use
#
Using varnishDrupal chart:
If extra cookies are needed, they can be defined in a vcl_extra_cookies variable:
When varnish is enabled in silta config, drupal configuration needs to be adjusted, so purge can find the varnish server.
Using varnish module:
You should consider using purge module instead No adjustments needed
Using varnish_purge module:
- Add varnish purger to purge settings.
- Find purger configuration name. You can see it by hovering over the configuration link (i.e.
1b619ba479
). This will be Your<PURGER_ID>
. - Put this snippet into your
settings.php
file:
Make sure to replace <PURGER_ID>
with an actual id of purger configuration!
Changing varnish default control-key value
This can be done by adding secret
variable.
Please remember: best practice is to encrypt secrets.
Changing varnish cache backend
The current default cache backend is set to file storage. The setting is exposed in values file and can be changed. Here are few examples:
#
Using RedisBy default, redis service does not set max memory value. You can do it by setting flags:
#
Skip taking reference data dumps on each deploymentDrupal chart:
For some sites with a lot of files, taking a reference data dump after each deployment can cause the builds to time out. Disabling updateAfterDeployment
means new environments will be created with reference data from the previous nightly dump.
#
Sending e-mailNote: There is no e-mail handling for frontend chart. You must implement the smtp workflow via application.
If you just want to test email, you can use mailhog:
Drupal chart:
Mailhog access information will be printed in release notes.
For emails to be actually sent out of the cluster, you can use any external smtp server. Here's an example for sparkpost.
Drupal chart:
Note: To get the sparkpost API key, you have to validate your domain first.
Note 2: Because of long-standing bugs in the ssmtp package, the smtp password cannot contain the special characters #
, =
or :
.
If the smtp
is configured and enabled, but it does not appear to send anything, make sure mailhog
is not enabled.
#
Domain names and SSL certificatesAll environments are given a hostname by default. It is possible to attach a custom domain name to environment by configuring exposeDomains
configuration parameter. All hostnames attached to environment are printed in release notes.
You can also use letsencrypt-staging
issuer to avoid hitting letsencrypt
rate limits.
!NB Deploy exposeDomains
entries only when DNS entries are changed or are soon to be changed. Otherwise, Letsencrypt validation might eventually get stuck due to retries.
!NB Put exposeDomains
in a dedicated configuration yaml file, so only one environment (branch) would be assigned this hostname. Having multiple environments with the same domain will act as a round robin load balancer for all environments and unexpected responses might be returned.
Drupal chart and Frontend chart:
key
value is certificates private key.
crt
value is full chain of certificate.
ca
value is not required anymore for exposed domains.
See more information on how to convert and prepare SSL certificate for exposed domains
If you have same SSL certificate for multiple domains You can reuse ssl
block.
You don't need a custom static ip (via gce ingress) normally, but if Your project requires, here's how -
#
Add redirectsRedirects can be relative to current domain or contain full domain for more targeted redirects when multiple external domains (exposeDomains
) are attached to deployment, and you only need this redirect for a specific URL.
If you are scattering the redirect rules into separate yaml's, use keys (or the latter yaml will overwrite the whole nginx.redirects
object) and the alphabetical order of keys will be respected in the nginx redirect map. Because of this, it's better to put everything in one file without keys, just descriptions and the order of the yaml will be respected.
Each redirect has from
and to
keys, and an optional description
key, which does not do anything currently, it's a documentation comment for configuration maintainer.
from
#
By default, strings are matched using case-insensitive exact matching.
Regular expressions can be used by prefixing the value with ~
for a case-sensitive matching, or with ~*
for case-insensitive matching. Regular expressions can contain named and positional captures that can be referenced in the to
value.
Make sure to use proper anchors (^
and $
) and character escaping in regular expressions, to get exactly the match you want and nothing extra.
- Bad example:
from: '~/old-page
matches any string containing/old-page
, e.g./anypath/old-page
or/old-page/anypath
or even/valid/path?/old-page
. - Good example:
from: ~^/old-page/.+\.html
matches specifically path/old-page/*.html
.
to
#
Can include references to captured values from regular expressions, and special nginx variables like $request_uri
or $query_string
.
Drupal chart and Frontend chart:
#
Allowing cross-namespace / cross-deployment connectionsResources in Silta charts are protected by Calico NetworkPolicy rules. Rules are defined in helm .Values.silta-release.ingressAccess
configuration object. There are few default rules that deny access to all pods in deployment from other deployments, but it is also possible to add extra [NetworkPolicy rules] (https://projectcalico.docs.tigera.io/security/policy-rules) to selecively allow access to deployment resources.
Here are few examples:
- Allowing access to pods from another namespace:
- Allow direct elasticsearch access from frontend namespace
- Allow CIDR access to service (routed connection only, does not work with NAT'ted connections)
#
Add custom include files for nginxDrupal chart builds nginx container using web/ folder as build context. This prevents files being included from outside the web folder and it's not a good idea to put config files under it.
To be able to add include files the build context needs to be changed from web/
into .
by passing nginx_build_context: "."
to drupal-docker-build
in .circleci/config.yml
:
Due root containing Drupal / shell container compatible .dockerignore file and for frontend there is a separate one inside the web/ folder this doesn't work anymore. Since version 19.03 Docker supports separate .dockerignore files for each Dockerfile. This requires Docker build to be made with BuildKit enabled. To enable BuildKit just pass the DOCKER_BUILDKIT=1
to the build environment as an environment variable:
The ignore file itself needs to be named the same as the Dockerfile with .dockerignore appended to the end and need to reside at the same place as the Dockerfile:
Note: our validation checks if the .dockerignore is present under web/ so you can either leave it there or just add an empty file in it's place.
To make the image to build correctly in this new context you need to update the COPY command in the nginx.Dockerfile to copy web
instead of .
and also add COPY commands to any custom config files you want to be able to include:
Now you can include the config file in silta.yml like this:
or if you COPY
the file under /etc/nginx/conf.d
they will be included automatically without the need to add them to silta.yml configs.
#
Deploy sub-project from the same repo using simple chartHaving e.g. Storybook or other frontend application included in the base project codebase that require separate deployment can be easily done even using different chart. See https://wunderio.github.io/silta/docs/circleci-conf-examples for the deployment setup part.
When using different charts (e.g. drupal and simple) you need to separate chart specific configurations to their own silta-*.yml files if you want to share any configs between the application deployments (for example basic auth credentials). Best way to do it is to put only the shared configurations to the silta.yml file and have e.g. silta-cms.yml and silta-storybook.yml for application specific configurations.
#
Add custom subcharts to deployment- In
silta
folder, createextra_charts.yml
which contains list of subcharts to add.
Following examples add a redis subchart to drupal chart deployment.
To use a local subchart, replace repository link with file://<path>/<to>/<subchart>
- Add these 2 parameters to
drupal-build-deploy
CircleCI job:
- If desired, modify variables for the subchart in
silta.yml
under the key of subcharts' name. For example above, it'sredis
.
Sets redis password to test
Notice the condition
key in extra_charts.yml
for the redis subchart. It makes it possible to deploy this subchart conditionally, when redis: enabled
is passed in silta.yml
.
Delete the condition: redis.enabled
line if you want this subchart installed in all your future deployments, regardless of settings in silta.yml
.