ww664853070 1 year ago
parent
commit
7fbf968551
  1. 47
      api/Dockerfile
  2. 37
      jenkinsfile_poms_api
  3. 41
      jenkinsfile_poms_web
  4. 10
      web/Dockerfile

47
api/Dockerfile

@ -1,38 +1,31 @@
# FROM repository.anxinyun.cn/devops/node:12-dev as builder
# COPY . /var/app
# WORKDIR /var/app
# EXPOSE 8080
# RUN npm config set registry=http://10.8.30.22:7000
# RUN echo "{\"time\":\"$BUILD_TIMESTAMP\",\"build\": \"$BUILD_NUMBER\",\"revision\": \"$SVN_REVISION_1\",\"URL\":\"$SVN_URL_1\"}" > version.json
# RUN npm cache clean -f
# RUN rm -rf package-lock.json
# RUN npm install --registry http://10.8.30.22:7000
# FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node:12
# COPY --from=builder --chown=node /var/app /home/node/app
# WORKDIR /home/node/app
FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node:12-dev as builder
COPY ./api/ /var/app
WORKDIR /var/app
EXPOSE 8080
RUN npm config set registry=https://nexus.ngaiot.com/repository/fs-npm/
RUN echo "{\"time\":\"$BUILD_TIMESTAMP\",\"build\": \"$BUILD_NUMBER\",\"revision\": \"$SVN_REVISION_1\",\"URL\":\"$SVN_URL_1\"}" > version.json
RUN npm cache clean -f
RUN rm -rf package-lock.json
RUN npm install --registry https://nexus.ngaiot.com/repository/fs-npm/
# CMD ["node", "server.js"]
FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node:12
COPY --from=builder --chown=node /var/app /home/node/app
WORKDIR /home/node/app
CMD ["node", "server.js"]
# 旧版本构建方式
FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2
# FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2
MAINTAINER liuxinyi "liu.xinyi@free-sun.com.cn"
# MAINTAINER liuxinyi "liu.xinyi@free-sun.com.cn"
COPY . /var/app
# COPY . /var/app
WORKDIR /var/app
# WORKDIR /var/app
RUN npm cache clean -f && npm install --production --force --registry http://10.8.30.22:7000
# RUN npm cache clean -f && npm install --production --force --registry http://10.8.30.22:7000
RUN rm -rf package-lock.json
# RUN rm -rf package-lock.json
CMD [ "node", "server.js" ]
# CMD [ "node", "server.js" ]

37
jenkinsfile_poms_api

@ -1,18 +1,21 @@
pipeline {
agent {
node{
label 'jnlp-slave'
}
}
stages {
stage('Testing hrm api......') {
steps {
buildName '#${BUILD_NUMBER} ~/pep/${JOB_NAME}:${IMAGE_VERSION}'
buildDescription 'harbor.anxinyun.cn/pep/${JOB_NAME}:${IMAGE_VERSION}'
sh 'nerdctl build -t harbor.anxinyun.cn/pep/${JOB_NAME}:${IMAGE_VERSION} ./api'
sh 'nerdctl push harbor.anxinyun.cn/pep/${JOB_NAME}:${IMAGE_VERSION}'
}
}
}
podTemplate {
node('pod-templ-jenkins-slave-common') {
env.IMAGE_NAME = "${IOT_IMAGES_REGISTRY}/${pep}/${JOB_NAME}"
env.IMAGE_NAME_SHORT = "${pep}/${JOB_NAME}"
env.CODE_ADDR = "${GIT_ADDRESS}/free-sun/HumanResource.git"
stage('Run shell') {
git branch: 'master', credentialsId: 'gitea-builder', url: "${CODE_ADDR}"
container('image-builder') {
sh'''
/kaniko/executor --context=${BUILD_WORKSPACE} --dockerfile=./api/Dockerfile --destination=${IMAGE_NAME}:${IMAGE_VERSION} --cache=false --cleanup
'''
}
buildName "${IMAGE_NAME_SHORT}:${IMAGE_VERSION}"
buildDescription "${IMAGE_NAME}:${IMAGE_VERSION}"
}
}
}

41
jenkinsfile_poms_web

@ -1,18 +1,25 @@
pipeline {
agent {
node{
label 'jnlp-slave'
}
}
stages {
stage('Testing hrm-web ......') {
steps {
buildName "#${BUILD_NUMBER} ~/pep/${JOB_NAME}:${IMAGE_VERSION}"
buildDescription "harbor.anxinyun.cn/pep/${JOB_NAME}:${IMAGE_VERSION}"
sh 'nerdctl build -t harbor.anxinyun.cn/pep/${JOB_NAME}:${IMAGE_VERSION} ./web'
sh 'nerdctl push harbor.anxinyun.cn/pep/${JOB_NAME}:${IMAGE_VERSION}'
}
}
}
podTemplate {
node('pod-templ-jenkins-slave-common') {
env.IMAGE_NAME = "${IOT_IMAGES_REGISTRY}/${PEP}/${JOB_NAME}"
env.IMAGE_NAME_SHORT = "${PEP}/${JOB_NAME}"
env.CODE_ADDR = "${GIT_ADDRESS}/free-sun/HumanResource.git"
stage('Run shell') {
git branch: 'master', credentialsId: 'gitea-builder', url: "${CODE_ADDR}"
container('image-builder') {
sh'''
pwd
ls -al
/kaniko/executor --context=${BUILD_WORKSPACE} --dockerfile=./web/Dockerfile --destination=${IMAGE_NAME}:${IMAGE_VERSION} --cache=false --cleanup
'''
}
buildName "${IMAGE_NAME_SHORT}:${IMAGE_VERSION}"
buildDescription "${IMAGE_NAME}:${IMAGE_VERSION}"
}
}
}

10
web/Dockerfile

@ -28,18 +28,18 @@
FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node:12-dev as builder
COPY . /var/app
COPY ./web/ /var/app
WORKDIR /var/app
EXPOSE 8080
RUN npm config set registry=http://10.8.30.22:7000
RUN npm config set registry=https://nexus.ngaiot.com/repository/fs-npm/
RUN echo "{\"time\":\"$BUILD_TIMESTAMP\",\"build\": \"$BUILD_NUMBER\",\"revision\": \"$SVN_REVISION_1\",\"URL\":\"$SVN_URL_1\"}" > version.json
RUN npm cache clean -f
RUN npm install --registry http://10.8.30.22:7000
RUN npm install --registry https://nexus.ngaiot.com/repository/fs-npm/
RUN npm run build
RUN rm -rf client/src
RUN rm -rf node_modules
RUN npm install --production --force --registry http://10.8.30.22:7000
FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node-16:7.22-06-20
RUN npm install --production --force --registry https://nexus.ngaiot.com/repository/fs-npm/
FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node:12
COPY --from=builder --chown=node /var/app /home/node/app
WORKDIR /home/node/app
CMD ["node", "server.js"]
Loading…
Cancel
Save