Update Dockerfile
This commit is contained in:
parent
8f6e02dbd5
commit
d24833b35d
15
Dockerfile
15
Dockerfile
|
@ -1,18 +1,23 @@
|
||||||
FROM golang:1.20.2-alpine3.17 AS builder
|
FROM golang:1.21.2-alpine3.18 AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
LABEL stage=gobuilder
|
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 CGO_ENABLED 0
|
||||||
ENV GOARCH amd64
|
ENV GOARCH amd64
|
||||||
ENV GOPROXY https://goproxy.cn,direct
|
ENV GOPROXY https://goproxy.cn,direct
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ADD go.mod .
|
||||||
|
ADD go.sum .
|
||||||
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
COPY etc/ /app/
|
COPY etc/ /app/
|
||||||
RUN go mod download
|
|
||||||
RUN go build -o /app/pcm-participant-kubernetes /app/kubernetes.go
|
RUN go build -o /app/pcm-participant-kubernetes /app/kubernetes.go
|
||||||
|
|
||||||
|
|
||||||
FROM alpine:3.16.2
|
FROM alpine:3.16.2
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pkg
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"gitlink.org.cn/jcce-pcm/utils/tool"
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
||||||
"io"
|
"io"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
@ -26,6 +27,7 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("错误: %v", err)
|
||||||
}
|
}
|
||||||
obj := &unstructured.Unstructured{}
|
obj := &unstructured.Unstructured{}
|
||||||
syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj)
|
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}
|
unstructureObj := &unstructured.Unstructured{Object: unstructuredMap}
|
||||||
gvr, err := tool.GetGVR(clientSet, unstructureObj.GroupVersionKind())
|
gvr, err := tool.GetGVR(clientSet, unstructureObj.GroupVersionKind())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("GetGVR错误: %v", err)
|
||||||
}
|
}
|
||||||
unstructuredYaml, err := sigyaml.Marshal(unstructureObj)
|
unstructuredYaml, err := sigyaml.Marshal(unstructureObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if unstructureObj.GetNamespace() == "" {
|
if unstructureObj.GetNamespace() == "" {
|
||||||
|
@ -47,6 +51,7 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy
|
||||||
if getErr != nil {
|
if getErr != nil {
|
||||||
_, createErr := dynamicClient.Resource(gvr).Namespace(unstructureObj.GetNamespace()).Create(context.Background(), unstructureObj, metav1.CreateOptions{})
|
_, createErr := dynamicClient.Resource(gvr).Namespace(unstructureObj.GetNamespace()).Create(context.Background(), unstructureObj, metav1.CreateOptions{})
|
||||||
if createErr != nil {
|
if createErr != nil {
|
||||||
|
logx.Errorf("错误: %v", createErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue