fix
This commit is contained in:
parent
851e4d9cbf
commit
25ec653e2d
23
Dockerfile
23
Dockerfile
|
@ -1,17 +1,14 @@
|
|||
FROM golang:1.20.2-alpine3.17 AS builder
|
||||
FROM golang:1.21-alpine3.18 as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
LABEL stage=gobuilder
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOARCH amd64
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
COPY . .
|
||||
COPY etc/ /app/
|
||||
RUN go mod download
|
||||
RUN go build -o /app/pcm-participant-kubernetes /app/main.go
|
||||
|
||||
RUN go env -w GO111MODULE=on \
|
||||
&& go env -w GOPROXY=https://goproxy.cn,direct \
|
||||
&& go env -w CGO_ENABLED=0 \
|
||||
&& go env \
|
||||
&& go mod tidy \
|
||||
&& go build -o pcm-kubernetes .
|
||||
|
||||
FROM alpine:3.16.2
|
||||
WORKDIR /app
|
||||
|
@ -24,11 +21,11 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repos
|
|||
apk add --update tzdata && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
COPY --from=builder /app/pcm-participant-kubernetes .
|
||||
COPY etc/config.yaml /app/etc/
|
||||
COPY --from=0 /app/pcm-kubernetes ./
|
||||
COPY --from=0 /app/config.yaml ./
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
EXPOSE 2003
|
||||
|
||||
ENTRYPOINT ./pcm-participant-kubernetes -f etc/config.yaml
|
||||
ENTRYPOINT ./pcm-kubernetes -c config.yaml
|
|
@ -1,72 +0,0 @@
|
|||
def JOB_NAME = "${env.JOB_NAME}"
|
||||
def BUILD_NUMBER = "${env.BUILD_NUMBER}"
|
||||
def label = "jenkins-${JOB_NAME}-${BUILD_NUMBER}-${UUID.randomUUID().toString()}"
|
||||
def secret_name = "harbor-auth"
|
||||
|
||||
podTemplate(label: label, containers: [
|
||||
containerTemplate(name: 'golang', image: 'golang:1.18.5-alpine3.16', command: 'cat', ttyEnabled: true),
|
||||
containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
|
||||
containerTemplate(name: 'kubectl', image: 'jcce/kubectl:1.23.7', command: 'cat', ttyEnabled: true)
|
||||
], serviceAccount: 'jenkins', volumes: [
|
||||
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
|
||||
]) {
|
||||
node(label) {
|
||||
def myRepo = checkout scm
|
||||
// 获取 git commit id 作为镜像标签
|
||||
def imageTag = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||
// 仓库地址
|
||||
def registryUrl = "hub.jcce.dev:18443/repository/docker-hub"
|
||||
def imageEndpoint = "jcce/jcce-schedule"
|
||||
// 镜像
|
||||
def image = "${registryUrl}/${imageEndpoint}:${imageTag}"
|
||||
def imageLatest = "${registryUrl}/${imageEndpoint}:latest"
|
||||
|
||||
stage('单元测试') {
|
||||
echo "1.测试阶段"
|
||||
}
|
||||
stage('代码编译打包') {
|
||||
try {
|
||||
container('golang') {
|
||||
echo "2.代码编译打包阶段"
|
||||
sh """
|
||||
export GOPROXY=https://goproxy.cn
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o jcce-schedule ./main.go
|
||||
"""
|
||||
}
|
||||
} catch (exc) {
|
||||
println "构建失败 - ${currentBuild.fullDisplayName}"
|
||||
throw(exc)
|
||||
}
|
||||
}
|
||||
stage('构建 Docker 镜像') {
|
||||
withCredentials([[$class: 'UsernamePasswordMultiBinding',
|
||||
credentialsId: 'docker-auth',
|
||||
usernameVariable: 'DOCKER_USER',
|
||||
passwordVariable: 'DOCKER_PASSWORD']]) {
|
||||
container('docker') {
|
||||
echo "3. 构建 Docker 镜像阶段"
|
||||
sh('cat /etc/resolv.conf')
|
||||
sh("docker login '${registryUrl}' -u '${DOCKER_USER}' -p '${DOCKER_PASSWORD}' ")
|
||||
sh("docker build -t '${image}' -t '${imageLatest}' .")
|
||||
sh("docker push '${image}'")
|
||||
sh("docker push '${imageLatest}'")
|
||||
sh("docker rmi '${image}' '${imageLatest}'")
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('运行 Kubectl 部署到k8s平台') {
|
||||
withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
|
||||
container('kubectl') {
|
||||
echo "5.部署应用"
|
||||
sh('mkdir -p ~/.kube && cp ${KUBECONFIG} ~/.kube/config')
|
||||
sh("sed -i 's#IMAGE_NAME#${image}#' deploy/jcce-schedule-deployment.yaml")
|
||||
sh("sed -i 's#SECRET_NAME#${secret_name}#' deploy/jcce-schedule-deployment.yaml")
|
||||
sh('kubectl apply -f deploy/')
|
||||
sh('sleep 3')
|
||||
echo "6.查看应用"
|
||||
sh('kubectl get all -n jcce-system -l app=${JOB_NAME}')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package etc
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
Name string `mapstructure:"name"`
|
||||
Port int `mapstructure:"port"`
|
||||
AdapterId int64 `mapstructure:"adapterId"`
|
||||
CoreServerUrl string `mapstructure:"coreServerUrl"`
|
||||
}
|
||||
|
||||
var ServerConf *ServerConfig
|
||||
|
||||
func init() {
|
||||
v := viper.New()
|
||||
v.SetConfigFile("etc/config.yaml")
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := v.Unmarshal(&ServerConf); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
name: pcm-kubernetes
|
||||
port: 2005
|
||||
|
||||
adapterId: 1752857389213683712
|
||||
|
||||
coreServerUrl: http://localhost:8999
|
||||
#coreServerUrl: http://47.92.39.128:31031
|
|
@ -85,9 +85,6 @@ func (p *OperateStruct) Apply() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue