Skip to content

Commit

Permalink
build: update dockerfile and makefile (#625)
Browse files Browse the repository at this point in the history
Signed-off-by: James Yin <[email protected]>
  • Loading branch information
ifplusor authored Sep 7, 2023
1 parent 14c12fd commit 23f5aee
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 55 deletions.
43 changes: 24 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ export VANUS_LOG_LEVEL=info

DOCKER_REGISTRY ?= public.ecr.aws
DOCKER_REPO ?= ${DOCKER_REGISTRY}/vanus
IMAGE_PREFIX ?=
IMAGE_TAG ?= ${GIT_COMMIT}
#os linux or darwin
GOOS ?= linux
#arch amd64 or arm64
GOARCH ?= amd64
CMD_OUTPUT_DIR ?= ${VANUS_ROOT}/bin

VERSION ?= ${IMAGE_TAG}

GO_BUILD= GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -trimpath
DOCKER_BUILD_ARG= --build-arg TARGETARCH=$(GOARCH) --build-arg TARGETOS=$(GOOS)
GO_BUILD = GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -trimpath
DOCKER_BUILD_ARG = --build-arg TARGETARCH=$(GOARCH) --build-arg TARGETOS=$(GOOS)
DOCKER_PLATFORM ?= linux/amd64,linux/arm64

clean :
clean:
rm -rf bin

docker-push: docker-push-root docker-push-controller docker-push-timer docker-push-trigger docker-push-gateway docker-push-store
docker-build: docker-build-root docker-build-controller docker-build-timer docker-build-trigger docker-build-gateway docker-build-store
build: build-root build-controller build-timer build-trigger build-gateway build-store

docker-push-store:
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/store:${IMAGE_TAG} -f build/images/store/Dockerfile . --push
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/${IMAGE_PREFIX}store:${IMAGE_TAG} -f build/images/store/Dockerfile . --push
docker-build-store:
docker build -t ${DOCKER_REPO}/store:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/store/Dockerfile .
docker build -t ${DOCKER_REPO}/${IMAGE_PREFIX}store:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/store/Dockerfile .
build-store:
$(GO_BUILD) -o bin/store cmd/store/main.go

docker-push-gateway:
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/gateway:${IMAGE_TAG} -f build/images/gateway/Dockerfile . --push
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/${IMAGE_PREFIX}gateway:${IMAGE_TAG} -f build/images/gateway/Dockerfile . --push
docker-build-gateway:
docker build -t ${DOCKER_REPO}/gateway:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/gateway/Dockerfile .
docker build -t ${DOCKER_REPO}/${IMAGE_PREFIX}gateway:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/gateway/Dockerfile .
build-gateway:
$(GO_BUILD) -o bin/gateway cmd/gateway/main.go

Expand All @@ -58,37 +60,40 @@ LD_FLAGS=${t4} -X 'main.Platform=${GOOS}/${GOARCH}'
docker-push-toolbox:
docker buildx build --no-cache --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/toolbox:${IMAGE_TAG} -f build/toolbox/Dockerfile . --push

build-cmd:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o bin/vsctl ./vsctl/
build-vsctl:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o ${CMD_OUTPUT_DIR}/vsctl ./vsctl/

build-repair-tool:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o bin/vsrepair ./vsrepair/
build-vsrepair:
$(GO_BUILD) -ldflags "${LD_FLAGS}" -o ${CMD_OUTPUT_DIR}/vsrepair ./vsrepair/

.PHONY: build-cmd
build-cmd: build-vsctl

docker-push-root:
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/root-controller:${IMAGE_TAG} -f build/images/root-controller/Dockerfile . --push
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/${IMAGE_PREFIX}root-controller:${IMAGE_TAG} -f build/images/root-controller/Dockerfile . --push
docker-build-root:
docker build -t ${DOCKER_REPO}/root-controller:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/root-controller/Dockerfile .
docker build -t ${DOCKER_REPO}/${IMAGE_PREFIX}root-controller:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/root-controller/Dockerfile .
build-root:
$(GO_BUILD) -o bin/root-controller cmd/root/main.go

docker-push-controller:
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/controller:${IMAGE_TAG} -f build/images/controller/Dockerfile . --push
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/${IMAGE_PREFIX}controller:${IMAGE_TAG} -f build/images/controller/Dockerfile . --push
docker-build-controller:
docker build -t ${DOCKER_REPO}/controller:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/controller/Dockerfile .
docker build -t ${DOCKER_REPO}/${IMAGE_PREFIX}controller:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/controller/Dockerfile .
build-controller:
$(GO_BUILD) -o bin/controller cmd/controller/main.go

docker-push-trigger:
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/trigger:${IMAGE_TAG} -f build/images/trigger/Dockerfile . --push
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/${IMAGE_PREFIX}trigger:${IMAGE_TAG} -f build/images/trigger/Dockerfile . --push
docker-build-trigger:
docker build -t ${DOCKER_REPO}/trigger:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/trigger/Dockerfile .
docker build -t ${DOCKER_REPO}/${IMAGE_PREFIX}trigger:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/trigger/Dockerfile .
build-trigger:
$(GO_BUILD) -o bin/trigger cmd/trigger/main.go

docker-push-timer:
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/timer:${IMAGE_TAG} -f build/images/timer/Dockerfile . --push
docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_REPO}/${IMAGE_PREFIX}timer:${IMAGE_TAG} -f build/images/timer/Dockerfile . --push
docker-build-timer:
docker build -t ${DOCKER_REPO}/timer:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/timer/Dockerfile .
docker build -t ${DOCKER_REPO}/${IMAGE_PREFIX}timer:${IMAGE_TAG} $(DOCKER_BUILD_ARG) -f build/images/timer/Dockerfile .
build-timer:
$(GO_BUILD) -o bin/timer cmd/timer/main.go

Expand Down
5 changes: 2 additions & 3 deletions build/all-in-one/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder
WORKDIR /workspace

COPY . .
Expand All @@ -15,7 +15,7 @@ RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-timer
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-gateway


FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.10
WORKDIR /vanus

ARG VERSION
Expand Down Expand Up @@ -44,4 +44,3 @@ ENV VERSION=$VERSION
ENV VANUS_LOG_LEVEL=debug

ENTRYPOINT ["/vanus/run.sh"]

23 changes: 18 additions & 5 deletions build/images/controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder

WORKDIR /workspace

COPY . .
RUN go mod download
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

ARG TARGETOS
ARG TARGETARCH

COPY . .
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-controller

FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.04

RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /vanus

COPY --from=builder /workspace/bin/controller bin/controller
ENTRYPOINT ["bin/controller"]

CMD ["bin/controller"]
22 changes: 17 additions & 5 deletions build/images/gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder

WORKDIR /workspace

COPY . .
RUN go mod download
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

ARG TARGETOS
ARG TARGETARCH

COPY . .
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-gateway

FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.04

WORKDIR /vanus

RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /workspace/bin/gateway bin/gateway
ENTRYPOINT ["bin/gateway"]

CMD ["bin/gateway"]
23 changes: 18 additions & 5 deletions build/images/root-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder

WORKDIR /workspace

COPY . .
RUN go mod download
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

ARG TARGETOS
ARG TARGETARCH

COPY . .
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-root

FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.04

WORKDIR /vanus

RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /workspace/bin/root-controller bin/root-controller
ENTRYPOINT ["bin/root-controller"]

CMD ["bin/root-controller"]
26 changes: 20 additions & 6 deletions build/images/store/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder

WORKDIR /workspace

COPY . .
RUN go mod download
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-store

FROM --platform=$BUILDPLATFORM ubuntu:22.10
COPY . .
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-store && \
GOOS=$TARGETOS GOARCH=$TARGETARCH make build-vsrepair

FROM --platform=$TARGETPLATFORM ubuntu:22.04

WORKDIR /vanus

RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /workspace/bin/store bin/store
ENTRYPOINT ["bin/store"]
COPY --from=builder /workspace/bin/vsrepair bin/vsrepair

CMD ["bin/store"]
22 changes: 17 additions & 5 deletions build/images/timer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder

WORKDIR /workspace

COPY . .
RUN go mod download
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

ARG TARGETOS
ARG TARGETARCH

COPY . .
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-timer

FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.04

RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /vanus

COPY --from=builder /workspace/bin/timer bin/timer
ENTRYPOINT ["bin/timer"]

CMD ["bin/timer"]
22 changes: 17 additions & 5 deletions build/images/trigger/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder

WORKDIR /workspace

COPY . .
RUN go mod download
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

ARG TARGETOS
ARG TARGETARCH

COPY . .
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-trigger

FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.04

RUN apt-get update && apt-get install -y \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /vanus

COPY --from=builder /workspace/bin/trigger bin/trigger
ENTRYPOINT ["bin/trigger"]

CMD ["bin/trigger"]
4 changes: 2 additions & 2 deletions build/toolbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM ubuntu:22.10
FROM --platform=$TARGETPLATFORM ubuntu:22.10

ARG TARGETOS
ARG TARGETARCH
Expand Down Expand Up @@ -26,4 +26,4 @@ RUN chmod a+x /vanus/toolbox/bin/*
RUN rm -rf etcd-v3.5.7-$TARGETOS-$TARGETARCH.*

RUN echo 'alias vsctl="vsctl --endpoint vanus-gateway:8080 --operator-endpoint vanus-operator:8089"' >> /root/.bashrc
ENV PATH=$PATH:/vanus/toolbox/etcd:/vanus/toolbox/bin
ENV PATH=$PATH:/vanus/toolbox/etcd:/vanus/toolbox/bin

0 comments on commit 23f5aee

Please sign in to comment.