Skip to content

AWS CodePipeline

AWS CodePipeline is a continuous integration and continuous delivery (CI/CD) service for fast and reliable application and infrastructure updates. This guide provides instructions on how to configure AWS CodePipeline to deploy Martini packages from your repository.

Overview

AWS CodePipeline automates the build and deployment process for your Martini packages. The pipeline can be configured to either bundle Martini Server Runtime with the packages or focus solely on deploying the packages. The process involves setting up a pipeline that fetches code from your repository, builds the necessary packages, and deploys them to your AWS environment.

Build Options

1. Build Docker

Buildspec file: martini-build-image.yaml

Builds a Docker image that bundles:

  • A specific version of the Martini Server Runtime
  • Application packages from the repository

The final image is pushed to Amazon ECR for deployment into runtime environments. This method is ideal for reproducible environments where the runtime and package versions must be locked together.

Supporting files: Dockerfile

Defines how the image is assembled from the base Martini runtime.

2. Deploy Packages

Buildspec file: martini-package-upload.yaml

Packages are zipped and uploaded directly to a live Martini runtime instance using the Martini API. This method is best when the runtime stays the same but packages are frequently updated.

Includes features like asynchronous uploads, retry-based polling for STARTED status, and dynamic filtering of packages.

Supporting files: upload_packages.sh

A reusable script that manages package validation, upload, and polling.

Steps to Configure AWS CodePipeline

  1. Access the CodePipeline Infrastructure Code
    Use the Terraform modules from Lonti's GitHub organization to provision the necessary AWS resources for the Martini pipelines. The templates are available here:
    Terraform Template Repository

  2. Choose Between the Two Pipelines

    • Use the martini-build-image module to build and publish a Docker image that includes the Martini runtime and packages.
    • Use the martini-upload-package module to upload packages directly to an existing runtime instance.
  3. Set Up Your Pipeline and CodeBuild Project via Terraform

1
2
3
4
git clone https://github.com/torocloud/martini-aws-codepipeline-terraform-module.git
cd martini-aws-codepipeline-terraform-module/<module-directory>
terraform init
terraform apply

4. Configure AWS SSM Parameter Store

Parameters should be defined and encrypted using SecureString. Example:

For martini-build-image.yaml

Parameter Required Description
MARTINI_VERSION No Martini runtime version. Defaults to latest.

For martini-upload-package.yaml

Parameter Required Description
BASE_URL Yes Base URL of the target Martini instance.
MARTINI_ACCESS_TOKEN Yes Token used to authenticate with the target Martini instance.
PACKAGE_NAME_PATTERN No Regex pattern to filter packages. Defaults to .*
PACKAGE_DIR No Directory containing packages to upload. Defaults to packages.
ASYNC_UPLOAD No If true, tolerate HTTP 504 responses and fallback to polling. Defaults to false.
SUCCESS_CHECK_TIMEOUT No Number of polling attempts. Defaults to 6.
SUCCESS_CHECK_DELAY No Delay between polling attempts in seconds. Defaults to 30.
SUCCESS_CHECK_PACKAGE_NAME No If specified, only this package will be polled for STARTED status.

Example to retrieve parameter in buildspec:

1
PARAMETER=$(aws ssm get-parameter --name "${PARAMETER_NAME}" --with-decryption --query "Parameter.Value" --output text)

5. Trigger the Pipeline

AWS CodePipeline can automatically start on repository changes. For manual runs:

1
aws codepipeline start-pipeline-execution --name <pipeline-name>

You can also add this to your buildspec to trigger a pipeline within a pipeline.

Additional Resources