DEVOPS

CI/CD with Altostra and CircleCI

Integrating your Altostra projects with CircleCI

Yossi Ittach
Altostra

--

Originally published on Altostra.

CI/CD and Altostra

In our last post, we discussed how to integrate Altostra with GitHub Actions to create a simple yet effective CI/CD process. Cool as GitHub Actions is, it’s still the new kid on the block, and our users have rightfully demanded the CircleCI edition. So with no further ado, let’s learn how to add a simple CircleCI CI/CD flow to a basic Altostra API service project.

You can read more about the basic API project we’ll use here, and more about CircleCI here.

Using Altostra API Key with CircleCI

Getting the Altostra API Key

First of all, we’ll need to get an API key from Altostra.

Go to the Account Settings page in the Altostra Web Console:

  1. Click “Create Token”
  2. Give your token a meaningful name so you’ll recognize it later
  3. Keep your token somewhere safe — this is the last time you’ll see this token!

Creating a CircleCI workflow

Log in to your CircleCI account with your GitHub account.

  1. Under the “Projects” tab, find your project and click “Set Up Project”
  2. You’ll be prompted to add a configuration — add the configuration below.
  3. CircleCI will create a branch called circleci-project-setup for you in your repository with the appropriate config file.

This how it would look like:

This CircleCI workflow basically tells CircleCI to run the job whenever someone pushes anything to any branch that contains the.circleci/config.yml file.

Each time it runs it will checkout the code, install dependencies, config the Altostra CLI, and use the Altostra API key to push the latest version to the Altostra repository.

After you’ve set the configuration file, you’ll see that CircleCI has already started running the workflow for the new branch circleci-project-setup — but it will fail because we still haven’t added our API key to the workflow. Let’s fix that.

Connecting the secret API Key

Now to what is usually the tricky part — how to safely use your API key without jeopardizing it.

Usually in CI/CD frameworks you’d have to store your secrets either on a secure server or in some kind of vault (like AWS Secrets Manager).

CircleCI enables you to store your API key as an environment variable that can not be viewed — only updated or deleted.

Go to your CircleCI project, and:

1. Click on “Project Settings”

2. Select “Environment Variables” from the left side menu

3. Click “Add Environment Variable”

4. Name your environment variable ALTO_API_KEY

5. Paste your secret into the input field.

Your secret is not visible to anyone — it can only be updated or deleted.

Let’s try it out!

Now that we have the API Key safely stored and connected to the CircleCI workflow,

all we need to do is push a commit to any branch that contains a .circleci/config.yml file. In our case, it’s circleci-project-setup branch. (You can also just merge the circleci-project-setup branch into masterand work on it instead)

run npm version major && git push on your local machine, and open the CircleCI console.

Now you can go back to your terminal and list your images:

Turning the CI to CI/CD

The move from CI to CI/CD is not trivial — it usually requires some kind of canary testing, automated integration, and sanity tests. If you already have these in place, deploying your code to Production (or any other env) is as simple as adding another step to your CircleCI configuration after the pushstep:

Let’s see it in action:

First, we’ll add a hello endpoint to our API Gateway and a function to return Hello, CircleCI on GETrequest.

Now, let’s make sure we add & push all the required changes to our circleci-project-setup branch

Then, let’s make sure the CircleCI has triggered appropriately:

Once the deployment has been initiated, we can see it on the Altostra Web Console and check it’s status on the AWS CloudFormation stack:

Now that everything is up, we can test our new endpoint with a basic curlrequest:

curl --request GET '${YOUR_API_GATEWAY_ENDPOINT}/hello'

Voila! We added a feature to our code, pushed to git, and had it deployed to our Production env on AWS automatically!

Wrapping up

Using the Altostra’s API keys librates you to integrate your Altostra projects with any CI/CD framework you work with. What we’ve seen here is a simple example of utilizing CircleCI to create a basic CI/CD process, but it can also be integrated with many more testing and deployment tools — from Docker images to canary testing.

--

--

Yossi Ittach
Altostra

Software engineer with a Master’s degree in STS, a Vipassana practitioner who like to meditate at techno parties, and generally a curious guy