Open tenongene opened 10 months ago
I wrote a lambda function in AWS named "quotegen-update" that will update the application image in the EC2 instances using the NodeJS SDK for AWS. The function URL will be used to configure a Webhook in docker hub. The Webhook will send an HTTP POST request to the function URL with each push of a new image to docker hub.
The idea is for the function to send instructions to terminate the currently running instances, at which point the Autoscaling group will fire up new instances to replace the terminated ones. However, based on the embedded user data script, the new instances will have the latest application image pulled from docker hub when creating the containers.
The lambda function handler makes use of the DescribeInstancesCommand and TerminateInstancesCommand methods of the EC2 Client Module.
The DescribeInstancesCommand was used as a method to filter out the instances by the resource Tags of
Name and Instance Running Sate. The instance ID was not ideal because each new instance will have a
new instance ID and a new public IP address when fired up by the autoscaling group, so it wouldn't be
possible to code which instances to stop.
The resource Tags are the most efficient method since that is common to all instances created.
=====================================================================
Created function with function URL: https://aicu5rzgtfpqmwhaua4z7sijyi0snlsk.lambda-url.us-east-1.on.aws/
I configured a webhook for the application image repository in docker hub with the URL of the lambda function for which a POST request will be sent for image update.
I migrated the application code to GitLab as my preferred platform for continuous integration and continuous deployment.
============================================================================
I configured environment variables in the GitLab pipeline with credentials to access the DockerHub registry for automatically pushing any image updates.
================================================================================
Wrote the .gitlab-ci.yaml file definition for the pipeline that will propagate changes in the application to the image upon a push to the code repository. I used a Docker in Docker runner for the pipeline.
============================================================================
Ran initial pipeline with a test change to the application code to verify successful build of application docker image.
==============================================================================
Updated image successfully pushed to Docker Hub.