k8s
This commit is contained in:
15
frontend/admin/DockerfileK8s
Normal file
15
frontend/admin/DockerfileK8s
Normal file
@@ -0,0 +1,15 @@
|
||||
# admin
|
||||
FROM node:14.8.0-alpine
|
||||
|
||||
ENV APP_TYPE="prodk8slg"
|
||||
ENV APP_HOME=/usr/app/
|
||||
|
||||
RUN mkdir -p ${APP_HOME}
|
||||
WORKDIR $APP_HOME
|
||||
|
||||
COPY package*.json .
|
||||
RUN npm install
|
||||
COPY . .
|
||||
RUN npm run build:${APP_TYPE}
|
||||
|
||||
CMD npm run start:${APP_TYPE}
|
||||
3
frontend/admin/DockerfileK8sPipeline
Normal file
3
frontend/admin/DockerfileK8sPipeline
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM node:14.8.0-alpine
|
||||
COPY ./ ./
|
||||
CMD ["npm", "run", "start:prodk8slg"]
|
||||
51
frontend/admin/Jenkinsfile
vendored
Normal file
51
frontend/admin/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// https://github.com/jenkinsci/kubernetes-plugin
|
||||
podTemplate(
|
||||
name: "jenkins-slave",
|
||||
serviceAccount: "jenkins",
|
||||
containers: [
|
||||
containerTemplate(name: 'nodejs', image: 'node:14.8.0-alpine', ttyEnabled: true, command: 'cat'),
|
||||
containerTemplate(name: "docker", image: "docker", ttyEnabled: true, command: 'cat'),
|
||||
containerTemplate(name: "kubectl", image: "lachlanevenson/k8s-kubectl:v1.17.5", ttyEnabled: true, command: 'cat')
|
||||
],
|
||||
volumes: [
|
||||
hostPathVolume(mountPath: "/var/run/docker.sock", hostPath: "/var/run/docker.sock")
|
||||
]
|
||||
) {
|
||||
node(POD_LABEL) {
|
||||
def now = java.time.LocalDateTime.now()
|
||||
def projectId = "frontend-admin" // 프로젝트 아이디
|
||||
|
||||
// docker
|
||||
def dockerhubCredentialsId = "username-password-dockerhub" // 젠킨스 도커허브 자격증명
|
||||
def dockerImage = "egovframe/egovframe-msa-edu-${projectId}" // 도커허브 이미지
|
||||
def dockerImageTag = "latest" // 도커허브 이미지 태그
|
||||
|
||||
stage("git") {
|
||||
checkout scm
|
||||
}
|
||||
|
||||
stage("nodejs") {
|
||||
container("nodejs") {
|
||||
sh "npm install"
|
||||
sh "npm run build:prodk8slg"
|
||||
}
|
||||
}
|
||||
|
||||
stage("docker") {
|
||||
container("docker") {
|
||||
withCredentials([usernamePassword(credentialsId: "${dockerhubCredentialsId}", passwordVariable: "password", usernameVariable: "username")]) {
|
||||
sh "docker login -u $username -p $password"
|
||||
sh "docker build -f DockerfileK8sPipeline -t ${dockerImage}:${dockerImageTag} ."
|
||||
sh "docker push ${dockerImage}:${dockerImageTag}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage( "kubernetes" ) {
|
||||
container("kubectl") {
|
||||
sh "kubectl rollout restart deployment ${projectId}-deployment"
|
||||
sh "kubectl annotate deployment.apps/${projectId}-deployment kubernetes.io/change-cause='The image was updated at ${now} by ${env.BUILD_TAG}.'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@
|
||||
"start:prodlg": "env-cmd -f ./.env.production-lg node dist/index.js",
|
||||
"build:prodsm": "env-cmd -f ./.env.production-sm npm run build:next && npm run build:server",
|
||||
"start:prodsm": "env-cmd -f ./.env.production-sm node dist/index.js",
|
||||
"build:prodk8slg": "env-cmd -f ./.env.production-k8s-lg npm run build:next && npm run build:server",
|
||||
"start:prodk8slg": "env-cmd -f ./.env.production-k8s-lg node dist/index.js",
|
||||
"build:prodk8ssm": "env-cmd -f ./.env.production-k8s-sm npm run build:next && npm run build:server",
|
||||
"start:prodk8ssm": "env-cmd -f ./.env.production-k8s-sm node dist/index.js",
|
||||
"start": "NODE_ENV=production node dist/index.js",
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user