Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
CI/CD using GitHub Actions
While DuploCloud uses cURL commands to support Continuous Integration and Deployment (CI/CD) in , GitHub predefined actions are implemented to perform CI/CD tasks.
Use DuploCloud to upload to S3 from Github Actions
The goal of this section is to show how you can upload to an S3 bucket from Github Actions.
This process is done in two basic steps:
Logs in to AWS ECR using Just-In-Time (JIT) AWS credentials from DuploCloud
Upload your website content to S3
To use any of the below examples you will need to change:
The local path to upload from, if it is not build
duplo_host
env var
TENANT_NAME
env var
BUCKET_NAME
env var
The following example uploads a single directory to S3.
It does not show more advanced things like the following items:
Setting cache control directives
Making the uploaded content public
Making AWS delete older content
This example uploads multiple directories to S3.
It assumes that the following is true:
There is a subfolder named static
, whose contents can be cached for one year.
The rest of the contents can change at any time, so the cache uses must-revalidate
.
Use DuploCloud to build and push a Docker image from GitHub Actions
Avoid using capital letters when referencing a DuploCloud construct, such as a Tenant, even when the UI displays the string in all capital letters. Don't specify DEV01, for example; specify dev01. The `TENANT_NAME` may need to be lowercase even though the UI shows it in uppercase.
This section aims to show you how to build a Docker image and push it to ECR.
It does three things:
Logs in to AWS ECR (using just-in-time AWS credentials from DuploCloud)
Builds and tags your Docker image, with the tags based on the Git commit SHA and ref.
Pushes your Docker image
Here is an example of a GitHub workflow that builds and pushes a Docker image to ECR.
To use it, ensure the following are configured correctly:
DUPLO_HOST
environment variable
DUPLO_TOKEN
environment variable
Use Duplo to update a Service container from Github Actions
The goal of this section is to show how you can update the docker image for a Kubernetes service, after you have built that image. This task can be achieved using the action.
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 ensure your GHA Environment has the following:
DUPLO_HOST
env var
DUPLO_TENANT
env var
DUPLO_TOKEN
env var
You need to change the service name below from my-service
to the name of your actual service.
Use Duplo to update a Service container from Github Actions
The goal of this section is to show how you can update the docker image for an ECS service, after you have built that image. This task can be achieved using the action.
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 ensure your GHA Environment has the following:
DUPLO_HOST
env var
DUPLO_TENANT
env var
DUPLO_TOKEN
env var
You need to change the service name below from my-service
to the name of your actual service.
This section discusses how you can configure Github to integrate with Duplo
Follow these steps to interact with your Duplocloud Portal from GitHub Actions.
First you need a service account in your portal with the permissions.
Note: A 'service account' user in DuploCloud is just a user whose user name is not an email address, such as github-bot
or simply github
. These users are not able to use the web portal.
Here is the most basic setup for any pipeline to get started.
The most common use case with Duplocloud is to match up one Tenant to one Environment. Imagine we have a tenant named dev01
, then you make a new environment in every repo, which will deploy to it named dev01
. Often, you may not even need to add any secrets or variables because we have already added the DUPLO_HOST
and DUPLO_TOKEN
at the repo level earlier, and you only need the name of the environment as the value for the DUPLO_TENANT
.
This shows how to configure a job to use an environment using an input and match it up to the tenant.
The input type is environment
which only works on workflow_dispatch
because it provides a UI with a drop-down selector for choosing from the list of configured Github Environments. On any other event type, the environment input would be a type string
, and you pass in a name.
Retrieve the Duplo Tenant ID from the duplocloud_tenant
in the Terraform data source using the syntax: `duplocloud_tenant.tenant1.id`
.
The rest of this documentation will assume that you named the GitHub repository secret. DUPLO_TOKEN
.
Use GitHub Actions to deploy a Lambda Image or S3 bucket update
Instead of deploying your Lambda code in the same pipeline as your infrastructure, you can use CI/CD and GitHub Actions pipelines. With DuploCloud's GitHub Actions integration, you can build and deploy in your AWS account by deploying a Lambda image or by a package uploaded to an S3 bucket.
For general information about deploying serverless applications with GitHub Actions in AWS, reference this .
Use the following code as a template to update a Lambda container image with GitHub Actions. In this example, the Lambda container image in the dev01
The tenant is updated and redeployed.
You must ensure the following are configured in your environment and your specific situation.
The name of lambda is set on the action to your actual lambda
Duplocloud context configured correctly
Use the following code as a template to deploy your Lambda functions to an S3 bucket with GitHub Actions. In this example, the Lambda in the dev01
The tenant is updated using an S3 bucket that contains mylambda-v1.zip
You must ensure the following are configured in your environment and your specific situation.
Duplocloud context configured correctly
S3KEY
S3BUCKET
LAMBDA_NAME
Dockerhub Lambda Base Images
Use DuploCloud to update your CloudFront from Github Actions
The goal of this section is to show how you can upload to an S3 bucket and update a CloudFront distribution from Github Actions.
This process is done in four basic steps:
Logs in to AWS ECR using Just-In-Time (JIT) AWS credentials from DuploCloud
Build your website content
Upload your website content to S3
Inform AWS CloudFront that the website content has changed
NOTE: The example workflow assumes that all the website content is uploaded from a single subfolder named build
. It also makes extremely conservative assumptions about cache lifetimes. Your actual website content may allow a more optimal cache lifetime.
IMPORTANT: Steps to build website content are application specific and outside of the scope of this document. Please replace the example step in the workflow with the steps needed by your application's website.
To use it you will need to change the following:
The steps used to build your website content
duplo_host
env var
CLOUDFRONT_ID
env var
TENANT_NAME
env var
BUCKET_NAME
env var
You also likely will need to change the paths and AWS CLI arguments used to upload your website content.