前端配置文件介绍
1、Dockerfile
文件说明:
Dockerfile 是用来构建 Docker 镜像的构建文件,是由一系列(构建镜像所需的)命令和参数构成的脚本,文件没有后缀,名字就是Dockerfile,文件中 # 表示注释,第一条命令必需是FROM,作用是指定在哪个基础镜像上创建镜像
文件内容:
FROM harbor.geely.com/library/nginx:lastest
WORKDIR /usr/share/nginx/html
COPY deploy/default.conf /etc/nginx/conf.d/ COPY dist/ /usr/share/nginx/html
EXPOSE 80
2、default.conf
文件说明:
nginx配置文件,文件放在Dockerfile里指定的目录下(如:根目录下 deploy/default.conf),该文件只需修改反向代理地址(proxy_pass)即可,其他部分可沿用
文件内容:
server { listen 80; server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# api接口对应的代理地址(任何未知请求 (没有匹配到静态文件的请求) 代理到http:×××××××)
location /api {
proxy_pass http://10.34.76.244:31001/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache‘s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
# deny all;
#}
}
3、Jenkinsfile
文件说明:
Jenkinsfile 是 Jenkins 2.x 核心特性 Pipeline 的脚本,由Groovy语言实现。Jenkinsfile一般是放在项目根目录,随项目一起受源代码管理软件控制,用于编写pipeline,自动化构建部署
文件内容:
pipeline { // 设置Jenkins agent (Jenkins内置了 4 种类型的 podTemplate : base、nodejs、maven、go) agent { node { label ‘nodejs‘ } }
parameters {
string(name:‘TAG_NAME‘,defaultValue: ‘‘,description:‘‘)
}
// 配置信息,不同项目根据实际情况进行配置,不懂咨询曹少哲
environment {
// DOCKER连接密钥
DOCKER_CREDENTIAL_ID = ‘dockerhub-admin‘
// GITHUB连接密钥
GITHUB_CREDENTIAL_ID = ‘gitlab-csz‘
// K8S的配置密钥名称
KUBECONFIG_CREDENTIAL_ID = ‘kubeconfig-test‘
// 仓库的域名
REGISTRY = ‘harbor.geely.com‘
// 仓库的项目名称
DOCKERHUB_NAMESPACE = ‘library‘
// 需要发布的git分支名称 -- 需修改
BRANCH_NAME = ‘dev_0.11v‘
// K8S的项目名称 -- 需修改
K8S_NAMESPACES = ‘tms-project‘
// 当前应用名称 -- 需修改
APP_NAME = ‘ils-tms-web‘
// 组件名称 -- 需修改
COMPONENT = ‘ils-tms-web‘
// 组件/项目的划分
TIER = ‘frontend‘
}
stages {
// 从git拉代码
stage (‘checkout scm‘) {
steps {
checkout(scm)
}
}
// 编译打包
stage (‘npm install & build‘) {
steps {
container (‘nodejs‘) {
sh ‘npm -v‘
sh ‘npm config set registry http://10.34.252.90:8081/repository/npm-szzx/‘
//sh ‘npm config set registry http://10.34.252.90:8081/repository/npm-public/‘
//sh ‘npm install --production‘
sh ‘npm install‘
sh ‘npm run build‘
}
}
}
// 构建镜像:根据Dockerfile中的指令构建镜像,并推送到harbor私有仓库
stage (‘docker build & push‘) {
steps {
container (‘nodejs‘) {
sh ‘docker build --no-cache -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .‘
withCredentials([usernamePassword(passwordVariable : ‘DOCKER_PASSWORD‘ ,usernameVariable : ‘DOCKER_USERNAME‘ ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) {
sh ‘echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin‘
sh ‘docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER‘
}
}
}
}
// 推送latest镜像
stage(‘push latest‘){
steps{
container (‘nodejs‘) {
sh ‘docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ‘
sh ‘docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ‘
}
}
}
// K8S部署:拉取镜像,部署应用,完成服务的更新与重启;
stage(‘deploy to K8S‘) {
steps {
kubernetesDeploy(configs: ‘deploy/dev-test/**‘, enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
}
原文:https://www.cnblogs.com/blogsofMayw/p/14678499.html