Live Demo:
Custom aliases in your
continuous delivery pipeline
19th November 2020
1 Internal Use
Slide 2
Slide 2 text
Housekeeping
● This webinar will be recorded; we will share the recording and
slide deck with all registrants shortly -- keep an eye on your
inbox!
● Please add your questions in the Q&A box, we will answer
them after the presentation during the Q&A session at the end
● To get in touch, get in touch on Twitter @contentful or write to
us at [email protected]
Before we dive in...
Slide 3
Slide 3 text
Introductions
Shy Ruparel
Developer Evangelist
at Contentful
Janko Marklein
Software Engineer
at Contentful
Slide 4
Slide 4 text
This has a personal and a technical side.
Let’s discuss the technical one!
4
Slide 5
Slide 5 text
● Ship small changes
● Deploy constantly
● Rollback quickly if things break
5
DevOps practices
Slide 6
Slide 6 text
To not be afraid of
these practices, we need
the right tooling
Slide 7
Slide 7 text
Two parts of the
deployment process make
things especially difficult
7
Slide 8
Slide 8 text
● Not part of your version control setup
● Changes can not be easily reverted
● Often require some manual updating
8
1. Database
and
2. CMS
Slide 9
Slide 9 text
For databases
● Write migrations and check them into
your version control system
● Use local containers and / or staging
environments to test out structural
changes before applying them to
production data
9
So what to do
about it?
Slide 10
Slide 10 text
But how to make
changes to your CMS
less stressful?
Slide 11
Slide 11 text
Let’s have a look
at the tooling that Contentful
provides for this.
11
One master environment (by default)
● Serves as your production space
● Used by editors
/spaces//
/spaces//environment/master/
13
Space
Environments
master
Slide 14
Slide 14 text
master
Copy this (or any other) environment to get a
sandbox setup with the same content model as
the master.
/spaces//environment//
14
Space
Environments
local-sandbox-1
local-sandbox-2
Slide 15
Slide 15 text
Want to try out a new feature that involves
changes of the content model?
● You don’t want to experiment with
production content
● So you spin up a new environment and
use it for testing
15
How would you
use them?
Slide 16
Slide 16 text
Let’s see how you can create them
in the Web App.
16
+
Slide 17
Slide 17 text
17
DEMO #1
Slide 18
Slide 18 text
We can now test our content model
independently of the production data.
18
Slide 19
Slide 19 text
You have some nice options:
● Quickly manually try out content model
changes in a local setup
Even nicer would be:
● Set up a staging environment where
you apply your content model changes
before you apply them to the
production space.
● Make environments part of
a CI/CD pipeline
19
Some use cases
Slide 20
Slide 20 text
For setups like a staging
environment or a CI/CD pipeline
we need automation
20
Slide 21
Slide 21 text
21
● Apply programmatic content model changes
● Similar to how you would write migrations to
the structure of your database
● Write your migrations in JavaScript or
TypeScript
What can you do with it?
The migration
tool
Slide 22
Slide 22 text
22
● Create content type
● Delete content type
● Edit content type
● Create/edit/delete fields
● Change field ID
● Update content metadata (tags)
Some Examples
Slide 23
Slide 23 text
Running migrations
Workflow example
master
staging
ci
Run migration
scripts
Run migration
scripts
Run migration
scripts
Slide 24
Slide 24 text
Let’s see a simple
migration example
in action.
24
Slide 25
Slide 25 text
25
DEMO #2
Slide 26
Slide 26 text
26
Using the
migration tool
and environments
we can:
● Write repeatable content model
migrations and check them into
version control
● Easily test out any content model
changes programmatically locally by
using a personal sandbox
environment
● Set up a staging / QA environment or
a CI/CD pipeline with a dedicated
contentful environment
Slide 27
Slide 27 text
This takes a lot of stress away from the
deployment workflow, because it gives
you confidence that content model
changes won’t break things.
27
Slide 28
Slide 28 text
But there are still some parts
of the deployment process
where things can go wrong.
28
Slide 29
Slide 29 text
master
staging
ci
Run migration
scripts
Run migration
scripts
Run migration
scripts
This still
feels scary.
Slide 30
Slide 30 text
There is no way to quickly
rollback content model
changes if things go wrong.
30
Slide 31
Slide 31 text
31
● An environment alias is a static identifier
● You can think of it as a symlink pointing
to a specified environment
Environment
aliases
Slide 32
Slide 32 text
32
● Once you opt in, you get a default “master”
alias.
● Instead of having a master environment, you
now have a master alias that has a target
environment.
/spaces//environments/master
/spaces//
Environment
aliases
Slide 33
Slide 33 text
Enabling environment aliases for a space
By renaming master environment and adding an alias in its place
release-1
master
master
Slide 34
Slide 34 text
master
Point alias to any environment
release-1
release-2
/spaces//environments/master
Slide 35
Slide 35 text
35
● Similar to the master environment the
master alias has a special status
● Create more aliases with custom ids if
you want to
● We are looking into renaming “master”
to “main”
A few things to
keep in mind.
Slide 36
Slide 36 text
Let’s create some aliases.
36
Slide 37
Slide 37 text
37
DEMO #3
Slide 38
Slide 38 text
Now we have a way to deploy
content model changes without
running migrations against a live
production environment.
38
Slide 39
Slide 39 text
Minimize downtime and allow instant rollback
master is no longer a stand-alone
environment but acts as an alias
targeting another environment
Production content is
served from release-1
environment
Execute migration
scripts
Change master alias to
target release-2
environment
Production content is
now served from
release-2 environment
Promote
Problem discovered!
Rollback is required
Rollback
Rollback master to
target release-1
environment
release-1
release-2
Use case: Promote an environment to master
master
Slide 40
Slide 40 text
Of course, this process
can be adapted to different
use cases.
40
Slide 41
Slide 41 text
Better safe than sorry
master is no longer a stand-alone
environment but acts as an alias
targeting another environment
Content is served from
prod environment
Run migration
scripts
Restore by changing
master alias to target
prod-backup
environment
Backup
Problem discovered!
Rollback is required
Restore
prod
prod-backup
Use case: Backup and restore
master
Optional:
Delete prod
environment
prod
Optional: Recreate prod
from prod-backup
Change master alias to
target prod environment
Slide 42
Slide 42 text
42
Sum up Integral parts of agile development now can
be integrated into your workflow:
Devs can feel safe about constantly
shipping changes, because:
● Flexible manual and automated testing
can be done beforehand and as part of
the deployment
● Rollbacks are easy
Slide 43
Slide 43 text
43
Docs Tutorials:
- Integrating migrations in a continuous
delivery pipeline with CircleCI
- Scripting migrations with the
Contentful CLI
Concepts:
- Multiple environments
- Environment Aliases
Slide 44
Slide 44 text
44
Docs Articles:
- Keep your deployments on track:
Contentful now has seamless
promotion and rollbacks
Code:
- contentful/contentful-cli
- contentful/contentful-migration
Slide 45
Slide 45 text
Let’s see how this looks
in a CI/CD pipeline
45
Slide 46
Slide 46 text
46
DEMO #4
Slide 47
Slide 47 text
Source control
Local computer
47
Dev writes code
Merged into Master, Staging
or QA via pull request
Continuous Integration Provider
Update alias to use newly
created environment
Deploys the new code
PUSHED
Hosting provider
TRIGGERS A BUILD
Stop the build
Creates new environment and runs migration scripts on Contentful
Run tests and checks
DID THE TESTS PASS? YES
NO