From fd3c19d6a5e0aafb250af8b01f414a3997dd2430 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 13 Jul 2023 15:45:03 +0800 Subject: [PATCH] feat: add test file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .dockerignore | 31 +++++++++++++++ .github/workflows/build-docker-image.yml | 36 +++++++++++++++++ .github/workflows/openim-ci.yml | 21 +--------- Dockerfile | 50 +++++++++++++----------- docker-compose.yaml | 2 +- scripts/build_all_service.sh | 18 +++------ 6 files changed, 101 insertions(+), 57 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build-docker-image.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..9faeff616 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# Ignore files and directories starting with a dot + +# Ignore specific files +.dockerignore + +# Ignore build artifacts +_output/ +logs/ + +# Ignore non-essential documentation +README.md +README-zh_CN.md +CONTRIBUTING.md +CHANGELOG/ +# LICENSE + +# Ignore testing and linting configuration +.golangci.yml + +# Ignore deployment-related files +docker-compose.yaml +deployments/ + +# Ignore assets +assets/ + +# Ignore components +components/ + +# Ignore tools and scripts +.github/ diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml new file mode 100644 index 000000000..553ae5d10 --- /dev/null +++ b/.github/workflows/build-docker-image.yml @@ -0,0 +1,36 @@ +name: OpenIM Build Docker Images +on: + push: + tags: + - v* +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + bin: + - ssserver + - sslocal + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker metadata + id: metadata + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository_owner }}/openim-${{ matrix.bin }} + - name: Build and release Docker images + uses: docker/build-push-action@v3 + with: + platforms: linux/386,linux/amd64,linux/arm64/v8 + target: ${{ matrix.bin }} + tags: ${{ steps.metadata.outputs.tags }} + push: true \ No newline at end of file diff --git a/.github/workflows/openim-ci.yml b/.github/workflows/openim-ci.yml index 73b30e42b..6460a43b1 100644 --- a/.github/workflows/openim-ci.yml +++ b/.github/workflows/openim-ci.yml @@ -83,7 +83,7 @@ jobs: - name: Build source code for host platform run: | - make multiarch + make build echo "Build source code for host platform successfully" # - name: Collect Test Coverage File @@ -132,22 +132,3 @@ jobs: # - name: Test docker image # run: | # docker build -t openim:ci-build . - -# goreleaser-test: -# runs-on: ubuntu-20.04 -# steps: -# - name: Checkout -# uses: actions/checkout@v3 -# with: -# fetch-depth: 0 - -# - name: Set up Go -# uses: actions/setup-go@v3 -# with: -# go-version: ${{ env.GO_VERSION }} - -# - name: Run GoReleaser -# uses: goreleaser/goreleaser-action@v4 -# with: -# version: latest -# args: release --clean --skip-publish --snapshot diff --git a/Dockerfile b/Dockerfile index 579c0c1d6..09cb0b3b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,43 @@ +# Build Stage FROM golang as build -# go mod Installation source, container environment variable addition will override the default variable value -ENV GO111MODULE=on -ENV GOPROXY=https://goproxy.cn,direct +# Set go mod installation source and proxy +ARG GO111MODULE=on +ARG GOPROXY=https://goproxy.cn,direct +ENV GO111MODULE=$GO111MODULE +ENV GOPROXY=$GOPROXY # Set up the working directory WORKDIR /Open-IM-Server -# add all files to the container -COPY . . -WORKDIR /Open-IM-Server/scripts -RUN chmod +x *.sh - -RUN /bin/sh -c ./build_all_service.sh +# Copy all files to the container +ADD . . -#Blank image Multi-Stage Build -FROM ubuntu +RUN /bin/sh -c "make build" -RUN rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata +# Production Stage +FROM alpine +RUN apk --no-cache add tzdata -#set directory to map logs,config file,scripts file. -VOLUME ["/Open-IM-Server/logs","/Open-IM-Server/config","/Open-IM-Server/scripts","/Open-IM-Server/db/sdk"] +# Set directory to map logs, config files, scripts, and SDK +VOLUME ["/Open-IM-Server/logs", "/Open-IM-Server/config", "/Open-IM-Server/scripts", "/Open-IM-Server/db/sdk"] -#Copy scripts files and binary files to the blank image +# Copy scripts and binary files to the production image COPY --from=build /Open-IM-Server/scripts /Open-IM-Server/scripts -COPY --from=build /Open-IM-Server/_output/bin/platforms/linux/amd64 /Open-IM-Server/_output/bin/platforms/linux/amd64 +COPY --from=build /Open-IM-Server/_output/bin/platforms/linux/arm64 /Open-IM-Server/_output/bin/platforms/linux/arm64 WORKDIR /Open-IM-Server/scripts CMD ["./docker_start_all.sh"] + +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le +.PHONY: docker-buildx +docker-buildx: test ## Build and push docker image for the manager for cross-platform support + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + - $(CONTAINER_TOOL) buildx create --name project-v3-builder + $(CONTAINER_TOOL) buildx use project-v3-builder + - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx rm project-v3-builder + rm Dockerfile.cross \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index cea3b1480..842b05ae5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -100,7 +100,7 @@ services: openim_server: - image: ghcr.io/openimsdk/openim-server:v3.0.0-alpha.0 + image: ghcr.io/openimsdk/openim-server:v3.0.0-alpha.1 container_name: openim-server volumes: - ./logs:/Open-IM-Server/logs diff --git a/scripts/build_all_service.sh b/scripts/build_all_service.sh index 3fd56b420..30c671d48 100755 --- a/scripts/build_all_service.sh +++ b/scripts/build_all_service.sh @@ -37,10 +37,12 @@ echo -e "${BOLD_PREFIX}_________________________________________________________ bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" sdk_db_dir="$OPENIM_ROOT/db/sdk/" + +echo "==> bin_dir=$bin_dir" +echo "==> logs_dir=$logs_dir" +echo "==> sdk_db_dir=$sdk_db_dir" + # Automatically created when there is no bin, logs folder -if [ ! -d $bin_dir ]; then - mkdir -p $bin_dir -fi if [ ! -d $logs_dir ]; then mkdir -p $logs_dir fi @@ -48,16 +50,6 @@ if [ ! -d $sdk_db_dir ]; then mkdir -p $sdk_db_dir fi -#Include shell font styles and some basic information -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. - -echo "PWD=================>$PWD" - -#Include shell font styles and some basic information -source ./style_info.sh -source ./path_info.sh -source ./function.sh - cd $OPENIM_ROOT # Execute 'make build'