Continuous Integration (CI): Travis CI
Last updated
Last updated
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, automatically runs database change scripts if required. 3. When the api is deployed, deploy the ui.
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.
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.
you need to specify the pro option on travis cli even though we're not pro because they changed the domain for newer open source accounts to the same domain as the pro.
Repoistory Environment Variables can't be used in your .travis.yml file.
Travis cli encrypt overwrites encrypted variables by default instead of appending.
There's nothing on the environment variables page about how to use the variables in the .travis.yml file.
Testcontainers uses travis internally apparently but they don't have docs for it.
You have to specify not to delete the built files you want to deploy in the deploy section.
Only build prs and master branch
Select Open Source.
Intall it for free.
Complete order and begin installation.
Select Install.
Sign in with GitHub.
Authorize travis-pro.
Open project in VSCode.
Create a new branch.
We need the docker service for our testcontainers database API tests.
Sign in to the AWS console.
Go to IAM.
Select Users.
Select Add user.
User name: travis
Access type: Programmatic access.
Select Next: permissions.
Select Attach existing policies directly.
Select AmazonS3FullAccess.
Select AWSElasticBeanstalkFullAccess.
Select Next: Review.
Select Create user.
Keep the page open so we can copy the credentials into our travis file.
Open the root of our project in VSCode.
Install the Travis CLI
Login into your travis account using the CLI
The pro is important because travis changed their domain for free accounts to the pro domain.
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.
Commit your work.
Push the branch.
Check if the build passed in Travis CI.
Click the build: unknown
badge next to your repo name.
Select Markdown.
Copy the code.
Paste it in the root README.md
.
Following
Open .
Create the .travis.yml
file from .