From 0fbb4cfcbabb7b25a737682939ea45ceb1bed775 Mon Sep 17 00:00:00 2001 From: Airren Date: Thu, 23 May 2024 11:17:59 +0800 Subject: [PATCH] feat: refactor the image build Signed-off-by: Airren --- Dockerfile | 17 ---- Makefile | 78 ++++++++++++++----- build/crossdns.Dockerfile | 16 ++++ build/octopus.Dockerfile | 15 ++++ build/ovnmaster.Dockerfile | 15 ++++ deploy/cluster/templates/crossdns-deploy.yaml | 2 +- deploy/cluster/templates/dedinic-ds.yaml | 6 +- deploy/cluster/templates/ovn-controller.yaml | 2 +- .../cluster/templates/tunnel_deployment.yaml | 4 +- deploy/cluster/values.yaml | 8 +- deploy/hub/templates/tunnel_eployment.yaml | 4 +- deploy/hub/values.yaml | 7 +- 12 files changed, 121 insertions(+), 53 deletions(-) delete mode 100644 Dockerfile create mode 100644 build/crossdns.Dockerfile create mode 100644 build/octopus.Dockerfile create mode 100644 build/ovnmaster.Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 5c5b336a..00000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM alpine:3.7 as ovnmaster -WORKDIR / -COPY ./cmd/ovnmaster/ovnmaster . -ENTRYPOINT ["./ovnmaster"] - -FROM alpine:3.19 as octopus -RUN apk add --no-cache wireguard-tools bash wget openresolv iptables -WORKDIR / -COPY ./cmd/octopus/octopus . -ENTRYPOINT ["./octopus"] - -FROM scratch as crossdns - -ADD ./cmd/crossdns/crossdns /crossdns - -EXPOSE 53 53/udp -ENTRYPOINT ["/crossdns"] diff --git a/Makefile b/Makefile index a68c58d7..08a85843 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,6 @@ IMG ?= ovnmaster:latest # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) CRD_OPTIONS ?= "crd:crdVersions=v1,generateEmbeddedObjectMeta=true" -IMAGE_TAG := $(shell git rev-parse --short HEAD) -IMAGE_REPOSITORY := ghcr.io/nauti-io - - # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -15,11 +11,30 @@ else GOBIN=$(shell go env GOBIN) endif +GIT_COMMIT = $(shell git rev-parse HEAD) +ifeq ($(shell git tag --points-at ${GIT_COMMIT}),) +GIT_VERSION=$(shell echo ${GIT_COMMIT} | cut -c 1-7) +else +GIT_VERSION=$(shell git describe --abbrev=0 --tags --always) +endif + +IMAGE_TAG = ${GIT_VERSION} +REGISTRY ?= ghcr.io +REGISTRY_NAMESPACE ?= nauti-io + + +DOCKERARGS?= +ifdef HTTP_PROXY + DOCKERARGS += --build-arg http_proxy=$(HTTP_PROXY) +endif +ifdef HTTPS_PROXY + DOCKERARGS += --build-arg https_proxy=$(HTTPS_PROXY) +endif + lint: golangci-lint golangci-lint run -c .golangci.yaml --timeout=10m - # Generate manifests e.g. CRD, RBAC etc. manifests: controller-gen $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=deploy/hub/crds/ @@ -43,29 +58,54 @@ endif ovnmaster: - CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o cmd/ovnmaster/ovnmaster cmd/ovnmaster/main.go + CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o bin/ovnmaster cmd/ovnmaster/main.go + crossdns: - CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -a -installsuffix cgo -o cmd/crossdns/crossdns cmd/crossdns/main.go + CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -a -installsuffix cgo -o bin/crossdns cmd/crossdns/main.go + octopus: - CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o cmd/octopus/octopus cmd/octopus/main.go + CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o bin/octopus cmd/octopus/main.go + dedinic: CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o bin/dedinic cmd/dedinic/main.go + ep-controller: CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o bin/ep-controller cmd/ep-controller/main.go images: - docker build -f ./build/dedinic.Dockerfile ./ -t ${IMAGE_REPOSITORY}/dedinic:${IMAGE_TAG} - docker build -f ./build/ep-controller.Dockerfile ./ -t ${IMAGE_REPOSITORY}/ep-controller:${IMAGE_TAG} - docker push ${IMAGE_REPOSITORY}/dedinic:${IMAGE_TAG} - docker push ${IMAGE_REPOSITORY}/ep-controller:${IMAGE_TAG} - -dedinic-image: - docker build -f ./build/dedinic.Dockerfile ./ -t${IMAGE_REPOSITORY}/dedinic:${IMAGE_TAG} - docker push ${IMAGE_REPOSITORY}/dedinic:${IMAGE_TAG} -ep-controller-image: - docker build -f ./build/ep-controller.Dockerfile ./ -t ${IMAGE_REPOSITORY}/ep-controller:${IMAGE_TAG} - docker push ${IMAGE_REPOSITORY}/ep-controller:${IMAGE_TAG} + docker build $(DOCKERARGS) -f ./build/ovnmaster.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/ovnmaster:${IMAGE_TAG} + docker build $(DOCKERARGS) -f ./build/crossdns.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/crossdns:${IMAGE_TAG} + docker build $(DOCKERARGS) -f ./build/octopus.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/octopus:${IMAGE_TAG} + docker build $(DOCKERARGS) -f ./build/dedinic.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/dedinic:${IMAGE_TAG} + docker build $(DOCKERARGS) -f ./build/ep-controller.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/ep-controller:${IMAGE_TAG} + +image-ovnmaster: + docker build $(DOCKERARGS) -f ./build/ovnmaster.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/ovnmaster:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/ovnmaster:${IMAGE_TAG} + +image-crossdns: + docker build $(DOCKERARGS) -f ./build/crossdns.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/crossdns:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/crossdns:${IMAGE_TAG} + +image-octopus: + docker build $(DOCKERARGS) -f ./build/octopus.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/octopus:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/octopus:${IMAGE_TAG} + +image-dedinic: + docker build $(DOCKERARGS) -f ./build/dedinic.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/dedinic:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/dedinic:${IMAGE_TAG} + +image-ep-controller: + docker build $(DOCKERARGS) -f ./build/ep-controller.Dockerfile ./ -t ${REGISTRY}/${REGISTRY_NAMESPACE}/ep-controller:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/ep-controller:${IMAGE_TAG} + +images-push: + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/ovnmaster:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/crossdns:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/octopus:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/dedinic:${IMAGE_TAG} + docker push ${REGISTRY}/${REGISTRY_NAMESPACE}/ep-controller:${IMAGE_TAG} # find or download golangci-lint # download golangci-lint if necessary diff --git a/build/crossdns.Dockerfile b/build/crossdns.Dockerfile new file mode 100644 index 00000000..edc1f537 --- /dev/null +++ b/build/crossdns.Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.21-alpine as builder + +WORKDIR /workspace +RUN apk add make +COPY ../go.mod ../go.sum ./ +COPY ../staging/ ./staging +RUN go mod download +COPY .. . +RUN make crossdns + + +FROM scratch + +COPY --from=builder /workspace/bin/crossdns / +EXPOSE 53 53/udp +ENTRYPOINT "/crossdns" \ No newline at end of file diff --git a/build/octopus.Dockerfile b/build/octopus.Dockerfile new file mode 100644 index 00000000..9ce99398 --- /dev/null +++ b/build/octopus.Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.21-alpine as builder + +WORKDIR /workspace +RUN apk add make +COPY ../go.mod ../go.sum ./ +COPY ../staging/ ./staging +RUN go mod download +COPY .. . +RUN make octopus + + +FROM alpine:3.17.2 +RUN apk add --no-cache wireguard-tools bash wget openresolv iptables +COPY --from=builder /workspace/bin/octopus / +ENTRYPOINT "/octopus" \ No newline at end of file diff --git a/build/ovnmaster.Dockerfile b/build/ovnmaster.Dockerfile new file mode 100644 index 00000000..1c205778 --- /dev/null +++ b/build/ovnmaster.Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.21-alpine as builder + +WORKDIR /workspace +RUN apk add make +COPY ../go.mod ../go.sum ./ +COPY ../staging/ ./staging +RUN go mod download +COPY .. . +RUN make ovnmaster + + +FROM alpine:3.17.2 + +COPY --from=builder /workspace/bin/ovnmaster / +ENTRYPOINT "/ovnmaster" \ No newline at end of file diff --git a/deploy/cluster/templates/crossdns-deploy.yaml b/deploy/cluster/templates/crossdns-deploy.yaml index 6edbde19..49275204 100644 --- a/deploy/cluster/templates/crossdns-deploy.yaml +++ b/deploy/cluster/templates/crossdns-deploy.yaml @@ -62,7 +62,7 @@ spec: - -conf - /etc/coredns/Corefile name: crossdns - image: "{{ .Values.image.repository }}/crossdns:{{ .Values.image.tag | default .Chart.AppVersion }}" + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}/crossdns:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} volumeMounts: - mountPath: /etc/coredns diff --git a/deploy/cluster/templates/dedinic-ds.yaml b/deploy/cluster/templates/dedinic-ds.yaml index 14176017..730c89cd 100644 --- a/deploy/cluster/templates/dedinic-ds.yaml +++ b/deploy/cluster/templates/dedinic-ds.yaml @@ -32,7 +32,7 @@ spec: fieldPath: metadata.namespace - name: PARALLEL_IP_ANNOTATION value: "nauti.io/ip_address" - image: {{ .Values.epControllerImage }} + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}/ep-controller:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: Always resources: requests: @@ -83,9 +83,9 @@ spec: value: "true" - name: DBUS_SYSTEM_BUS_ADDRESS value: unix:path=/host/var/run/dbus/system_bus_socket - image: {{ .Values.dedinicImage }} + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}/dedinic:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: Always - name: cni-server + name: dedinic resources: limits: cpu: "1" diff --git a/deploy/cluster/templates/ovn-controller.yaml b/deploy/cluster/templates/ovn-controller.yaml index cf1fcd81..6c8504a4 100644 --- a/deploy/cluster/templates/ovn-controller.yaml +++ b/deploy/cluster/templates/ovn-controller.yaml @@ -19,7 +19,7 @@ spec: serviceAccountName: ovn containers: - name: ipam-controller - image: "{{ .Values.image.repository }}/ovnmaster:{{ .Values.image.tag | default .Chart.AppVersion }}" + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}/ovnmaster:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: NODE_IPS diff --git a/deploy/cluster/templates/tunnel_deployment.yaml b/deploy/cluster/templates/tunnel_deployment.yaml index 7952bcab..21674f05 100644 --- a/deploy/cluster/templates/tunnel_deployment.yaml +++ b/deploy/cluster/templates/tunnel_deployment.yaml @@ -24,12 +24,12 @@ spec: spec: serviceAccountName: {{ .Values.serviceAccount.name }} containers: - - name: {{ .Chart.Name }} + - name: octopus securityContext: privileged: false capabilities: add: ["NET_ADMIN", "NET_RAW"] - image: "{{ .Values.image.repository }}/octopus:{{ .Values.image.tag | default .Chart.AppVersion }}" + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}/octopus:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: OCTOPUS_CLUSTERID diff --git a/deploy/cluster/values.yaml b/deploy/cluster/values.yaml index ba9ec08d..0076e42d 100644 --- a/deploy/cluster/values.yaml +++ b/deploy/cluster/values.yaml @@ -2,12 +2,11 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. image: - repository: lmxia + registry: ghcr.io + repository: nauti-io pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. - tag: "v1.0" -epControllerImage: docker.io/airren/ep-controller:latest -dedinicImage: docker.io/airren/dedinic:v1.13.0-debug + tag: "latest" cluster: # Specifies whether this is a hub @@ -26,7 +25,6 @@ hub: tunnel: cidr: "" - globalcidr: 10.112.0.0/12 serviceAccount: # Specifies whether a service account should be created diff --git a/deploy/hub/templates/tunnel_eployment.yaml b/deploy/hub/templates/tunnel_eployment.yaml index 1ed12d81..76c33875 100644 --- a/deploy/hub/templates/tunnel_eployment.yaml +++ b/deploy/hub/templates/tunnel_eployment.yaml @@ -23,12 +23,12 @@ spec: spec: serviceAccountName: {{ .Values.serviceAccount.name }} containers: - - name: {{ .Chart.Name }} + - name: octopus securityContext: privileged: false capabilities: add: ["NET_ADMIN", "NET_RAW"] - image: "{{ .Values.image.repository }}/octopus:{{ .Values.image.tag | default .Chart.AppVersion }}" + image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}/octopus:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: OCTOPUS_CLUSTERID diff --git a/deploy/hub/values.yaml b/deploy/hub/values.yaml index 2b8f6610..6f8b34ec 100644 --- a/deploy/hub/values.yaml +++ b/deploy/hub/values.yaml @@ -2,10 +2,11 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. image: - repository: lmxia - pullPolicy: IfNotPresent + registry: ghcr.io + repository: nauti-io + pullPolicy: Always # Overrides the image tag whose default is the chart appVersion. - tag: "v1.0" + tag: "latest" cluster: # Specifies whether this is a hub