r/webdev•
expl0dingz

How do you guys handle CI versioning and deployment to multiple environments? (create-react-app, gitlab, AWS Lambda)

At work, we have a create-react-app project which we deploy built static files on a s3 instance. It then calls our APIs/Lambda functions and does stuff.

We have two environments, dev (staging) and prod.

Here's how I have the CI for the frontend set up:

  • do dev work until it's time for next deployment
  • update package.json version and CHANGELOG.md
  • push to master
  • create tag locally with shell script that checks if package.json version and CHANGELOG.md is up to date and in sync
  • push tag to remote
  • gitlab CI detects semver formatted tag, and triggers build process
  • if there is a -beta suffix in the tag name, it deploys to staging, otherwise deploy to prod

One thing i feel there is room for improvement: branches. We are not utilizing branches fully, usually it's just one branch per development cycle, sometimes a feature, but mostly it's just me pushing to master straightaway (as I'm the main person working on this project)

I feel that having to add a -beta suffix to the tag all the time for frequent deployments to our dev/staging environment is a little out of place, but it feels better than having to do it the other way round and add something like a -release suffix to the ones deployed to prod.

Should each tag be a distinct build version (1.0.1 vs 1.0.1-beta)? If so, I would then have a clean list of tags for each version, but I would then lose the ability to push to different environment via tag name.

Is there a better way of managing tags and the environment those certain versions are deployed to?

Is there something inherently wrong about the direction I'm heading?

Posted Aug 16, 2018, 10:49 AM UTC

22
MomoGunz•

I don't think there is anything entirely wrong with your way of managing build versioning as long as you have a need for it.

An alternative would be using branches to identify deploys.

For example, pushing to "master" would deploy to your staging env and pushing to "production" would deploy to your prod env.

3
Kovaz•

I'm working through a similar process at my company. Different tools (vue-cli, heroku, circle CI) but same idea.

A couple of differences I'm noticing:

In my setup, there are three environments: development, staging, and production. I deploy to development multiple times per day and it's no problem if a build is broken on development - it's mostly to get feedback on features that are in-progress or to demo my current progress in a meeting. Staging is set up identically to production; the only difference being that staging is only ever seen internally. So staging is the final testing ground for production-ready builds. I never deploy to production directly - always deploy to stage and promote from stage to production. Fortunately that's about 5 seconds to do in Heroku, and I think you could quite easily script a similar process for s3.

I feel that having to add a -beta suffix to the tag all the time for frequent deployments to our dev/staging environment is a little out of place, but it feels better than having to do it the other way round and add something like a -release suffix to the ones deployed to prod

The question I'd ask here is: what value do you want your tags to provide? In my opinion, tags should be used to mark versions of the app that have gone out to the public. I think if you start polluting your tags with both production versions and development deployments you lose a lot of the usefulness of the tags. What I'd propose would be something like this:

  • CI triggers build process on every push to master
  • Deploy to development regardless of tags
  • If there's a semver-formatted tag, also deploy to production (or stage)

That way you know your dev site is always in sync with master, which is nice for demoing progress. And production (or stage) is always up to date with your latest tag, but your tags aren't polluted with "v1.0.1-beta-3" or whatever.

EDIT: On using feature branches: it's definitely a habit that's good to get into. I've been burned in the past by not working on a branch and being halfway through 3 different features all on master when one of the three became super high priority, so I had to work a 70-hour week to get all 3 done because there was no way to revert the work in progress on just 2 of them. As a rule of thumb, if a task you're working on can't be done in one reasonably small commit, you should just use a feature branch. I've also found if you're not working on feature branches, there's always a half-day or so of work to get the repo ready for a new team member to join, which is annoying.

2