Using GET Webhook For Rainbow Deployments

  • Difficulty - intermediate
  • Time To Complete - 20-30 minutes
  • Free Tier Compatible - no

Resources

The following resources are required to complete this tutorial:

This Github Repository has all the necessary resources for following along with this guide. It is recommended that you fork this repo so that you can update the source code in the future.

Creating the Image Source

To begin, an Image Source should be created from either this repo (using the Dockerfile image source type) or an image source of your own.

  1. Navigate to the Images Tab from the Portal
  2. Click the Create button at the top of the nested side navigation.
  3. Add a name for the Image Source
  4. For Type, select the Dockerfile - Git Repo option
  5. Paste the clone link for the Git Repo in the Git Repo URL field
  6. The Git Repo included above has a Dockerfile at /Dockerfile, which is the default. If using a different repo for this guide, ensure that this route points to the Dockerfile in the repository.
  7. Click Create Image Source

Once the Image Source is created, click Import Image in the upper right of the page.

Creating the Deployment

Checkpoint

At this point, the following resources should be created:

  • Server
  • Environment
  • DNS Zone (verified)
  • Image Source
  • Image

The next step is to create a new deployment and assign it the appropriate deployment tags. These tags will be used to associate a LINKED Record.

To create a container inside a deployment:

  1. Go to the Environment Tab and select an environment.
  2. In the top right, click Deploy a Container. This will open the New Container modal.
  3. Give the container a name. In the screenshots below, the container name is website.
  4. In the Image section of the form, select the image source created in the previous step.
  5. In the Network section, enable Public Network to enable and add port mappings.
  6. Enable Deployments and enter a deployment version, for example, v0.0.1.
  7. Leave the remaining fields as their defaults and click Deploy Container.
Container Deploy Form

Semantic Versions

Only versions starting with the character v will adhere to semantic versioning standards.

Deployment Tags

At least 2 tags should be created for this tutorial - test and current. To create these tags:

  1. Select the Deployments section in the Environment where the container is deployed.
  2. On the Deployment table, use the + button to open the tag create form
  3. Add the tag current
  4. Add the tag test

The screenshot below illustrates the process of adding a tag to a deployment.

Create TagNew Tag Showing on Dashboard
add a tag
tag created

Configuring LINKED Records

Now that the two tags are created, two LINKED records will be configured. One record will route traffic to the deployment with the current tag, and the other record will route traffic to the deployment with the test tag.

Each record will direct traffic to a different subdomain, and the test record will be updated first in the deployment pipeline. This record will be used to test that the deployment is live and accepting traffic before promoting the current tag, which simulates production traffic.

To create the current record:

  1. Navigate to your verified DNS Zone.
  2. Click the Add Record button in the top right.
  3. Select the LINKED Record type.
  4. Select the appropriate Environment.
  5. Set the name to @
  6. Select Link to Deployment
  7. Add the container identifier on the left-hand side of the form, and the tag current on the right. This will route traffic to the container with a matching identifier within the deployment tagged current.
  8. Select TLS Enabled to automatically generate a TLS cert for this domain.

Repeat the process for the test record, but set the Name field to test and the Deployment Tag field to test.

Linked Record Tag

Start Environment

Before visiting the linked record URLs, activate the environment using the Start All button.

Navigate to both domains to verify the URLs resolve and everything functions as expected.

Adding the Pipeline

The next step is to create the Pipeline.

  1. Navigate to the Pipelines Section of the Portal.
  2. Click the Create button.
  3. Provide a name.
  4. Select Dynamic pipeline. This allows for variables to be inserted into the pipeline at runtime.
  5. Select the Editor tab.
  6. Create a new stage called Deployment

Step 1: Create and Import Image

The first step of the pipeline involves creating and importing the image created previously.

  1. Click the Add New Step button, then select Create and Import Image from the dropdown menu.
  2. Expand the Step Reference section, and add a step reference image. This allows us to reference the image created in future steps.
  3. Provide a name for the image.
  4. For the Image section, use the lookup functionality to select the image source created in the first step of this guide.
  5. Click Create Step
step 1

Step 2: Create Container

In the next step, a new container will be created from the image.

  1. Create a new step - Create Container.
  2. Set the Name field to match the container created earlier in the guide. In this case, website.
  3. For the Environment field, select the Resource type, and enter the variable {{environment}}. This will allow the environment to be specified at pipeline runtime.
  4. In the Image field, select the From type and target the image created in the first step. (Stage 1) -> image (Step 1).
    • This will create a new container from the imported image.
  5. Set Public Network to enabled
  6. Add ports 80:80 and 443:80.
  7. Set the Deployment Version to the variable {{version}}.
step 2

Step 3: Start Environment Deployment

This step will facilitate starting the containers within a specific deployment.

  1. Add the step Start Environment Deployment
  2. Reference the variable assigned to the environment in step 2. Set the field to Resource type and specify {{environment}}.
    • By referencing the same variable, this allows the pipeline to work for any environment specified at runtime.
  3. Set Deployment type to version
  4. Set the Deployment Version field to the variable {{version}}.

step 3
Since the same {{version}} variable is used in this step and the last, this will start the deployment that was just created.

Step 4: Update Deployment Tag

Now that the deployment containers have been started, it's time to test that the deployment is live and working properly. To facilitate this, the tag test will be applied to the deployment.

Recall that a LINKED Record was set up to point to the test tag. In order to test this new deployment, the test deployment tag will be added to confirm the container is live and accepting traffic using the GET Webhook in the next step.

  1. Add the step Update Deployment Tag Version
  2. For Environment, set the target field to Resource and specify the variable {{environment}}.
  3. Set the Deployment Type to version.
  4. Set the Existing Version field to {{version}}.
  5. Set the **New Tag **field to test.

This step will add the test tag to the new deployment.

step 4

Step 5: Sleep

To ensure the container has a few moments to get up and running, implement a Sleep step of 30s.

  1. Add the step Sleep.
  2. Set the Duration value to 30s.

This will ensure the next step hits the appropriate resource and avoids a race condition.

Step 6: Get Webhook

A GET Webhook step will be used to check that the container has come online and is able to respond to a request. This ensures the container is operational and will verify that the pipeline is ready to promote the deployment version to current.

  1. Add the step GET Webhook.
  2. For the URL field, use the URL of the LINKED Record pointing to the test tagged deployment.
  3. Expand Advanced Options and check the boxes Retry on and not in the second row.
  4. Then enter the code 200 into the HTTP Codes field.
    • This setting instructs Cycle to retry this webhook until a 200 response is recieved.
  5. Set the Interval field to 20s.
  6. Set the Max Attempts field to 5.
step 6

Step 7: Update Deployment Tag Version

At this point, the deployment is live and accepting traffic on the test domain. Since this check has been passed, it is safe to promote the deployment to current using deployment tags, which simulates promoting a production version of the application.

But first, we will update the tag on the previous version to previous. This deployment will be important if there is an issue and the application needs to be rolled back.

  1. Add the step Update Deployment Tag Version
  2. In the Environment field, select Resource and add the appropriate variable - {{environment}}.
  3. In the Existing Tag field, target the tag current.
  4. For the New Tag field, set the value to previous.
step 7

This will find the deployment with tag current and add an additional tag previous.

Step 8: Update Deployment Tag Version

Now, the new deployment will be promoted to current.

  1. Add another Update Deployment Tag Version step
  2. In the Environment field, select Resource and add the appropriate variable - {{environment}}.
  3. Set the Deployment Type to version. Then set the Existing Version field to the version variable {{version}}.
    • Since we are using the same variable throughout, this will ensure deployment created in this pipeline is being referenced.
  4. In the New Tag field, set the value to current.
step 8

Step 9: Prune Environment Deployments

Now, there are two deployments of importance - one is tagged previous and one is tagged current. As a cleanup step, any deployments without a tag can be removed through the pruning process.

  1. Add the step Prune Environment Deployments.
  2. In the Environment field, select Resource and add the appropriate variable - {{environment}}.

Save Pipeline

Once the pipeline has been created, be sure to click Save Pipeline button to save all step and stage changes.

Next Steps

Change the Website

Before running the pipeline, a change needs to be made to the website itself. This will allow us to test that the deployment was proccessed successfully.

If using the resource provided by this tutorial, simply change one of the text lines in the /src/App.js file and commit the change.

Trigger the Pipeline

In the Portal, return to the newly created pipeline and locate the Trigger Pipeline button in the top right.

  1. Click the V option to the right of the button to provide the pipeline variables that will be used.
  2. For the environment variable, specify the environment in the format env:<environment-identifier>. The environment identifier can be found on the enviroment settings page.
  3. For version, choose a deployment version for the new deployment.
  4. Set the test-tag to test.
Pipeline Variables

Deployment Complete

After triggering the pipeline, changes will be live within the next few minutes.

To see the pipeline steps in real time, navigate to the environment and click the Deployments tab.

  • The new container will appear in its new deployment, and the previous and current tag will update.
  • As soon as the current tag is updated to the new deployment, the site will be rendering the new content.