상세 컨텐츠

본문 제목

web-was 구축해보기 (nginx-proxy) -(3)

web-application 시스템 구축

by drogva 2024. 4. 7. 00:29

본문

-eks 에서 자동화 빌드하고 배포해 포기

젠킨슨으로  빌드하고 argo 를 통해 배포해보기 

 

nginx 도커파일은 바로 도커이미지로 빌드 할 수 있으므로 kaniko 를 통해 빌드

jar 파일은 jib 를 통해 빌드

 

젠킨슨 빠이쁘라인

 

 

pipeline {
    options {
        timeout(time: 1, unit: 'HOURS')
    }

    environment {
        DOCKER_REPOSITORY = 'xxxxxxxxxxxxx.dkr.ecr.ap-northeast-2.amazonaws.com/drogva'
        TAG = 'page'
        KUBE_CREDENTIAL_ID = '5ff9cd68-e734-4bd9-9053-8041ae5f2648'
        AWS_CLI_PATH = '/var/jenkins_home/aws-cli/v2/current/bin'
        AWS_REGION = 'ap-northeast-2'
        ECR_URL = 'xxxxxxxxxxxxx.dkr.ecr.ap-northeast-2.amazonaws.com'
    }

    agent {
        kubernetes {
            yaml '''
            apiVersion: v1
            kind: Pod
            spec:
              containers:
                - name: kaniko
                  image: gcr.io/kaniko-project/executor:debug
                  command: ['sleep']
                  args: ['infinity']
                  volumeMounts:
                    - name: registry-credentials
                      mountPath: /kaniko/.docker
                  volumes:
                    - name: registry-credentials
                      secret:
                        secretName: ecr-registry-secret
                      items:
                        - key: .dockerconfigjson
                          path: config.json
            '''
        }
    }

    stages {
        stage('Checkout Gradle Repo - nginx') {
            steps {
                git credentialsId: 'drogva', url: 'https://github.com/drogva/nginx.git', branch: 'main'
            }
        }

        stage('Push Docker image to ECR - nginx') {
            steps {
                container('kaniko') {
                    script {
                        withCredentials([string(credentialsId: KUBE_CREDENTIAL_ID, variable: 'KUBE_CONFIG')]) {
                            sh '''
                            /kaniko/executor --context dir://$(pwd) --dockerfile=$(pwd)/Dockerfile --destination=${DOCKER_REPOSITORY}:${TAG}
                            '''
                        }
                    }
                }
            }
        }

        stage('Checkout Gradle Repo - jen') {
            steps {
                git credentialsId: 'drogva', url: 'https://github.com/drogva/jen.git', branch: 'main'
            }
        }

        stage('Set Execute Permission for Gradle Wrapper') {
            steps {
                script {
                    sh 'chmod +x ./gradlew'
                }
            }
        }

        stage('Login to ECR') {
            steps {
                script {
                    withAWS(region: "ap-northeast-2", credentials: "aws") {
                        ecrLogin()
                    }
                }
            }
        }

        stage('Build and Push image using Jib') {
            steps {
                script {
                    withAWS(region: "ap-northeast-2" , credentials: "aws") {
                        env.AWS_REGION = 'ap-northeast-2'
                        echo 'jib build and push'
                        def ecrLoginResult = ecrLogin()
                        env.ECR_PASSWORD = ecrLoginResult.split("-p ")[1].split(" ")[0]
                        sh "./gradlew jib -Pprofile=prod -Djib.to.image=xxxxxxxxxxxxx.dkr.ecr.ap-northeast-2.amazonaws.com/drogva:hi -Djib.to.auth.username=AWS -Djib.to.auth.password=${ECR_PASSWORD}"
                    }
                }
            }
        }
    }
}








https://github.com/drogva/nginx   -nginx 역방향 프록시 서버

 

GitHub - drogva/nginx

Contribute to drogva/nginx development by creating an account on GitHub.

github.com

 

 

 

https://github.com/drogva/jen     - gradle 프로젝트  - 스프링부트 프레임워크 -rds 연동

 

GitHub - drogva/jen

Contribute to drogva/jen development by creating an account on GitHub.

github.com

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

관련글 더보기