automated terminal push

This commit is contained in:
lenape
2025-07-12 09:49:26 +00:00
parent 790e8e65f7
commit d35731bada

37
Jenkinsfile vendored
View File

@@ -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()
}
}
}
}
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}]
}]' \