This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


The following commit(s) were added to refs/heads/main by this push:
     new cc01ffd4 Fix cannot publish windows and linux docker image (#404)
cc01ffd4 is described below

commit cc01ffd4104707586bff69c8fbb666cbc7ff37c0
Author: mrproliu <741550...@qq.com>
AuthorDate: Fri Mar 8 01:12:08 2024 +0000

    Fix cannot publish windows and linux docker image (#404)
---
 .github/workflows/publish-docker.yml | 29 +++++++++--------------------
 Makefile                             |  2 +-
 api/Makefile                         |  4 ++--
 bydbctl/Makefile                     |  5 ++++-
 docker/Dockerfile                    | 13 ++++++++++---
 docker/Dockerfile.windows            | 26 --------------------------
 scripts/build/base.mk                |  7 -------
 scripts/build/build.mk               | 10 ++++++----
 scripts/build/docker.mk              | 35 ++++++++++-------------------------
 scripts/build/generate_go.mk         |  2 +-
 10 files changed, 43 insertions(+), 90 deletions(-)

diff --git a/.github/workflows/publish-docker.yml 
b/.github/workflows/publish-docker.yml
index 1682761d..c348a492 100644
--- a/.github/workflows/publish-docker.yml
+++ b/.github/workflows/publish-docker.yml
@@ -29,17 +29,13 @@ env:
 jobs:
   push-banyandb-image:
     if: github.repository == 'apache/skywalking-banyandb'
-    runs-on: ${{ matrix.target }}-latest
+    runs-on: ubuntu-latest
     permissions:
       contents: read
       packages: write
     timeout-minutes: 90
     strategy:
       fail-fast: true
-      matrix:
-        target:
-          - ubuntu
-          - windows
     env:
       TAG: ${{ github.sha }}
     steps:
@@ -72,26 +68,19 @@ jobs:
         uses: actions/setup-go@v3
         with:
           go-version-file: 'go.mod'
-      - name: Update dependencies on Linux
-        if: steps.cache-go.outputs.cache-hit != 'true' && matrix.target == 
'ubuntu'
+      - name: Update dependencies
+        if: steps.cache-go.outputs.cache-hit != 'true'
         run: GOPROXY=https://proxy.golang.org go mod download
-      - name: Update dependencies on Windows
-        if: steps.cache-go.outputs.cache-hit != 'true' && matrix.target == 
'windows'
-        run: |
-          $env:GOPROXY="https://proxy.golang.org";
-          go mod download
       - name: Generate codes
         run: make generate
-      - name: Set up Docker Buildx on Linux
-        if: matrix.target == 'ubuntu'
+      - name: Set up Docker Buildx
         uses: docker/setup-buildx-action@v1
-      - name: Build binaries on Windows
-        if: matrix.target == 'windows'
+      - name: Build Windows binaries
         run: |
-          $env:BUILD_TAGS="prometheus"
-          make -C banyand banyand-server-static
-          make -C bydbctl build
-      - name: Build docker image on Linux
+          GOOS=windows GOARCH=amd64 BUILD_TAGS=prometheus make -C banyand 
banyand-server-static
+          GOOS=windows GOARCH=amd64 make -C bydbctl build
+      - name: Build docker image
+        if: github.ref != 'refs/heads/main' # Only build docker image on 
PR(Push image when pushed to main branch)
         run: |
           make docker.build || make docker.build
           docker image ls
diff --git a/Makefile b/Makefile
index b77efe5a..6e94331a 100644
--- a/Makefile
+++ b/Makefile
@@ -150,7 +150,7 @@ license-dep: default ## Fix license header issues
 
 docker.build: TARGET=docker
 docker.build: DIR=docker
-docker.build: 
+docker.build:
        $(MAKE) $(TARGET) -C $(DIR); \
        if [ $$? -ne 0 ]; then \
                exit 1; \
diff --git a/api/Makefile b/api/Makefile
index ee39ccdb..22fb2ef3 100644
--- a/api/Makefile
+++ b/api/Makefile
@@ -46,5 +46,5 @@ $(BUF):
        @GOBIN=$(tool_bin) go install 
github.com/envoyproxy/protoc-gen-validate@$(PROTOC_GEN_VALIDATE_VERSION)
 
 generate: $(BUF)
-       PATH=$(tool_bin):$(proto_dir):$$PATH; $(BUF) generate
-       cp proto/api-reference.md $(root_dir)/docs
+       @PATH=$(tool_bin):$(proto_dir) $(BUF) generate && \
+         cp proto/api-reference.md $(root_dir)/docs
diff --git a/bydbctl/Makefile b/bydbctl/Makefile
index 8f8d7601..249207a8 100644
--- a/bydbctl/Makefile
+++ b/bydbctl/Makefile
@@ -23,13 +23,16 @@ include ../scripts/build/version.mk
 include ../scripts/build/base.mk
 include ../scripts/build/generate_go.mk
 
+GOOS ?= linux
+GOARCH ?= amd64
+
 .PHONY: all
 all: build
 
 .PHONY: build
 build: 
        @echo "Building binary"
-       go build -v --ldflags '${GO_LINK_VERSION}' -o $(BUILD_DIR)/$(NAME) 
github.com/apache/skywalking-banyandb/bydbctl/cmd/bydbctl/$*
+       GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v --ldflags 
'${GO_LINK_VERSION}' -o $(BUILD_DIR)/$(NAME) 
github.com/apache/skywalking-banyandb/bydbctl/cmd/bydbctl/$*
        chmod +x $(BUILD_DIR)/$(NAME)
        @echo "Done building $(NAME)"
 
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 563949e4..c3d44bbf 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -47,14 +47,21 @@ RUN --mount=target=. \
 FROM alpine:edge AS certs
 RUN apk add --no-cache ca-certificates && update-ca-certificates
 
-FROM busybox:stable-glibc
+FROM busybox:stable-glibc as build-linux
 
-COPY --from=builder /out/banyand-server-static /banyand-server
+COPY --from=builder /out/banyand-server-static /banyand
 COPY --from=certs /etc/ssl/certs /etc/ssl/certs
 COPY --from=builder /out/bydbctl /bydbctl
 
+FROM mcr.microsoft.com/windows/servercore:ltsc2022 as build-windows
+
+COPY banyand/build/bin/banyand-server-static "/banyand"
+COPY bydbctl/build/bin/bydbctl "/bydbctl"
+
+FROM build-${TARGETOS} AS final
+
 EXPOSE 17912
 EXPOSE 17913
 EXPOSE 6060
 
-ENTRYPOINT ["/banyand-server"]
\ No newline at end of file
+ENTRYPOINT ["/banyand"]
\ No newline at end of file
diff --git a/docker/Dockerfile.windows b/docker/Dockerfile.windows
deleted file mode 100644
index 1755f514..00000000
--- a/docker/Dockerfile.windows
+++ /dev/null
@@ -1,26 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-FROM mcr.microsoft.com/windows/servercore:ltsc2022
-
-COPY banyand/build/bin/banyand-server-static c:\\banyand-server
-COPY bydbctl/build/bin/bydbctl c:\\bydbctl
-
-EXPOSE 17912
-EXPOSE 17913
-EXPOSE 6060
-
-ENTRYPOINT ["c:\\banyand-server"]
\ No newline at end of file
diff --git a/scripts/build/base.mk b/scripts/build/base.mk
index ffc59c0b..58bd16f3 100644
--- a/scripts/build/base.mk
+++ b/scripts/build/base.mk
@@ -22,13 +22,6 @@ root_dir := $(mk_dir)../..
 tool_bin := $(root_dir)/bin
 tool_include := "$(root_dir)/include"
 
-ifeq ($(OS),Windows_NT)
-       # Using unix style path when running on Windows machine or Windows 
version Git Bash
-    tool_bin := $(subst \,/,$(tool_bin))
-    # Match any drive letter and replace with lowercase version prefixed with 
'/'
-    tool_bin := $(shell echo $(tool_bin) | sed 
's/\([A-Za-z]\):\/\?/\/\L\1\//g')
-endif
-
 # Retrieve git versioning details so we can add to our binary assets
 VERSION_PATH    := github.com/apache/skywalking-banyandb/pkg/version
 ifdef RELEASE_VERSION
diff --git a/scripts/build/build.mk b/scripts/build/build.mk
index cb6a9c3f..47595d7c 100644
--- a/scripts/build/build.mk
+++ b/scripts/build/build.mk
@@ -30,6 +30,8 @@ DEBUG_STATIC_BINARIES ?= $(addsuffix 
-static,$(DEBUG_BINARIES))
 BUILD_DIR ?= build/bin
 # Define SUB_DIR var if the project is not at root level project
 SOURCE_DIR := $(if $(SUB_DIR),$(SUB_DIR)/$(NAME),$(NAME))
+GOOS ?= linux
+GOARCH ?= amd64
 
 ##@ Build targets
 
@@ -39,7 +41,7 @@ all: $(BINARIES)  ## Build all the binaries
 $(BINARIES): $(NAME)-%: $(BUILD_DIR)/$(NAME)-%
 $(addprefix $(BUILD_DIR)/,$(BINARIES)): $(BUILD_DIR)/$(NAME)-%:
        @echo "Building binary"
-       go build -v -buildvcs=false --ldflags '${GO_LINK_VERSION}' -tags 
"$(BUILD_TAGS)" -o $@ github.com/apache/skywalking-banyandb/$(SOURCE_DIR)/cmd/$*
+       GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v -buildvcs=false --ldflags 
'${GO_LINK_VERSION}' -tags "$(BUILD_TAGS)" -o $@ 
github.com/apache/skywalking-banyandb/$(SOURCE_DIR)/cmd/$*
        chmod +x $@
        @echo "Done building $(NAME) $*"
 
@@ -49,14 +51,14 @@ $(DEBUG_BINARIES): $(NAME)-%-debug: 
$(BUILD_DIR)/$(NAME)-%-debug
 $(addprefix $(BUILD_DIR)/,$(DEBUG_BINARIES)): $(BUILD_DIR)/$(NAME)-%-debug:
        @echo "Building debug binary"
        mkdir -p $(BUILD_DIR)
-       go build -v -buildvcs=false --ldflags '${GO_LINK_VERSION}' -tags 
"$(BUILD_TAGS)" -gcflags='all=-N -l' -o $@ 
github.com/apache/skywalking-banyandb/$(SOURCE_DIR)/cmd/$*
+       GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v -buildvcs=false --ldflags 
'${GO_LINK_VERSION}' -tags "$(BUILD_TAGS)" -gcflags='all=-N -l' -o $@ 
github.com/apache/skywalking-banyandb/$(SOURCE_DIR)/cmd/$*
        chmod +x $@
        @echo "Done building debug $(NAME) $*"
 
 $(STATIC_BINARIES): $(NAME)-%-static: $(BUILD_DIR)/$(NAME)-%-static
 $(addprefix $(BUILD_DIR)/,$(STATIC_BINARIES)): $(BUILD_DIR)/$(NAME)-%-static:
        @echo "Building static binary"
-       CGO_ENABLED=0 go build \
+       CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
                -buildvcs=false \
                -a --ldflags '${GO_LINK_VERSION} -extldflags "-static"' -tags 
"netgo $(BUILD_TAGS)" -installsuffix netgo \
                -o $(BUILD_DIR)/$(NAME)-$*-static 
github.com/apache/skywalking-banyandb/$(SOURCE_DIR)/cmd/$*
@@ -68,7 +70,7 @@ debug-static: $(DEBUG_STATIC_BINARIES)  ## Build the debug 
static binaries
 $(DEBUG_STATIC_BINARIES): $(NAME)-%-debug-static: 
$(BUILD_DIR)/$(NAME)-%-debug-static
 $(addprefix $(BUILD_DIR)/,$(DEBUG_STATIC_BINARIES)): 
$(BUILD_DIR)/$(NAME)-%-debug-static:
        @echo "Building debug static binary"
-       CGO_ENABLED=0 go build \
+       CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
                -buildvcs=false \
                -a --ldflags '${GO_LINK_VERSION} -extldflags "-static"' -tags 
"netgo $(BUILD_TAGS)" -gcflags='all=-N -l' -installsuffix netgo \
                -o $(BUILD_DIR)/$(NAME)-$*-debug-static 
github.com/apache/skywalking-banyandb/$(SOURCE_DIR)/cmd/$*
diff --git a/scripts/build/docker.mk b/scripts/build/docker.mk
index 1ec5e2ef..b575b47e 100644
--- a/scripts/build/docker.mk
+++ b/scripts/build/docker.mk
@@ -31,32 +31,17 @@ IMG := $(HUB)/$(IMG_NAME):$(TAG)
 
 # Disable cache in CI environment
 ifeq (true,$(CI))
-       ifeq ($(OS),Windows_NT)
-               # windows not support buildx, so no "--load" option
-               DOCKER_BUILD_ARGS := $(DOCKER_BUILD_ARGS) --no-cache
-       else
-               DOCKER_BUILD_ARGS := $(DOCKER_BUILD_ARGS) --no-cache --load
-       endif
+       DOCKER_BUILD_ARGS := $(DOCKER_BUILD_ARGS) --no-cache
 endif
 
-DOCKER_FILE := Dockerfile
-DOCKER_BUILD = docker buildx build
-TIME = time
-ifeq ($(OS),Windows_NT)
-       # build docker using other Dockerfile and docker build command
-       DOCKER_FILE = Dockerfile.windows
-       DOCKER_BUILD = docker build
-       # time is not support in the windows(CI environment)
-       TIME =
-endif
-
-.PHONY: docker
-docker:
-       @echo "Build $(IMG)"
-       $(TIME) $(DOCKER_BUILD) $(DOCKER_BUILD_ARGS) -t $(IMG) -f 
$(DOCKER_FILE) ..
+docker: PLATFORMS =
+docker: LOAD_OR_PUSH = --load
+docker: DOCKER_TYPE = "Build"
+docker.push: PLATFORMS = --platform linux/amd64,linux/arm64,windows/amd64
+docker.push: LOAD_OR_PUSH = --push
+docker.push: DOCKER_TYPE = "Push"
 
-.PHONY: docker.push
-docker.push:
-       @echo "Push $(IMG)"
-       $(TIME) docker push $(IMG)
+docker docker.push:
+       @echo "$(DOCKER_TYPE) $(IMG)"
+       @time docker buildx build $(DOCKER_BUILD_ARGS) $(PLATFORMS) 
$(LOAD_OR_PUSH) -t $(IMG) -f Dockerfile ..
 
diff --git a/scripts/build/generate_go.mk b/scripts/build/generate_go.mk
index 2523a1eb..49edbca8 100644
--- a/scripts/build/generate_go.mk
+++ b/scripts/build/generate_go.mk
@@ -24,4 +24,4 @@ $(MOCKGEN):
 
 .PHONY: generate
 generate: $(MOCKGEN)
-       PATH=$(tool_bin):$$PATH; go generate ./...
+       @PATH=$(tool_bin):$$PATH; go generate ./...

Reply via email to