summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlinxin <[email protected]>2023-03-13 17:44:41 +0800
committerlinxin <[email protected]>2023-03-13 17:44:41 +0800
commit0b7594348a0686b7d46f63789ef7a55662b63bb9 (patch)
tree71c94641a3c146aef342032a2f375c747f5b7888
parent66db1a56eb768b4e1aa643a175b7112324bea9a3 (diff)
增加docker镜像制作脚本HEADmain
-rw-r--r--Dockerfile4
-rw-r--r--build16
-rw-r--r--webhook/webhook.go28
3 files changed, 34 insertions, 14 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..28b5830
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,4 @@
+FROM alpine:latest
+
+ADD webhook-example /webhook-example
+ENTRYPOINT ["./webhook-example"] \ No newline at end of file
diff --git a/build b/build
new file mode 100644
index 0000000..f64eeaf
--- /dev/null
+++ b/build
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+DOCKER_USER=docker.io
+date=$(date "+%Y%m%d%H%M")
+version="v1.0.0_$date"
+: ${DOCKER_USER:? required}
+
+export GO111MODULE=on
+export GOPROXY=https://goproxy.cn
+# build webhook
+CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o webhook-example
+# build docker image
+docker build --no-cache -t ${DOCKER_USER}/webhook-example:${version} .
+rm -rf webhook-example
+
+#docker push ${DOCKER_USER}/webhook-example:${version}
diff --git a/webhook/webhook.go b/webhook/webhook.go
index 433e7a3..20054a0 100644
--- a/webhook/webhook.go
+++ b/webhook/webhook.go
@@ -253,14 +253,14 @@ func mutationRequired(ignoredList []string, metadata *metav1.ObjectMeta) bool {
func createPatch(deployment appsv1.Deployment, addAnnotations map[string]string, addLabels map[string]string) ([]byte, error) {
var patches []patchOperation
- objectMeta := deployment.ObjectMeta
- labels := objectMeta.Labels
- annotations := objectMeta.Annotations
- labelsPatch := updateLabels(labels, addLabels)
- annotationsPatch := updateAnnotation(annotations, addAnnotations)
+ // objectMeta := deployment.ObjectMeta
+ // labels := objectMeta.Labels
+ // annotations := objectMeta.Annotations
+ // labelsPatch := updateLabels(labels, addLabels)
+ // annotationsPatch := updateAnnotation(annotations, addAnnotations)
containersPatch := updateContainers(deployment)
- patches = append(patches, labelsPatch...)
- patches = append(patches, annotationsPatch...)
+ // patches = append(patches, labelsPatch...)
+ // patches = append(patches, annotationsPatch...)
patches = append(patches, containersPatch...)
//打印出来看一下
@@ -309,13 +309,13 @@ func updateLabels(target map[string]string, added map[string]string) (patch []pa
return patch
}
-var addContainer = []corev1.Container{
- {
- Name: "side-car",
- Image: "busybox",
- Command: []string{"/bin/sleep", "infinity"},
- },
-}
+// var addContainer = []corev1.Container{
+// {
+// Name: "side-car",
+// Image: "busybox",
+// Command: []string{"/bin/sleep", "infinity"},
+// },
+// }
func updateContainers(deployment appsv1.Deployment) (patch []patchOperation) {
currentDeployment := deployment.DeepCopy()