From 2b5d5741c89a2b5e62e2dc6182215ec9592180d1 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751@qq.com> Date: Mon, 4 Sep 2023 21:58:49 +0800 Subject: [PATCH] fix: add admin file (#179) Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- Makefile | 14 ++++---------- build/docker/api-admin/Dockerfile | 10 +++++----- build/docker/api-chat/Dockerfile | 10 +++++----- build/docker/rpc-admin/Dockerfile | 13 ++++++++----- build/docker/rpc-chat/Dockerfile | 8 +++++--- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index d78fedac..d4c21c92 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ ifeq ($(origin GOBIN), undefined) GOBIN := $(GOPATH)/bin endif -COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/*)) +COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/*/*)) BINS ?= $(foreach cmd,${COMMANDS},$(notdir ${cmd})) ifeq (${COMMANDS},) @@ -185,15 +185,9 @@ go.build.%: @echo "=====> BIN_DIR=$(BIN_DIR)" @echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)" @mkdir -p $(BIN_DIR)/platforms/$(OS)/$(ARCH) - @if [ "$(COMMAND)" = "rpc" ] || [ "$(COMMAND)" = "api" ]; then \ - for d in $(wildcard $(ROOT_DIR)/cmd/$(COMMAND)/*/); do \ - cd $$d && CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ - $(BIN_DIR)/platforms/$(OS)/$(ARCH)/$$(basename $$d)$(GO_OUT_EXT) .; \ - done; \ - else \ - @CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ - $(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_PACKAGE)/cmd/$(COMMAND)/main.go; \ - fi + @cd $(ROOT_DIR)/cmd/*/$(COMMAND) && CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \ + $(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) . + ## build-multiarch: Build binaries for multiple platforms. .PHONY: build-multiarch diff --git a/build/docker/api-admin/Dockerfile b/build/docker/api-admin/Dockerfile index a5bbcadf..a1aeaf1f 100644 --- a/build/docker/api-admin/Dockerfile +++ b/build/docker/api-admin/Dockerfile @@ -35,9 +35,7 @@ RUN go mod download COPY . . RUN make clean -RUN make build BINS=api - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/chat-api +RUN make build BINS=admin-api FROM ghcr.io/openim-sigs/openim-bash-image:latest @@ -47,6 +45,8 @@ COPY --from=builder ${OPENIM_CHAT_BINDIR}/platforms /openim/openim-chat/_output/ COPY --from=builder ${OPENIM_CHAT_CONFIG_NAME} /openim/openim-chat/config/config.yaml ENV PORT=10009 +EXPOSE 10009 + +RUN mv ${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/admin-api /usr/bin/admin-api -EXPOSE ${PORT} -CMD ["bash","-c","${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/admin-api --port ${PORT} --config_folder_path ${OPENIM_CHAT_CONFIG_NAME}"] +ENTRYPOINT ["bash", "-c", "admin-api --port $PORT -c $OPENIM_CHAT_CONFIG_NAME"] diff --git a/build/docker/api-chat/Dockerfile b/build/docker/api-chat/Dockerfile index f244a9f4..1b5225fd 100644 --- a/build/docker/api-chat/Dockerfile +++ b/build/docker/api-chat/Dockerfile @@ -32,9 +32,7 @@ RUN go mod download COPY . . RUN make clean -RUN make build BINS=api - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/admin-api +RUN make build BINS=chat-api FROM ghcr.io/openim-sigs/openim-bash-image:latest @@ -44,6 +42,8 @@ COPY --from=builder ${OPENIM_CHAT_BINDIR}/platforms /openim/openim-chat/_output/ COPY --from=builder ${OPENIM_CHAT_CONFIG_NAME} /openim/openim-chat/config/config.yaml ENV PORT=10008 +EXPOSE 10008 + +RUN mv ${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/chat-api /usr/bin/chat-api -EXPOSE ${PORT} -CMD ["bash", "-c","${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/chat-api --port ${PORT} --config_folder_path ${OPENIM_CHAT_CONFIG_NAME}"] +ENTRYPOINT ["bash", "-c", "chat-api --port $PORT -c $OPENIM_CHAT_CONFIG_NAME"] diff --git a/build/docker/rpc-admin/Dockerfile b/build/docker/rpc-admin/Dockerfile index 13c1c2d0..b77cf611 100644 --- a/build/docker/rpc-admin/Dockerfile +++ b/build/docker/rpc-admin/Dockerfile @@ -32,9 +32,7 @@ RUN go mod download COPY . . RUN make clean -RUN make build BINS=rpc - -RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/chat-rpc +RUN make build BINS=admin-rpc FROM ghcr.io/openim-sigs/openim-bash-image:latest @@ -43,7 +41,12 @@ WORKDIR ${CHAT_WORKDIR} COPY --from=builder ${OPENIM_CHAT_BINDIR}/platforms /openim/openim-chat/_output/bin/platforms COPY --from=builder ${OPENIM_CHAT_CONFIG_NAME} /openim/openim-chat/config/config.yaml -ENV PORT=30200 -EXPOSE ${PORT} CMD ["bash", "-c", "${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/admin-rpc --port ${PORT} --config_folder_path ${OPENIM_CHAT_CONFIG_NAME}"] + +ENV PORT=30200 +EXPOSE 30200 + +RUN mv ${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/admin-rpc /usr/bin/admin-rpc + +ENTRYPOINT ["bash", "-c", "admin-rpc --port $PORT -c $OPENIM_CHAT_CONFIG_NAME"] diff --git a/build/docker/rpc-chat/Dockerfile b/build/docker/rpc-chat/Dockerfile index 62d80aee..436254ba 100644 --- a/build/docker/rpc-chat/Dockerfile +++ b/build/docker/rpc-chat/Dockerfile @@ -32,7 +32,7 @@ RUN go mod download COPY . . RUN make clean -RUN make build BINS=rpc +RUN make build BINS=chat-rpc RUN rm -rf ./_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/admin-rpc @@ -44,6 +44,8 @@ COPY --from=builder ${OPENIM_CHAT_BINDIR}/platforms /openim/openim-chat/_output/ COPY --from=builder ${OPENIM_CHAT_CONFIG_NAME} /openim/openim-chat/config/config.yaml ENV PORT=30300 +EXPOSE 30300 -EXPOSE ${PORT} -CMD ["bash", "-c","${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/chat-rpc --port ${PORT} --config_folder_path ${OPENIM_CHAT_CONFIG_NAME}"] \ No newline at end of file +RUN mv ${OPENIM_CHAT_BINDIR}/platforms/$(get_os)/$(get_arch)/chat-rpc /usr/bin/chat-rpc + +ENTRYPOINT ["bash", "-c", "chat-rpc --port $PORT -c $OPENIM_CHAT_CONFIG_NAME"]