From f72e41207fae7360efb6479995985adcf069fe87 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw)" <3293172751nss@gmail.com> Date: Fri, 20 Oct 2023 02:26:52 +0800 Subject: [PATCH] feat: fix openim ci and deployment Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --- .github/workflows/build-docker-image.yml | 9 ++++ .github/workflows/build-openim-web-image.yml | 43 ++++---------------- README.md | 2 +- build/images/Dockerfile | 10 +++++ deployments/README.md | 10 +++++ install.sh | 8 ++-- scripts/make-rules/common.mk | 1 + scripts/make-rules/image.mk | 11 +++-- 8 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 build/images/Dockerfile diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 735c160df..79b60fbed 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -120,6 +120,15 @@ jobs: uses: docker/metadata-action@v5.0.0 with: images: ghcr.io/openimsdk/openim-server + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - name: Log in to GitHub Container Registry uses: docker/login-action@v3 diff --git a/.github/workflows/build-openim-web-image.yml b/.github/workflows/build-openim-web-image.yml index 800500af6..e040d5270 100644 --- a/.github/workflows/build-openim-web-image.yml +++ b/.github/workflows/build-openim-web-image.yml @@ -114,15 +114,12 @@ jobs: uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 +# ghcr.io/openimsdk/openim-web:latest + - name: Extract metadata (tags, labels) for Docker + id: meta2 + uses: docker/metadata-action@v5.0.0 with: - install: true - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- + images: ghcr.io/openimsdk/openim-web - name: Log in to GitHub Container Registry uses: docker/login-action@v3 @@ -131,38 +128,12 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker openim-web - id: meta1 - uses: docker/metadata-action@v5.0.0 - with: - images: ghcr.io/openimsdk/openim-web - - - name: Build and push Docker image for openim-web + - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . file: ./build/images/openim-tools/openim-web/Dockerfile platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta1.outputs.tags }} - labels: ${{ steps.meta1.outputs.labels }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache - - - name: Extract metadata (tags, labels) for Docker openim-web - id: meta2 - uses: docker/metadata-action@v5.0.0 - with: - images: ghcr.io/openimsdk/component - - - name: Build and push Docker image for component - uses: docker/build-push-action@v5 - with: - context: . - file: ./build/images/openim-tools/component/Dockerfile - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta2.outputs.tags }} - labels: ${{ steps.meta2.outputs.labels }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + labels: ${{ steps.meta2.outputs.labels }} \ No newline at end of file diff --git a/README.md b/README.md index d2482f59c..30499824c 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ It is recommended to use Docker Compose for deployment, which can easily and qui
Compile from Source -Ur need `Go 1.18` or higher version, and `make`. +Ur need `Go 1.20` or higher version, and `make`. ```bash diff --git a/build/images/Dockerfile b/build/images/Dockerfile new file mode 100644 index 000000000..518de78b1 --- /dev/null +++ b/build/images/Dockerfile @@ -0,0 +1,10 @@ +FROM BASE_IMAGE + +WORKDIR ${SERVER_WORKDIR} + +# Set HTTP proxy +ARG BINARY_NAME + +COPY BINARY_NAME ./bin/BINARY_NAME + +ENTRYPOINT ["./bin/BINARY_NAME"] \ No newline at end of file diff --git a/deployments/README.md b/deployments/README.md index 4a93ff334..e070d8e1f 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -103,6 +103,16 @@ $ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bas $ helm repo add brigade https://openimsdk.github.io/openim-charts ``` +### OpenIM 的镜像策略 + +自动化提供的 aliyun, ghcr, docker hub: https://github.com/openimsdk/open-im-server/blob/main/docs/conversions/images.md + +**本地化测试构建方法:** + +```bash +$ make image +``` + ### 容器化安装 diff --git a/install.sh b/install.sh index d43767362..9809646fa 100755 --- a/install.sh +++ b/install.sh @@ -40,7 +40,7 @@ REPO="Open-IM-Server" # Version of Go you want to use, make sure it is compatible with your OpenIM-Server requirements. # Default is 1.18, if you want to use a different version, replace accordingly. -GO_VERSION="1.18" +GO_VERSION="1.20" # Default HTTP_PORT is 80. If you want to use a different port, uncomment and replace the value. # HTTP_PORT=80 @@ -168,7 +168,7 @@ function install_go() { command -v go >/dev/null 2>&1 # Determines if GO_VERSION is defined if [ -z "$GO_VERSION" ]; then - GO_VERSION="1.18" + GO_VERSION="1.20" fi if [[ $? -ne 0 ]]; then @@ -309,7 +309,7 @@ function cmd_help() { color_echo ${BLUE_PREFIX} "-t, --tag ${CYAN_PREFIX}specify the tag (default option, set to latest if not specified)${COLOR_SUFFIX}" color_echo ${BLUE_PREFIX} "-r, --release ${CYAN_PREFIX}specify the release branch (cannot be used with the tag option)${COLOR_SUFFIX}" color_echo ${BLUE_PREFIX} "-gt, --github-token ${CYAN_PREFIX}set the GITHUB_TOKEN (default: not set)${COLOR_SUFFIX}" - color_echo ${BLUE_PREFIX} "-g, --go-version ${CYAN_PREFIX}set the Go language version (default: GO_VERSION=\"1.18\")${COLOR_SUFFIX}" + color_echo ${BLUE_PREFIX} "-g, --go-version ${CYAN_PREFIX}set the Go language version (default: GO_VERSION=\"1.20\")${COLOR_SUFFIX}" color_echo ${BLUE_PREFIX} "--install-dir ${CYAN_PREFIX}set the OpenIM installation directory (default: /tmp)${COLOR_SUFFIX}" color_echo ${BLUE_PREFIX} "--cpu ${CYAN_PREFIX}set the number of concurrent processes${COLOR_SUFFIX}" echo @@ -329,7 +329,7 @@ function parseinput() { # CHINA=false # TAG=latest # RELEASE="" - # GO_VERSION=1.18 + # GO_VERSION=1.20 # INSTALL_DIR=/tmp # GITHUB_TOKEN="" # CPU=$(nproc) diff --git a/scripts/make-rules/common.mk b/scripts/make-rules/common.mk index f72d22f73..99ceea7e0 100644 --- a/scripts/make-rules/common.mk +++ b/scripts/make-rules/common.mk @@ -167,6 +167,7 @@ define MAKEFILE_EXAMPLE # make install-deepcopy-gen Install deepcopy-gen tools if the license is missing. # make build BINS=openim-api V=1 DEBUG=1 Build debug binaries for only openim-api. # make multiarch -j PLATFORMS="linux_arm64 linux_amd64" V=1 Build binaries for both platforms. +# make image endef export MAKEFILE_EXAMPLE diff --git a/scripts/make-rules/image.mk b/scripts/make-rules/image.mk index ef275360b..09e92126b 100644 --- a/scripts/make-rules/image.mk +++ b/scripts/make-rules/image.mk @@ -42,8 +42,8 @@ endif # Determine image files by looking into build/images/*/Dockerfile IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/images/*) -# Determine images names by stripping out the dir names -IMAGES ?= $(filter-out tools,$(foreach image,${IMAGES_DIR},$(notdir ${image}))) +# Determine images names by stripping out the dir names, and filter out the undesired directories +IMAGES ?= $(filter-out Dockerfile openim-tools openim-cmdutils,$(foreach image,${IMAGES_DIR},$(notdir ${image}))) ifeq (${IMAGES},) $(error Could not determine IMAGES, set ROOT_DIR or run in source dir) @@ -100,10 +100,9 @@ image.build.%: go.build.% $(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM)))) @echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)" @mkdir -p $(TMP_DIR)/$(IMAGE)/$(PLATFORM) - @awk '/FROM/ {c++; if (c==2) {print; next}} c>=2' $(ROOT_DIR)/build/images/$(IMAGE)/Dockerfile \ -| sed -e "s#BASE_IMAGE#$(BASE_IMAGE)#g" \ - -e 's/--from=builder //g' \ - -e 's#COPY /openim/openim-server/#COPY ./#g' > $(TMP_DIR)/$(IMAGE)/Dockerfile + @cat $(ROOT_DIR)/build/images/Dockerfile\ + | sed "s#BASE_IMAGE#$(BASE_IMAGE)#g" \ + | sed "s#BINARY_NAME#$(IMAGE)#g" >$(TMP_DIR)/$(IMAGE)/Dockerfile @cp $(BIN_DIR)/platforms/$(IMAGE_PLAT)/$(IMAGE) $(TMP_DIR)/$(IMAGE) $(eval BUILD_SUFFIX := $(_DOCKER_BUILD_EXTRA_ARGS) --pull -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE)) @if [ $(shell $(GO) env GOARCH) != $(ARCH) ] ; then \