Update Dockerfile

This commit is contained in:
devad 2023-12-13 15:33:59 +08:00
parent 8f6e02dbd5
commit d24833b35d
2 changed files with 15 additions and 5 deletions

View File

@ -1,18 +1,23 @@
FROM golang:1.20.2-alpine3.17 AS builder
WORKDIR /app
FROM golang:1.21.2-alpine3.18 AS builder
LABEL stage=gobuilder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \
apk update --no-cache && apk add --no-cache tzdata
ENV CGO_ENABLED 0
ENV GOARCH amd64
ENV GOPROXY https://goproxy.cn,direct
WORKDIR /app
ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
COPY etc/ /app/
RUN go mod download
RUN go build -o /app/pcm-participant-kubernetes /app/kubernetes.go
FROM alpine:3.16.2
WORKDIR /app

View File

@ -3,6 +3,7 @@ package pkg
import (
"bytes"
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/jcce-pcm/utils/tool"
"io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -26,6 +27,7 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy
break
}
if err != nil {
logx.Errorf("错误: %v", err)
}
obj := &unstructured.Unstructured{}
syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj)
@ -35,9 +37,11 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy
unstructureObj := &unstructured.Unstructured{Object: unstructuredMap}
gvr, err := tool.GetGVR(clientSet, unstructureObj.GroupVersionKind())
if err != nil {
logx.Errorf("GetGVR错误: %v", err)
}
unstructuredYaml, err := sigyaml.Marshal(unstructureObj)
if err != nil {
logx.Errorf("错误: %v", err)
}
if unstructureObj.GetNamespace() == "" {
@ -47,6 +51,7 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy
if getErr != nil {
_, createErr := dynamicClient.Resource(gvr).Namespace(unstructureObj.GetNamespace()).Create(context.Background(), unstructureObj, metav1.CreateOptions{})
if createErr != nil {
logx.Errorf("错误: %v", createErr)
}
}