diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index df636bb95..9a497ff52 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -22,6 +22,11 @@ on: - v* workflow_dispatch: +env: + # Common versions + GO_VERSION: "1.20" + DEFAULT_OWNER: "OpenIMSDK" + jobs: build: runs-on: ubuntu-latest @@ -29,12 +34,16 @@ jobs: - name: Check out the repo uses: actions/checkout@v3 -# build chat - - name: Build chat + - name: Setup Golang with cache + uses: magnetikonline/action-golang-cache@v3 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Dependencies run: | - sudo make build - cd scripts - sudo ./build_all_service.sh + sudo apt update && sudo apt install -y gcc-aarch64-linux-gnu \ + libbtrfs-dev libgpgme-dev libdevmapper-dev \ + qemu-user-static binfmt-support # docker.io/openim/openim-chat:latest - name: Extract metadata (tags, labels) for Docker @@ -75,6 +84,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta2.outputs.tags }} labels: ${{ steps.meta2.outputs.labels }} @@ -100,4 +110,3 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta3.outputs.tags }} labels: ${{ steps.meta3.outputs.labels }} - diff --git a/.github/workflows/chatci.yml b/.github/workflows/chatci.yml index ba04cca5c..8233d2391 100644 --- a/.github/workflows/chatci.yml +++ b/.github/workflows/chatci.yml @@ -82,13 +82,4 @@ jobs: - name: Build source code for host platform run: | sudo make build - echo "Build source code for host platform successfully" - - # - name: Collect Test Coverage File - # uses: actions/upload-artifact@v1.0.0 - # with: - # name: main-output - # path: _output/tmp/coverage.out - - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v1 + echo "Build source code for host platform successfully" \ No newline at end of file diff --git a/.github/workflows/docker-buildx.yml b/.github/workflows/docker-buildx.yml index 0b3efc90f..e3b2c170b 100644 --- a/.github/workflows/docker-buildx.yml +++ b/.github/workflows/docker-buildx.yml @@ -1,35 +1,105 @@ -name: OpenIM Build Docker Images +name: OpenIM Buildx Docker Images + on: - push: - tags: - - v* + schedule: + - cron: "0 10 * * *" + push: + branches: + - "**" + tags: + - "v*.*.*" + pull_request: + branches: + - "main" + +env: + IMAGE_NAME: openim-chat + # Common versions + GO_VERSION: "1.20" + DEFAULT_OWNER: "OpenIMSDK" + jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - bin: - - openim-chat + # strategy: + # matrix: + # bin: + # - openim-chat steps: - name: Checkout uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + + - name: Setup Golang with cache + uses: magnetikonline/action-golang-cache@v3 with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} + go-version: ${{ env.GO_VERSION }} + + - name: Install Dependencies + run: | + sudo apt update && sudo apt install -y gcc-aarch64-linux-gnu \ + libbtrfs-dev libgpgme-dev libdevmapper-dev \ + qemu-user-static binfmt-support + - name: Docker metadata - id: metadata + id: meta uses: docker/metadata-action@v4 with: - images: ghcr.io/${{ github.repository_owner }}/openim-${{ matrix.bin }} + # list of Docker images to use as base name for tags + # registry.cn-hangzhou.aliyuncs.com/${{github.repository_owner}}/${{env.IMAGE_NAME}} + # ghcr.io/${{github.repository_owner}}/${{env.IMAGE_NAME}} + + images: | + openim/${{env.IMAGE_NAME}} + + # 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 Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and release Docker images - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 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 + context: . + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }},latest + push: ${{ github.event_name != 'pull_request' }} + labels: ${{ steps.meta.outputs.labels }} + + # - name: Log in to GitHub Container Registry + # uses: docker/login-action@v2 + # with: + # registry: ghcr.io + # username: ${{ github.actor }} + # password: ${{ secrets.GITHUB_TOKEN }} + + # - name: Log in to AliYun Docker Hub + # uses: docker/login-action@v2 + # with: + # registry: registry.cn-hangzhou.aliyuncs.com + # username: ${{ secrets.ALIREGISTRY_USERNAME }} + # password: ${{ secrets.ALIREGISTRY_TOKEN }} + + # - name: Build and release Docker images + # uses: docker/build-push-action@v4 + # with: + # context: . + # platforms: linux/amd64,linux/arm64 + # tags: ${{ steps.meta.outputs.tags }},latest + # push: ${{ github.event_name != 'pull_request' }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 952ef67fc..32bf70d99 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,6 +24,11 @@ jobs: go-version: stable # More assembly might be required: Docker logins, GPG, etc. It all depends # on your needs. + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - name: Log in to Docker Hub uses: docker/login-action@v2 @@ -53,6 +58,7 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + USERNAME: ${{ github.repository_owner }} # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' # distribution: # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.github/workflows/scripts-test.yml b/.github/workflows/scripts-test.yml new file mode 100644 index 000000000..6d254973a --- /dev/null +++ b/.github/workflows/scripts-test.yml @@ -0,0 +1,68 @@ +# Copyright © 2023 OpenIM. All rights reserved. +# +# Licensed 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. + +name: OpenIM Start Execute Scripts + +on: + push: + branches: + - main + paths-ignore: + - "docs/**" + - "README.md" + - "README_zh-CN.md" + - "CONTRIBUTING.md" + pull_request: + branches: + - main + paths-ignore: + - "README.md" + - "README_zh-CN.md" + - "CONTRIBUTING.md" + - "docs/**" + +jobs: + execute-scripts: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Build Chat + run: | + sudo make build + sudo chmod +x ./scripts/build_all_service.sh + sudo ./scripts/build_all_service.sh + shell: bash + + - name: start all services + run: | + sudo chmod +x ./scripts/start_all.sh + sudo ./scripts/start_all.sh + shell: bash + + - name: Check all services + run: | + sudo chmod +x ./scripts/check_all.sh + sudo ./scripts/check_all.sh + sudo cat logs/openIM.log 2>/dev/null + shell: bash + + - name: Print openIM.log + run: | + sudo cat logs/* 2>/dev/null + sudo cat logs/* 2>/dev/null >> "$GITHUB_OUTPUT" + shell: bash + continue-on-error: true diff --git a/.goreleaser.yaml b/.goreleaser.yaml index bfae363ea..59ef132e1 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -218,6 +218,7 @@ dockers: - "--label=org.opencontainers.image.version={{.Version}}" - "--label=org.opencontainers.image.source={{.GitURL}}" - "--platform=linux/amd64" + goarch: amd64 - image_templates: - "openim/openim-chat:{{ .Tag }}-arm64" @@ -240,31 +241,31 @@ dockers: - "--platform=linux/arm64" goarch: arm64 -docker_manifests: - - name_template: "openim/openim-chat:{{ .Tag }}" - image_templates: - - "openim/openim-chat:{{ .Tag }}-amd64" - - "openim/openim-chat:{{ .Tag }}-arm64" - - name_template: "ghcr.io/openimsdk/openim-chat:{{ .Tag }}" - image_templates: - - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-amd64" - - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-arm64" - - name_template: "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}" - image_templates: - - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-amd64" - - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-arm64" - - name_template: "openim/openim-chat:latest" - image_templates: - - "openim/openim-chat:{{ .Tag }}-amd64" - - "openim/openim-chat:{{ .Tag }}-arm64" - - name_template: "ghcr.io/openimsdk/openim-chat:latest" - image_templates: - - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-amd64" - - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-arm64" - - name_template: "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:latest" - image_templates: - - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-amd64" - - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-arm64" +# docker_manifests: +# - name_template: "openim/openim-chat:{{ .Tag }}" +# image_templates: +# - "openim/openim-chat:{{ .Tag }}-amd64" +# - "openim/openim-chat:{{ .Tag }}-arm64" +# - name_template: "ghcr.io/openimsdk/openim-chat:{{ .Tag }}" +# image_templates: +# - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-amd64" +# - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-arm64" +# - name_template: "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}" +# image_templates: +# - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-amd64" +# - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-arm64" +# - name_template: "openim/openim-chat:latest" +# image_templates: +# - "openim/openim-chat:{{ .Tag }}-amd64" +# - "openim/openim-chat:{{ .Tag }}-arm64" +# - name_template: "ghcr.io/openimsdk/openim-chat:latest" +# image_templates: +# - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-amd64" +# - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-arm64" +# - name_template: "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:latest" +# image_templates: +# - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-amd64" +# - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-arm64" nfpms: - id: packages @@ -341,6 +342,9 @@ checksum: release: footer: | + + ## Welcome to the {{ .Tag }} release of [chat](https://github.com/OpenIMSDK/chat)!🎉🎉! + **Full Changelog**: https://github.com/OpenIMSDK/chat/compare/{{ .PreviousTag }}...{{ .Tag }} ## Helping out diff --git a/Dockerfile b/Dockerfile index 3decabdc6..2dff2ed7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,16 +5,14 @@ WORKDIR /workspace ENV GOPROXY=https://goproxy.cn -# Copy go mod and go sum files then download dependencies -COPY go.mod go.sum ./ -RUN go mod download - ARG GOARCH ARG GOOS # Copy source code files into the image COPY . . +RUN go mod download + # Compile the source code RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_admin ./cmd/rpc/admin RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_admin_api ./cmd/api/admin_api