Continuous Integration (CI): Travis CI

Continuous Integration vs. Continuous Delivery vs. Continuous Deployment

It seems the definition is rather subjective so let me be explict about what glue-stack does: 1. Tests are run when you create your pull request (pr) into master and you can't merge until they pass. 2. When you've merged your code into master, it will be deployed to production.

I guess that would be Continuous Deployment?

Our pipeline (process) looks like this: 1. Run the ui and api tests in parallel. 2. When they are both complete and pass, deploy the api. 1. The api is deployed to AWS elastic beanstalk which is AWS' PaaS (platform as a service) offering. It can be configured to do rolling deploys for zero downtime deploys. 2. When the new api version starts up, Flyway automatically runs database change scripts if required. 3. When the api is deployed, deploy the ui.

Execution

Oh wow was this hard. That was probably in part due to me not wanting to do this but CI is very standard in the industry so it really had to be done and the final product is pretty cool. Unfortunately I didn't really learn anything more about CI while setting up Travis, I mainly learned about setting up Travis. And how painful it is.

Its really easy to get a basic build and test to make sure the branch doesn't fail but the automatic deploy was a bit harder.

Alternatives

After reaching the halfway point I thought about changing to either Circle CI or Buddy.works but I thought that would be harder than just finishing off travis. Travis is cool because it gives you concurrent jobs for free but that's only for open source projects.

This is a bit of a weird area for this project because I want to teach everyone software development; open source and closed source, but at the same time its nice to reap the rewards offered by services for open source projects. GitLab has its own CI for free for private projects so that is pretty dam tasty if you go closed source because the private repo and CI is free. I don't think I'm willing to move this project over to GitLab since GitHub is largely the open source standard but if I needed closed source I would be looking at them.

Problems

Method

Following https://docs.travis-ci.com/user/getting-started/

  1. Select Open Source.

  2. Intall it for free.

  3. Complete order and begin installation.

  4. Select Install.

  5. Sign in with GitHub.

  6. Authorize travis-pro.

  7. Open project in VSCode.

  8. Create a new branch.

  9. Create the .travis.yml file from .travis.yml.

    We need the docker service for our testcontainers database API tests.

  10. Sign in to the AWS console.

  11. Go to IAM.

  12. Select Users.

  13. Select Add user.

    User name: travis

    Access type: Programmatic access.

  14. Select Next: permissions.

  15. Select Attach existing policies directly.

  16. Select AmazonS3FullAccess.

  17. Select AWSElasticBeanstalkFullAccess.

  18. Select Next: Review.

  19. Select Create user.

  20. Keep the page open so we can copy the credentials into our travis file.

  21. Open the root of our project in VSCode.

  22. Install the Travis CLI

    brew install travis
  23. Login into your travis account using the CLI

    travis login --pro

    The pro is important because travis changed their domain for free accounts to the pro domain.

  24. Encrypt your credentials. This is done using a private key for your account that only travis knows. Its bad practice to check in credentials into source control. In fact, there are bots that are constantly scanning GitHub for credentials and if they find some they automatically spin up instances, usually to mine bitcoin, and you pay for it.

    travis encrypt access_key_id=YOUR_ACCESS_KEY --add env
    travis encrypt secret_access_key=YOUR_SECRET_KEY --add --append env
  25. Commit your work.

  26. Push the branch.

  27. Check if the build passed in Travis CI.

  28. Click the build: unknown badge next to your repo name.

  29. Select Markdown.

  30. Copy the code.

  31. Paste it in the root README.md.

Last updated