GitLab's Integration with AWS CodePipeline for ECS
Aws codepipeline provides integration with most of the third-party repositories but for Gitlab’s the pipeline doesn’t supports the build in integration therefore it becomes challenging for developers to have a complete stack set of CICD pipeline.
This blog is more about how we can overcome this challenge and build a complete end-to-end pipeline. There are different ways to achieve this. Here we are using one of the easiest technique
The following diagram depicts how the CICD pipeline is set up for GitLab’s using s3 as a source and its different components
In order to integrate Gitlabs with Code Pipeline, the GitLab gives us a provision to do this by using the .gitlab-ci.yml file. The GitLab file should include the script with the required set of IAM Permission to S3 bucket which allows users to push the Object to s3 bucket. The file should be included under the project repository.
Therefore, whenever the developer commits the code into the GitLab’s repository with the use of GitLab-ci.yaml file which contains the script to push the repo code to the desired s3 bucket. Once the Object is uploaded into the s3 bucket the Code Pipeline has an event that is S3 as a source which in turn helps to trigger the pipeline and later executes the rest of the phases for the code pipeline will be executed.
Steps
Create the S3 Bucket. This bucket will be used to push the object.
Create the gitlab yaml file which includes the below scripts.
The above sample contains the variables and script. Script bascially includes the logic to upload the code to S3 bucket. Gitlabs provides the pre-defined variables like CI_COMMIT_SHORT_SHA. This commit code can be used to reterive the last commit hash made to the repository. We can used this commit hash code as a tagging to the bucket.
- Create the IAM user which has permissions permisson to S3 bucket to put object as well as put object tagging.We are adding tag to a bucket with the commit hash code which help us in order to back trace any request in case of any issues.
- Configure the AccesskeyID, AccessSecretkey in Gitlabs under Secret Variables.AWS Cli will automatically consume these varaibles whenever the scripts executes in order to upload the files as a zip to S3 bucket.
- At last create the Codepipeline with S3 as source with Build and deploy steps.
Conclussion:
This is one of the easist techique which overcomes the challenges to setup end to end CICD pipeline quickly.
Top comments (0)