复制项目

This commit is contained in:
kim.dev.6789
2026-01-14 22:16:44 +08:00
parent e2577b8cee
commit e50142a3b9
691 changed files with 97009 additions and 1 deletions

65
build/README.md Normal file
View File

@@ -0,0 +1,65 @@
# Building OpenIM
Building OpenIM is easy if you take advantage of the containerized build environment. This document will help guide you through understanding this build process.
## Requirements
1. Docker, using one of the following configurations:
* **macOS** Install Docker for Mac. See installation instructions [here](https://docs.docker.com/docker-for-mac/).
**Note**: You will want to set the Docker VM to have at least 4GB of initial memory or building will likely fail.
* **Linux with local Docker** Install Docker according to the [instructions](https://docs.docker.com/installation/#installation) for your OS.
* **Windows with Docker Desktop WSL2 backend** Install Docker according to the [instructions](https://docs.docker.com/docker-for-windows/wsl-tech-preview/). Be sure to store your sources in the local Linux file system, not the Windows remote mount at `/mnt/c`.
**Note**: You will need to check if Docker CLI plugin buildx is properly installed (`docker-buildx` file should be present in `~/.docker/cli-plugins`). You can install buildx according to the [instructions](https://github.com/docker/buildx/blob/master/README.md#installing).
2. **Optional** [Google Cloud SDK](https://developers.google.com/cloud/sdk/)
You must install and configure Google Cloud SDK if you want to upload your release to Google Cloud Storage and may safely omit this otherwise.
## Actions
About [Images packages](https://github.com/orgs/OpenIMSDK/packages?repo_name=Open-IM-Server)
All files in the `build/images` directory are not templated and are instead rendered by Github Actions, which is an automated process.
Trigger condition:
1. create a new tag with the format `vX.Y.Z` (e.g. `v1.0.0`)
2. push the tag to the remote repository
3. wait for the build to finish
4. download the artifacts from the release page
## Make images
**help info:**
```bash
$ make image.help
```
**build images:**
```bash
$ make image
```
## Overview
While it is possible to build OpenIM using a local golang installation, we have a build process that runs in a Docker container. This simplifies initial set up and provides for a very consistent build and test environment.
## Basic Flow
The scripts directly under [`build/`](.) are used to build and test. They will ensure that the `openim-build` Docker image is built (based on [`build/build-image/Dockerfile`](../Dockerfile) and after base image's `OPENIM_BUILD_IMAGE_CROSS_TAG` from Dockerfile is replaced with one of those actual tags of the base image, like `v1.13.9-2`) and then execute the appropriate command in that container. These scripts will both ensure that the right data is cached from run to run for incremental builds and will copy the results back out of the container. You can specify a different registry/name and version for `openim-cross` by setting `OPENIM_CROSS_IMAGE` and `OPENIM_CROSS_VERSION`, see [`common.sh`](common.sh) for more details.
The `openim-build` container image is built by first creating a "context" directory in `_output/images/build-image`. It is done there instead of at the root of the OpenIM repo to minimize the amount of data we need to package up when building the image.
There are 3 different containers instances that are run from this image. The first is a "data" container to store all data that needs to persist across to support incremental builds. Next there is an "rsync" container that is used to transfer data in and out to the data container. Lastly there is a "build" container that is used for actually doing build actions. The data container persists across runs while the rsync and build containers are deleted after each use.
`rsync` is used transparently behind the scenes to efficiently move data in and out of the container. This will use an ephemeral port picked by Docker. You can modify this by setting the `OPENIM_RSYNC_PORT` env variable.
All Docker names are suffixed with a hash derived from the file path (to allow concurrent usage on things like CI machines) and a version number. When the version number changes all state is cleared and clean build is started. This allows the build infrastructure to be changed and signal to CI systems that old artifacts need to be deleted.
## Build artifacts
The build system output all its products to a top level directory in the source repository named `_output`.
These include the binary compiled packages (e.g. imctl, openim-api etc.) and archived Docker images.
If you intend to run a component with a docker image you will need to import it from this directory with

431
build/goreleaser.yaml Normal file
View File

@@ -0,0 +1,431 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
- make clean
# You may remove this if you don't use go modules.
- make tidy
- make copyright.add
# you may remove this if you don't need go generate
- go generate ./...
git:
# What should be used to sort tags when gathering the current and previous
# tags if there are more than one tag in the same commit.
#
# Default: '-version:refname'
tag_sort: -version:creatordate
# What should be used to specify prerelease suffix while sorting tags when gathering
# the current and previous tags if there are more than one tag in the same commit.
#
# Since: v1.17
prerelease_suffix: "-"
# Tags to be ignored by GoReleaser.
# This means that GoReleaser will not pick up tags that match any of the
# provided values as either previous or current tags.
#
# Templates: allowed.
# Since: v1.21.
ignore_tags:
- nightly
# - "{{.Env.IGNORE_TAG}}"
snapshot:
name_template: "{{ incpatch .Version }}-next"
# gomod:
# proxy: true
report_sizes: true
# metadata:
# mod_timestamp: "{{ .CommitTimestamp }}"
builds:
- binary: openim-api
id: openim-api
main: ./cmd/openim-api/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-cmdutils
id: openim-cmdutils
main: ./cmd/openim-cmdutils/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-crontask
id: openim-crontask
main: ./cmd/openim-crontask/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-msggateway
id: openim-msggateway
main: ./cmd/openim-msggateway/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-msgtransfer
id: openim-msgtransfer
main: ./cmd/openim-msgtransfer/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-push
id: openim-push
main: ./cmd/openim-push/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-auth
id: openim-rpc-auth
main: ./cmd/openim-rpc/openim-rpc-auth/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-conversation
id: openim-rpc-conversation
main: ./cmd/openim-rpc/openim-rpc-conversation/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-friend
id: openim-rpc-friend
main: ./cmd/openim-rpc/openim-rpc-friend/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-group
id: openim-rpc-group
main: ./cmd/openim-rpc/openim-rpc-group/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-msg
id: openim-rpc-msg
main: ./cmd/openim-rpc/openim-rpc-msg/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-third
id: openim-rpc-third
main: ./cmd/openim-rpc/openim-rpc-third/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
- binary: openim-rpc-user
id: openim-rpc-user
main: ./cmd/openim-rpc/openim-rpc-user/main.go
goos:
- darwin
- windows
- linux
goarch:
- amd64
- arm64
# TODONeed a script, such as the init - release to help binary to find the right directory
# ,which can be compiled binary
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# Set this to true if you want all files in the archive to be in a single directory.
# If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz',
# you'll get a folder 'goreleaser_Linux_arm64'.
# If set to false, all files are extracted separately.
# You can also set it to a custom folder name (templating is supported).
wrap_in_directory: true
# use zip for windows archives
files:
- CHANGELOG/*
- deployment/*
- config/*
- build/*
- scripts/*
- Makefile
- install.sh
- docs/*
- src: "*.md"
dst: docs
# Strip parent folders when adding files to the archive.
strip_parent: true
# File info.
# Not all fields are supported by all formats available formats.
#
# Default: copied from the source file
info:
# Templates: allowed (since v1.14)
owner: root
# Templates: allowed (since v1.14)
group: root
# Must be in time.RFC3339Nano format.
#
# Templates: allowed (since v1.14)
mtime: "{{ .CommitDate }}"
# File mode.
mode: 0644
format_overrides:
- goos: windows
format: zip
changelog:
sort: asc
use: github
filters:
exclude:
- "^test:"
- "^chore"
- "merge conflict"
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 300
- title: "New Features"
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: "Security updates"
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
order: 150
- title: "Bug fixes"
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: "Documentation updates"
regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$
order: 400
- title: "Build process updates"
regexp: ^.*?build(\([[:word:]]+\))??!?:.+$
order: 400
- title: Other work
order: 9999
# dockers:
# - image_templates:
# - "openimsdk/open-im-server-deploy:{{ .Tag }}-amd64"
# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64"
# dockerfile: build/images/openim-api/Dockerfile.release
# ids:
# - openim-api
# use: buildx
# build_flag_templates:
# - "--pull"
# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/openimsdk/open-im-server-deploy/main/README.md"
# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/openimsdk/open-im-server-deploy/blob/main/assets/logo/openim-logo-green.png"
# - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]'
# - "--label=io.artifacthub.package.license=Apace-2.0"
# - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system"
# - "--label=org.opencontainers.image.created={{.Date}}"
# - "--label=org.opencontainers.image.name={{.ProjectName}}"
# - "--label=org.opencontainers.image.revision={{.FullCommit}}"
# - "--label=org.opencontainers.image.version={{.Version}}"
# - "--label=org.opencontainers.image.source={{.GitURL}}"
# - "--platform=linux/amd64"
# extra_files:
# - scripts/entrypoint.sh
# - image_templates:
# - "goreleaser/goreleaser:{{ .Tag }}-arm64"
# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64"
# dockerfile: build/images/openim-api/Dockerfile.release
# use: buildx
# build_flag_templates:
# - "--pull"
# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/openimsdk/open-im-server-deploy/main/README.md"
# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/openimsdk/open-im-server-deploy/blob/main/assets/logo/openim-logo-green.png"
# - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]'
# - "--label=io.artifacthub.package.license=Apace-2.0"
# - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system"
# - "--label=org.opencontainers.image.created={{.Date}}"
# - "--label=org.opencontainers.image.name={{.ProjectName}}"
# - "--label=org.opencontainers.image.revision={{.FullCommit}}"
# - "--label=org.opencontainers.image.version={{.Version}}"
# - "--label=org.opencontainers.image.source={{.GitURL}}"
# - "--platform=linux/arm64"
# goarch: arm64
# extra_files:
# - scripts/entrypoint.sh
# docker_manifests:
# - name_template: "goreleaser/goreleaser:{{ .Tag }}"
# image_templates:
# - "goreleaser/goreleaser:{{ .Tag }}-amd64"
# - "goreleaser/goreleaser:{{ .Tag }}-arm64"
# - name_template: "ghcr.io/goreleaser/goreleaser:{{ .Tag }}"
# image_templates:
# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64"
# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64"
# - name_template: "goreleaser/goreleaser:latest"
# image_templates:
# - "goreleaser/goreleaser:{{ .Tag }}-amd64"
# - "goreleaser/goreleaser:{{ .Tag }}-arm64"
# - name_template: "ghcr.io/goreleaser/goreleaser:latest"
# image_templates:
# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64"
# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64"
nfpms:
- id: packages
builds:
- openim-api
- openim-cmdutils
- openim-crontask
- openim-msggateway
- openim-msgtransfer
- openim-push
- openim-rpc-auth
- openim-rpc-conversation
- openim-rpc-friend
- openim-rpc-group
- openim-rpc-msg
- openim-rpc-third
- openim-rpc-user
# Your app's vendor.
vendor: OpenIMSDK
homepage: https://github.com/openimsdk/open-im-server-deploy
maintainer: kubbot <https://github.com/kubbot>
description: |-
Auto sync github labels
kubbot && openimbot
license: MIT
formats:
- apk
- deb
- rpm
- termux.deb # Since: v1.11
- archlinux # Since: v1.13
dependencies:
- git
recommends:
- golang
# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
# Default: './dist'
dist: ./_output/dist
# .goreleaser.yaml
milestones:
# You can have multiple milestone configs
-
# Repository for the milestone
# Default is extracted from the origin remote URL
repo:
owner: OpenIMSDK
name: Open-IM-Server
# Whether to close the milestone
close: true
# Fail release on errors, such as missing milestone.
fail_on_error: false
# Name of the milestone
#
# Default: '{{ .Tag }}'
name_template: "Current Release"
# publishers:
# - name: "fury.io"
# ids:
# - packages
# dir: "{{ dir .ArtifactPath }}"
# cmd: |
# bash -c '
# if [[ "{{ .Tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# curl -F package=@{{ .ArtifactName }} https://{{ .Env.FURY_TOKEN }}@push.fury.io/{{ .Env.USERNAME }}/
# else
# echo "Skipping deployment: Non-production release detected"
# fi'
checksum:
name_template: "{{ .ProjectName }}_checksums.txt"
algorithm: sha256
release:
prerelease: auto

24
build/images/Dockerfile Normal file
View File

@@ -0,0 +1,24 @@
# # 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.
# FROM BASE_IMAGE
# WORKDIR ${SERVER_WORKDIR}
# # Set HTTP proxy
# ARG BINARY_NAME
# COPY BINARY_NAME ./bin/BINARY_NAME
# ENTRYPOINT ["./bin/BINARY_NAME"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory first (must be before COPY . . to avoid conflicts)
# This copies protocol to /protocol, which is ../protocol relative to SERVER_DIR
COPY protocol /protocol
# Copy current directory
COPY . .
RUN echo "执行 go mod tidy..." && go mod tidy || (echo "go mod tidy 失败" && exit 1)
RUN echo "开始编译 openim-api..." && \
go build -v -o _output/openim-api ./cmd/openim-api || \
(echo "编译失败,查看详细错误信息" && exit 1)
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-api"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-crontask ./cmd/openim-crontask
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-crontask"]

View File

@@ -0,0 +1,43 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory first (must be before COPY . . to avoid conflicts)
# This copies protocol to /protocol, which is ../protocol relative to SERVER_DIR
COPY protocol /protocol
# Copy current directory
COPY . .
RUN echo "执行 go mod tidy..." && go mod tidy || (echo "go mod tidy 失败" && exit 1)
RUN echo "开始编译 openim-msggateway..." && \
go build -v -o _output/openim-msggateway ./cmd/openim-msggateway || \
(echo "编译失败,查看详细错误信息" && exit 1)
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-msggateway"]

View File

@@ -0,0 +1,43 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory first (must be before COPY . . to avoid conflicts)
# This copies protocol to /protocol, which is ../protocol relative to SERVER_DIR
COPY protocol /protocol
# Copy current directory
COPY . .
RUN echo "执行 go mod tidy..." && go mod tidy || (echo "go mod tidy 失败" && exit 1)
RUN echo "开始编译 openim-msgtransfer..." && \
go build -v -o _output/openim-msgtransfer ./cmd/openim-msgtransfer || \
(echo "编译失败,查看详细错误信息" && exit 1)
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-msgtransfer"]

View File

@@ -0,0 +1,43 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory first (must be before COPY . . to avoid conflicts)
# This copies protocol to /protocol, which is ../protocol relative to SERVER_DIR
COPY protocol /protocol
# Copy current directory
COPY . .
RUN echo "执行 go mod tidy..." && go mod tidy || (echo "go mod tidy 失败" && exit 1)
RUN echo "开始编译 openim-push..." && \
go build -v -o _output/openim-push ./cmd/openim-push || \
(echo "编译失败,查看详细错误信息" && exit 1)
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-push"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-rpc-auth ./cmd/openim-rpc/openim-rpc-auth
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-auth"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-rpc-conversation ./cmd/openim-rpc/openim-rpc-conversation
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-conversation"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-rpc-friend ./cmd/openim-rpc/openim-rpc-friend
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-friend"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-rpc-group ./cmd/openim-rpc/openim-rpc-group
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-group"]

View File

@@ -0,0 +1,64 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git, build tools and dependencies for Quirc
RUN apk add --no-cache git ca-certificates build-base make gcc musl-dev pkgconfig
# Build and install Quirc library (static library)
RUN cd /tmp && \
git clone --depth 1 https://github.com/dlbeer/quirc.git && \
cd quirc && \
sed -i 's/\$(shell pkg-config --cflags sdl 2>&1)/\$(shell pkg-config --cflags sdl 2>\/dev\/null || true)/g' Makefile && \
sed -i 's/\$(shell pkg-config --libs sdl)/\$(shell pkg-config --libs sdl 2>\/dev\/null || true)/g' Makefile && \
sed -i 's/\$(shell pkg-config --cflags opencv4 2>&1)/\$(shell pkg-config --cflags opencv4 2>\/dev\/null || true)/g' Makefile && \
sed -i 's/\$(shell pkg-config --libs opencv4)/\$(shell pkg-config --libs opencv4 2>\/dev\/null || true)/g' Makefile && \
make libquirc.a && \
mkdir -p /usr/local/lib /usr/local/include && \
cp libquirc.a /usr/local/lib/ && \
cp lib/quirc.h /usr/local/include/ && \
ls -la /usr/local/lib/libquirc.a /usr/local/include/quirc.h && \
rm -rf /tmp/quirc
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
ENV CGO_ENABLED=1
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
# Build with static linking for Quirc (静态链接,运行时无需库文件)
# 使用 -ldflags 强制静态链接 Quirc 库和数学库
# 注意Alpine Linux 使用 musl libc需要静态链接数学库
RUN go build -tags cgo \
-ldflags '-linkmode external -extldflags "-static -L/usr/local/lib -lquirc -lm"' \
-o _output/openim-rpc-msg ./cmd/openim-rpc/openim-rpc-msg && \
echo "构建完成,验证二进制文件..." && \
file _output/openim-rpc-msg && \
ldd _output/openim-rpc-msg 2>&1 | head -5 || echo "静态链接验证:二进制文件不依赖动态库(这是正常的)"
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-msg"]

View File

@@ -0,0 +1,42 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-rpc-third ./cmd/openim-rpc/openim-rpc-third
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-third"]

View File

@@ -0,0 +1,40 @@
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Install git for repository access
RUN apk add --no-cache git ca-certificates
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Copy protocol directory
COPY protocol /protocol
# Copy current directory
COPY . .
RUN go mod tidy
RUN go build -o _output/openim-rpc-user ./cmd/openim-rpc/openim-rpc-user
# Using Alpine Linux for the final image
FROM alpine:latest
# Install necessary packages, such as bash
RUN apk add --no-cache bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "_output/openim-rpc-user"]

View File

@@ -0,0 +1,108 @@
# # 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.
# # OpenIM base image: https://github.com/openim-sigs/openim-base-image
# # Set go mod installation source and proxy
# FROM golang:1.20 AS builder
#
# WORKDIR /openim/openim-server
#
# ENV GOPROXY=$GOPROXY
# COPY go.mod go.sum ./
# RUN go mod download
# COPY . .
# RUN make clean
# RUN make build BINS=component
# # FROM ghcr.io/openim-sigs/openim-bash-image:latest
# FROM ghcr.io/openim-sigs/openim-bash-image:latest
# WORKDIR /openim/openim-server
# COPY --from=builder /openim/openim-server/_output/bin/tools /openim/openim-server/_output/bin/tools/
# COPY --from=builder /openim/openim-server/config /openim/openim-server/config
# ENV OPENIM_SERVER_CONFIG_NAME=/openim/openim-server/config
# RUN mv ${OPENIM_SERVER_BINDIR}/platforms/$(get_os)/$(get_arch)/component /usr/bin/component
# ENTRYPOINT ["bash", "-c", "component -c $OPENIM_SERVER_CONFIG_NAME"]
# Use Go 1.22 Alpine as the base image for building the application
FROM golang:1.22-alpine AS builder
# Define the base directory for the application as an environment variable
ENV SERVER_DIR=/openim-server
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
# Set the Go proxy to improve dependency resolution speed
#ENV GOPROXY=https://goproxy.io,direct
# Copy all files from the current directory into the container
COPY . .
RUN go mod download
# Install Mage to use for building the application
RUN go install github.com/magefile/mage@v1.15.0
# ENV BINS=openim-rpc-user
# Optionally build your application if needed
# RUN mage build ${BINS} check-free-memory seq || true
RUN mage build check-free-memory seq || true
# Using Alpine Linux with Go environment for the final image
FROM golang:1.22-alpine
# Install necessary packages, such as bash
RUN apk add bash
# Set the environment and work directory
ENV SERVER_DIR=/openim-server
WORKDIR $SERVER_DIR
# Copy the compiled binaries and mage from the builder image to the final image
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
COPY --from=builder /go/bin/mage /usr/local/bin/mage
COPY --from=builder $SERVER_DIR/magefile_windows.go $SERVER_DIR/
COPY --from=builder $SERVER_DIR/magefile_unix.go $SERVER_DIR/
COPY --from=builder $SERVER_DIR/magefile.go $SERVER_DIR/
# COPY --from=builder $SERVER_DIR/start-config.yml $SERVER_DIR/
COPY --from=builder $SERVER_DIR/go.mod $SERVER_DIR/
COPY --from=builder $SERVER_DIR/go.sum $SERVER_DIR/
RUN echo -e "serviceBinaries:\n \n" \
> $SERVER_DIR/start-config.yml && \
echo -e "toolBinaries:\n - check-free-memory\n - seq\n" >> $SERVER_DIR/start-config.yml && \
echo "maxFileDescriptors: 10000" >> $SERVER_DIR/start-config.yml
RUN go get github.com/openimsdk/gomake@v0.0.15-alpha.1
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"]