In the world of continuous integration and deployment, automation is key. Deploying applications efficiently and reliably requires seamless coordination between different components of your development stack. One such critical integration is between AWS CodeCommit and Kubernetes, specifically using ArgoCD for service deployment. In this article, we’ll explore how a Python script, utilizing AWS CodeCommit API, can simplify and enhance your Kubernetes service deployment workflow.
Why AWS CodeCommit and Kubernetes?
AWS CodeCommit provides a scalable, fully managed source control service that makes it easy for teams to host secure and highly available Git repositories. On the other hand, Kubernetes, an open-source container orchestration platform, simplifies deploying, managing, and scaling containerised applications. Combining these services offers a powerful environment for managing your codebase and deploying applications at scale.
Introducing ArgoCD
ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It uses Git repositories as the source of truth for declarative infrastructure and applications definitions. With ArgoCD, you can automate the deployment of applications to your Kubernetes cluster, ensuring consistency and reliability.
Python Script for Docker Tag Update
Sample value.yaml
dockerTag: 9
dockerImage: registry.io/linuxserver/sonarr
version: 1.0.0import boto3
import base64
import sys
try :
repository_name = sys.argv[1]
branch_name =sys.argv[2]
file_path = sys.argv[3]
buildNumber=sys.argv[4]
client = boto3.client('codecommit')
response = client.get_file(
repositoryName=repository_name,
commitSpecifier=branch_name,
filePath=file_path
)
file_content =response['fileContent'].decode()
comitId=response['commitId']
new_first_line = "dockerTag: "+buildNumber
# Replace the first line in the file content
lines = file_content.split('\n')
lines[0] = new_first_line
updated_content = '\n'.join(lines)
# Push the updated file back to the repository
client.put_file(
repositoryName=repository_name,
branchName=branch_name,
fileContent=updated_content,
filePath=file_path,
fileMode='NORMAL', # or 'EXECUTABLE' if needed
parentCommitId=comitId,
commitMessage="updated value.yaml with = "+updated_content,
name="jenkins-script",
email="jenkins-script"
)
except Exception as e:
print(f"HelmUpdator script failed with:- {e}")Sample jenkins pipeline script
pipeline {
environment {
registry = ""
registry_image_repo = ""
registryCredential = ""
imagename = ''
dockerImage = ''
BUILD_NUMBER = "${BUILD_NUMBER}"
repositoryName=""
filePath="repo-subfolder/values.yaml"
branchName=""
}
agent any
stages {
stage('checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'codecommit_cred', url: 'paste-repo-url']]])
}
}
stage('Building image') {
steps{
script {
//
}
}
}
stage('Deploy Image') {
steps{
script {
//----push image--container registory
}
}
}
stage('helm-update'){
steps{
sh """
python3 /scripts/helmUpdator.py ${repositoryName} \
${branchName} \
${filepath} \
${BUILD_NUMBER}
"""
}
}
}
}Ditch manual deployments and embrace automation! This guide leverages a powerful Python script and AWS CodeCommit to streamline your Kubernetes service deployments. Achieve effortless deployment automation, improve consistency, and accelerate delivery cycles. Take your DevOps game to the next level — start automating today




