Series: ember-cli-deploy

ember-cli-deploy-Versioned Deploys

Published on Jun 10, 2016

Use versioned deploys to preview new deploys before launching them and to easily revert to old deploys.

We use three plugins to do this: ember-cli-deploy-revision-data, ember-cli-deploy-display-revisions, and ember-cli-deploy-s3-index.


Links

Code

$ ember install ember-cli-deploy-revision-data
$ ember install ember-cli-deploy-display-revisions
$ ember install ember-cli-deploy-s3-index
//config/deploy.js
var ENV = {
  's3-index': {
    accessKeyId: process.env.AWS_ACCESS_ID,
    secretAccessKey: process.env.AWS_ACCESS_SECRET,
    bucket: 'ember-school-deploy',
    region: 'us-east-1'
  }
}
$ ember deploy production
$ ember deploy:list production
$ ember deploy:activate --revision <your revision>
$ ember deploy production --activate

Transcript

Welcome back to our series on ember-cli-deploy. Currently, we’ve got our app both deployed and talking to the API. Now we’re going to add versioning.

Why versioning? Aside from being programmers and reflexively liking to version things, there are two big benefits I see. The first is that this makes it easy to test new deploys in production before showing them to the general public. The second is that if the current deploy ends up having a bug, it’s easy to revert to a previous version.

To implement our versioning, we’ll be installing 3 different plugins which work together via the hooks in the build pipeline. One of them will be S3-specific, but much of what we learn can be useful to other strategies.

ember-cli-deploy-revision-data

The first addon will be ember-cli-deploy-revision-data.
bash
$ ember install ember-cli-deploy-revision-data
`
It’s sole purpose is to generate a unique revision key that can be used by other plugins: https://github.com/ember-cli-deploy/ember-cli-deploy-revision-data/blob/master/index.js#L48

This is a great way to share a common feature between addons that may not have much in common.

ember-cli-deploy-display-revisions

The second addon will be ember-cli-deploy-display-revisions.
bash
$ ember install ember-cli-deploy-display-revisions

It’s sole purpose is to take the deploy:list command and make it display the available revisions. The command itself is built into ember-cli-deploy, but doesn’t seem to do anything unless there’s a plugin such as ember-cli-deploy-display-revisions that does something with the displayRevisions hook.

https://github.com/ember-cli-deploy/ember-cli-deploy-display-revisions/blob/master/index.js#L26
http://ember-cli-deploy.github.io/ember-cli-deploy/docs/v0.6.x/pipeline-hooks/#hooks-by-command

It then explicitly says that it expects the fetchRevisions hook to be implemented by a different plugin.
https://github.com/ember-cli-deploy/ember-cli-deploy-display-revisions#passing-revisions

ember-cli-deploy-s3-index

So those are our two supporting plugins. Everything else will be done by ember-cli-deploy-s3-index.
bash
$ ember install ember-cli-deploy-s3-index

This is the plugin that will implement fetchRevisions like is needed in ember-cli-deploy-display-revisions. It’s also the one that will take the revisionKey spit out by ember-cli-deploy-revision-data and hook that into the upload process. Finally, it will allow us to choose which revision to activate at any given time.

But first, we have to set up the configuration. We’ll basically copy our S3 configuration:

//config/deploy.js
var ENV = {
  's3-index': {
    accessKeyId: process.env.AWS_ACCESS_ID,
    secretAccessKey: process.env.AWS_ACCESS_SECRET,
    bucket: 'ember-school-deploy',
    region: 'us-east-1'
  }
}

We can also delete the filePattern field from the S3 configuration, since we’re now taking care of uploading the index.html file via the s3-index plugin.

And with that, we can deploy.

$ ember deploy production
$ ember deploy:list production

We’ll ask for a list of our deployments back and it will give us the one deployment we’ve had since installing the ember-cli-deploy-revision-data plugin.

Making new revisions

Let’s change something small and then deploy again. You’ll see that there’s another revision in the list. This shows us that you don’t need to commit to deploy, so keep that in mind- more as a pitfall to avoid than a tool to be exploited.

Now we’ll try to deploy a third time, this time without changing anything, and you’ll see that another revision is NOT generated.
Previewing and Activating revisions

If you change something then deploy, you’ll see that nothing has changed. That’s because your new version hasn’t been activated yet.

Before you activate it, you may want to preview it. To do that, after the index.html you put a colon and then the revision.

To activate it, run
bash
$ ember deploy:activate --revision <your revision>

Then you’ll see that it’s updated. This is the mechanism which you use to easily revert to previous versions.

If you want to activate your new revision immediately without deploying it, then you can add the activate option to your deploy command
bash
$ ember deploy production —activate

Conclusion

That’s how you can use revisions in your ember deploy. The commands themselves are really easy. The more complex part of this episode was understanding the hooks that are used in order to get the three plugins we went over to work together.

We’ll talk more about that next week when we talk about the lightning deploy stack. See you then!

ember-cli-deploy

Subscribe to our mailing list