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 GitLab, GitHub predefined actions are implemented to perform CI/CD tasks.
This section discusses how you can configure Github to integrate with Duplo
To interact with your Duplocloud Portal from Github Actions, you need to follow these steps.
First you need a service account in your portal which has the needed 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.
To get fully setup with Duplocloud and the underlying cloud provider you use, you get everything you need setup with duplocloud/actions/setup. This action will install the cli for duplocloud and the CLI for the underlying cloud as well. Finally it will perform a safe login so subsequent steps may freely interact with duplocloud or the cloud it manages.
Here is the most basic setup for any pipeline to get started.
Github Environments are how you define different deployment environments for your workflows and how they are differ from one to the other. Here you define environment specific variables and secrets. This allows you to parameterize and secure your workflows. We highly recommend using this feature, however it is paid and therefore optional since you may not have it.
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 times you may not even need to add any secrets or variables because we 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 simply be type string and you pass in a name.
References:
The rest of this documentation will assume that you named the GitHub repository secret DUPLO_TOKEN
.
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 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 service, after you have built that image. This task can be achieved using the duplocloud/actions/update-service 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 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 Lambda functions 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 blog.
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
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
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
Use Duplo 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 as all capital letters. Don't specify DEV01 for example, specify dev01.
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 AWS credentials from Duplo)
Builds and tags your docker image, with the tag based on the git commit SHA and ref.
Pushes your docker image
Here is an example github workflow that builds a docker image and pushes it to ECR.
To use it you will need to ensure the following are configured correctly:
DUPLO_HOST
env var
DUPLO_TOKEN
env var
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.