Add container build jpl
Change-Id: I03572a466c77ea539dc8e1587570531fd0b091b1
Signed-off-by: Saheer Babu <saheer.babu@arm.com>
diff --git a/ci/container-build.jpl b/ci/container-build.jpl
new file mode 100644
index 0000000..cdf7b91
--- /dev/null
+++ b/ci/container-build.jpl
@@ -0,0 +1,92 @@
+pipeline {
+ agent {
+ kubernetes {
+ yaml """
+apiVersion: v1
+kind: Pod
+spec:
+ volumes:
+ - name: docker-auth
+ emptyDir: {}
+
+ containers:
+ - name: awscli
+ image: amazon/aws-cli
+ command: ['cat']
+ tty: true
+ volumeMounts:
+ - name: docker-auth
+ mountPath: /root/.docker
+
+ - name: buildah
+ image: quay.io/buildah/stable
+ command: ['cat']
+ tty: true
+ env:
+ - name: STORAGE_DRIVER
+ value: vfs
+ volumeMounts:
+ - name: docker-auth
+ mountPath: /root/.docker
+"""
+ defaultContainer 'buildah'
+ }
+ }
+
+ environment {
+ AWS_REGION = "eu-west-1"
+ ECR_REGISTRY = "123456789012.dkr.ecr.eu-west-1.amazonaws.com"
+ }
+
+ stages {
+ stage('Build and Push Multiple Images') {
+ steps {
+ script {
+ def images = ['app1', 'app2', 'base']
+
+ for (img in images) {
+ stage("Build and Push ${img}") {
+ // Clone repo and build the image
+ container('buildah') {
+ checkout scm
+ sh "env"
+ sh """
+ echo "[INFO] Cloning repo..."
+ env
+ gitRepo="${GIT_BASE_URL}${env.GERRIT_PROJECT}"
+ git clone ${gitRepo} repo
+ cd /repo
+
+ echo "[INFO] Building image: ${img}"
+ buildah bud -t ${img} -f Dockerfile.${img} .
+
+ echo "[INFO] Tagging image"
+ buildah tag ${img} ${ECR_REGISTRY}/${img}:latest
+ """
+ }
+
+ // Dynamic login before push
+ container('awscli') {
+ withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-creds']]) {
+ sh """
+ echo "[INFO] Logging into ECR before pushing ${img}"
+ aws ecr get-login-password --region $AWS_REGION | \
+ docker login --username AWS --password-stdin $ECR_REGISTRY
+ """
+ }
+ }
+
+ // Push after dynamic login
+ container('buildah') {
+ sh """
+ echo "[INFO] Pushing image: ${img}"
+ buildah push ${ECR_REGISTRY}/${img}:latest
+ """
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file