automated terminal push
This commit is contained in:
43
Jenkinsfile
vendored
43
Jenkinsfile
vendored
@@ -5,10 +5,11 @@ pipeline {
|
|||||||
GITEA_CREDS = '52ee0829-6e65-4951-925b-4186254c3f21'
|
GITEA_CREDS = '52ee0829-6e65-4951-925b-4186254c3f21'
|
||||||
SONAR_HOST = 'https://sonar.jacquesingram.online'
|
SONAR_HOST = 'https://sonar.jacquesingram.online'
|
||||||
SONAR_TOKEN = credentials('sonar-token')
|
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_CRED_ID = 'aws-ci'
|
||||||
|
AWS_ACCOUNT_ID = credentials('AWS_ACCOUNT_ID')
|
||||||
AWS_REGION = 'us-east-2'
|
AWS_REGION = 'us-east-2'
|
||||||
|
ECR_REPO = 'nvhi-atsila-microservice'
|
||||||
|
|
||||||
TF_BACKEND_BUCKET = 'nvhi-atsila-tf-state'
|
TF_BACKEND_BUCKET = 'nvhi-atsila-tf-state'
|
||||||
TF_BACKEND_PREFIX = 'ecs/terraform.tfstate'
|
TF_BACKEND_PREFIX = 'ecs/terraform.tfstate'
|
||||||
TF_DDB_TABLE = 'nvhi-atsila-locks'
|
TF_DDB_TABLE = 'nvhi-atsila-locks'
|
||||||
@@ -21,7 +22,7 @@ pipeline {
|
|||||||
TF_VAR_key_pair_name = 'nvhi-atsila-deployer'
|
TF_VAR_key_pair_name = 'nvhi-atsila-deployer'
|
||||||
TF_VAR_jenkins_ip_cidr = "${JENKINS_SSH_CIDR}"
|
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}"
|
IMAGE_TAG = "v1.0.${BUILD_NUMBER}"
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
@@ -33,7 +34,6 @@ pipeline {
|
|||||||
stage('SonarQube Scan') {
|
stage('SonarQube Scan') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// Resolve the SonarQube Scanner installation
|
|
||||||
def scannerHome = tool 'SonarQubeScanner'
|
def scannerHome = tool 'SonarQubeScanner'
|
||||||
withSonarQubeEnv('SonarQube') {
|
withSonarQubeEnv('SonarQube') {
|
||||||
sh """
|
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') {
|
stage('Build & Push Docker Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
docker.withRegistry(env.ARTIFACTORY_URL, env.ARTIFACTORY_CREDS) {
|
def img = docker.build("${IMAGE_NAME}:${IMAGE_TAG}")
|
||||||
def img = docker.build("${IMAGE_NAME}:${IMAGE_TAG}")
|
img.push()
|
||||||
img.push()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Terraform Init & Apply') {
|
stage('Terraform Init & Apply') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) {
|
withCredentials([[
|
||||||
|
$class: 'AmazonWebServicesCredentialsBinding',
|
||||||
|
credentialsId: env.AWS_CRED_ID
|
||||||
|
]]) {
|
||||||
dir('terraform') {
|
dir('terraform') {
|
||||||
sh """
|
sh """
|
||||||
terraform init \
|
terraform init \
|
||||||
@@ -95,14 +111,17 @@ pipeline {
|
|||||||
}
|
}
|
||||||
stage('Register & Deploy to ECS') {
|
stage('Register & Deploy to ECS') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) {
|
withCredentials([[
|
||||||
|
$class: 'AmazonWebServicesCredentialsBinding',
|
||||||
|
credentialsId: env.AWS_CRED_ID
|
||||||
|
]]) {
|
||||||
sh """
|
sh """
|
||||||
aws ecs register-task-definition \
|
aws ecs register-task-definition \
|
||||||
--family ${TF_VAR_cluster_name} \
|
--family ${TF_VAR_cluster_name} \
|
||||||
--network-mode bridge \
|
--network-mode bridge \
|
||||||
--container-definitions '[{
|
--container-definitions '[{
|
||||||
"name":"health-workload",
|
"name":"health-workload",
|
||||||
"image":"${ARTIFACTORY_URL}/${IMAGE_NAME}:${IMAGE_TAG}",
|
"image":"${IMAGE_NAME}:${IMAGE_TAG}",
|
||||||
"essential":true,
|
"essential":true,
|
||||||
"portMappings":[{"containerPort":8080,"hostPort":8080}]
|
"portMappings":[{"containerPort":8080,"hostPort":8080}]
|
||||||
}]' \
|
}]' \
|
||||||
@@ -118,4 +137,4 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user