To use CircleCI CI/CD, you need to deploy the application with DuploCloud as a Service and test that it works as expected.
CircleCI CI/CD is recommended only for upgrades of container images and to run tests that can be written to run before or after.
In order to call a DuploCloud API from CircleCI, you need to obtain and configure an API token.
(Recommended) Create a "service account" user in DuploCloud to own the API token.
Give the DuploCloud user access to the desired Tenant. See adding Tenants to a user.
Create an API token for that user. See creating API Tokens.
Add a CircleCI Environment Variables in the Context created for the organization, to allow CircleCI pipelines to communicate with the DuploCloud Portal.
Note: A 'service account' user in DuploCloud is just a user whose user name is not an email address, such as github-bot
or my-api-user
. These users are not able to log in.
Login to the CircleCI portal and select your organization.
Click on Organization Settings in the left-hand sidebar.
Click on Create Context button and create context by providing a name.
Click on the newly created context and scroll to Environment Variables section.
Click Add Environment Variable.
Set an Environment Variable name and value forDUPLO_HOST
(the value is the DuploCloud Portal URL).
Set an Environment Variable name and value for DUPLO_TOKEN
(the value of the token created for the above service account).
After adding the environment variables you should see them displayed in the Organization Settings section below.
The rest of this procedure assumes that you have added the above two environment variables.
The goal of this section is to show how you can build a docker image and push it to ECR.
It does three basic things:
Logs in to AWS ECR using just-in-time (JIT) AWS credentials from Duplo
Builds and tags your docker image, with the tag based on the git commit SHA.
Pushes your docker image
Here is an example CircleCI workflow that builds a docker image and pushes it to ECR.
To use it you will need to change following environment variables:
DOCKER_REPO
DOCKER_IMAGE_NAME
DUPLO_SERVICE_NAME
DOCKER_REPO
ECR_REGION
Above example of CircleCI requires DuploCloud utility shell script file which has to be checked in with your CircleCI file. This utility file can be found here: https://github.com/duplocloud/demo-npm-service/tree/master/.circleci
The goal of this section is to show how you can update the docker image for a service, after you have built that image.
This example makes some assumptions:
Your workflow already has a build
job - we created one in the previous section
Your build
job declares an output named image
- also done in the previous section
To use it you will need to change:
DOCKER_REPO
DOCKER_IMAGE_NAME
DUPLO_SERVICE_NAME
DOCKER_REPO
ECR_REGION
CI/CD using CircleCI
CircleCI is a popular Continuous Integration and Deployment (CI/CD) platform for implementing rapid development and deployment of DevOps functions.
To ensure that you use CircleCI securely, consult the CircleCI Best Practices Guide and keep up to date on the latest security alerts in the Blogs section.