fix ecr authentication config
This commit is contained in:
13
Jenkinsfile
vendored
13
Jenkinsfile
vendored
@@ -29,7 +29,14 @@ pipeline {
|
|||||||
script: "terraform output cluster_url",
|
script: "terraform output cluster_url",
|
||||||
returnStdout: true
|
returnStdout: true
|
||||||
)
|
)
|
||||||
sh "ls"
|
env.REPO_USER = sh(
|
||||||
|
script: "terraform output ecr_user_name",
|
||||||
|
returnStdout: true
|
||||||
|
)
|
||||||
|
env.REPO_PWD = sh(
|
||||||
|
script: "terraform output ecr_user_password",
|
||||||
|
returnStdout: true
|
||||||
|
)
|
||||||
env.KUBECONFIG="./kubeconfig.yaml"
|
env.KUBECONFIG="./kubeconfig.yaml"
|
||||||
sh "kubectl get node"
|
sh "kubectl get node"
|
||||||
}
|
}
|
||||||
@@ -61,14 +68,12 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "building the docker image..."
|
echo "building the docker image..."
|
||||||
withCredentials([usernamePassword(credentialsId: 'ecr-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
||||||
sh "docker build -t ${DOCKER_REPO_URL}:${IMAGE_NAME} ."
|
sh "docker build -t ${DOCKER_REPO_URL}:${IMAGE_NAME} ."
|
||||||
sh "echo $PASS | docker login -u $USER --password-stdin ${DOCKER_REPO_URL}"
|
sh "echo ${REPO_PWD} | docker login -u ${REPO_USER} --password-stdin ${DOCKER_REPO_URL}"
|
||||||
sh "docker push ${DOCKER_REPO_URL}:${IMAGE_NAME}"
|
sh "docker push ${DOCKER_REPO_URL}:${IMAGE_NAME}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
stage('deploy') {
|
stage('deploy') {
|
||||||
environment {
|
environment {
|
||||||
APP_NAME = 'java-maven-app'
|
APP_NAME = 'java-maven-app'
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ resource "aws_ecr_repository" "myapp-repo" {
|
|||||||
scan_on_push = true
|
scan_on_push = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "aws_ecr_authorization_token" "token" {}
|
||||||
@@ -9,3 +9,12 @@ output cluster_url {
|
|||||||
output kubeconfig {
|
output kubeconfig {
|
||||||
value = "module.eks.kubeconfig"
|
value = "module.eks.kubeconfig"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output ecr_user_name {
|
||||||
|
value = data.aws_ecr_authorization_token.token.user_name
|
||||||
|
}
|
||||||
|
|
||||||
|
output ecr_user_password {
|
||||||
|
value = data.aws_ecr_authorization_token.token.password
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user