From d35731badaa772559f223e1a3adbfb97dad06316 Mon Sep 17 00:00:00 2001 From: lenape Date: Sat, 12 Jul 2025 09:49:26 +0000 Subject: [PATCH] automated terminal push --- Jenkinsfile | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5f3343e..d038a86 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,10 +5,11 @@ pipeline { GITEA_CREDS = '52ee0829-6e65-4951-925b-4186254c3f21' SONAR_HOST = 'https://sonar.jacquesingram.online' SONAR_TOKEN = credentials('sonar-token') - ARTIFACTORY_URL = 'https://art.jacquesingram.online/artifactory/nvhi-atsila-docker' - ARTIFACTORY_CREDS = 'artifactory-api' AWS_CRED_ID = 'aws-ci' + AWS_ACCOUNT_ID = credentials('AWS_ACCOUNT_ID') AWS_REGION = 'us-east-2' + ECR_REPO = 'nvhi-atsila-microservice' + TF_BACKEND_BUCKET = 'nvhi-atsila-tf-state' TF_BACKEND_PREFIX = 'ecs/terraform.tfstate' TF_DDB_TABLE = 'nvhi-atsila-locks' @@ -21,7 +22,7 @@ pipeline { TF_VAR_key_pair_name = 'nvhi-atsila-deployer' TF_VAR_jenkins_ip_cidr = "${JENKINS_SSH_CIDR}" - IMAGE_NAME = 'lenape/nvhi-atsila-microservice' + IMAGE_NAME = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}" IMAGE_TAG = "v1.0.${BUILD_NUMBER}" } stages { @@ -33,7 +34,6 @@ pipeline { stage('SonarQube Scan') { steps { script { - // Resolve the SonarQube Scanner installation def scannerHome = tool 'SonarQubeScanner' withSonarQubeEnv('SonarQube') { sh """ @@ -45,19 +45,35 @@ pipeline { } } } + stage('Login to ECR') { + steps { + withCredentials([[ + $class: 'AmazonWebServicesCredentialsBinding', + credentialsId: env.AWS_CRED_ID + ]]) { + sh ''' + aws ecr get-login-password --region ${AWS_REGION} \ + | docker login \ + --username AWS \ + --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com + ''' + } + } + } stage('Build & Push Docker Image') { steps { script { - docker.withRegistry(env.ARTIFACTORY_URL, env.ARTIFACTORY_CREDS) { - def img = docker.build("${IMAGE_NAME}:${IMAGE_TAG}") - img.push() - } + def img = docker.build("${IMAGE_NAME}:${IMAGE_TAG}") + img.push() } } } stage('Terraform Init & Apply') { steps { - withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) { + withCredentials([[ + $class: 'AmazonWebServicesCredentialsBinding', + credentialsId: env.AWS_CRED_ID + ]]) { dir('terraform') { sh """ terraform init \ @@ -95,14 +111,17 @@ pipeline { } stage('Register & Deploy to ECS') { steps { - withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) { + withCredentials([[ + $class: 'AmazonWebServicesCredentialsBinding', + credentialsId: env.AWS_CRED_ID + ]]) { sh """ aws ecs register-task-definition \ --family ${TF_VAR_cluster_name} \ --network-mode bridge \ --container-definitions '[{ "name":"health-workload", - "image":"${ARTIFACTORY_URL}/${IMAGE_NAME}:${IMAGE_TAG}", + "image":"${IMAGE_NAME}:${IMAGE_TAG}", "essential":true, "portMappings":[{"containerPort":8080,"hostPort":8080}] }]' \ @@ -118,4 +137,4 @@ pipeline { } } } -} \ No newline at end of file +}