-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: implement services image build and CI release. (#2920)
* build: implement services image build. * remove unused tools * update test. * update images. * update dockerfile and go mod. * update go mod. * Add comments. * update go pkg. * update loadConfig and discovery logic in kubernetes. * update go pkg and discovery field. * update Load method args.
- Loading branch information
Showing
43 changed files
with
980 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Build and release services Images | ||
|
||
on: | ||
push: | ||
branches: | ||
- release-* | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "Tag version to be used for Docker image" | ||
required: true | ||
default: "v3.8.3" | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Log in to Aliyun Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: registry.cn-hangzhou.aliyuncs.com | ||
username: ${{ secrets.ALIREGISTRY_USERNAME }} | ||
password: ${{ secrets.ALIREGISTRY_TOKEN }} | ||
|
||
- name: Extract metadata for Docker (tags, labels) | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
tags: | | ||
type=ref,event=tag | ||
type=schedule | ||
type=ref,event=branch | ||
type=semver,pattern={{version}} | ||
type=semver,pattern=v{{version}} | ||
# type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern=release-{{raw}} | ||
type=sha | ||
type=raw,value=${{ github.event.inputs.tag }} | ||
- name: Build and push Docker images | ||
run: | | ||
ROOT_DIR="build/images" | ||
for dir in "$ROOT_DIR"/*/; do | ||
# Find Dockerfile or *.dockerfile in a case-insensitive manner | ||
dockerfile=$(find "$dir" -maxdepth 1 -type f \( -iname 'dockerfile' -o -iname '*.dockerfile' \) | head -n 1) | ||
if [ -n "$dockerfile" ] && [ -f "$dockerfile" ]; then | ||
IMAGE_NAME=$(basename "$dir") | ||
echo "Building Docker image for $IMAGE_NAME with tags:" | ||
# Initialize tag arguments | ||
tag_args=() | ||
# Read each tag and append --tag arguments | ||
while IFS= read -r tag; do | ||
tag_args+=(--tag "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag") | ||
tag_args+=(--tag "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$tag") | ||
tag_args+=(--tag "registry.cn-hangzhou.aliyuncs.com/openimsdk/$IMAGE_NAME:$tag") | ||
done <<< "${{ steps.meta.outputs.tags }}" | ||
|
||
# Build and push the Docker image with all tags | ||
docker buildx build --platform linux/amd64,linux/arm64 \ | ||
--file "$dockerfile" \ | ||
"${tag_args[@]}" \ | ||
--push "$dir" | ||
else | ||
echo "No valid Dockerfile found in $dir" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ 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 go get github.com/openimsdk/[email protected].14-alpha.5 | ||
RUN go get github.com/openimsdk/[email protected].15-alpha.1 | ||
|
||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +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. | ||
# # 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 | ||
# FROM BASE_IMAGE | ||
|
||
WORKDIR ${SERVER_WORKDIR} | ||
# WORKDIR ${SERVER_WORKDIR} | ||
|
||
# Set HTTP proxy | ||
ARG BINARY_NAME | ||
# # Set HTTP proxy | ||
# ARG BINARY_NAME | ||
|
||
COPY BINARY_NAME ./bin/BINARY_NAME | ||
# COPY BINARY_NAME ./bin/BINARY_NAME | ||
|
||
ENTRYPOINT ["./bin/BINARY_NAME"] | ||
# ENTRYPOINT ["./bin/BINARY_NAME"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,36 @@ | ||
# 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. | ||
# Use Go 1.22 Alpine as the base image for building the application | ||
FROM golang:1.22-alpine AS builder | ||
|
||
# OpenIM base image: https://github.com/openim-sigs/openim-base-image | ||
# Define the base directory for the application as an environment variable | ||
ENV SERVER_DIR=/openim-server | ||
|
||
# Set go mod installation source and proxy | ||
# Set the working directory inside the container based on the environment variable | ||
WORKDIR $SERVER_DIR | ||
|
||
FROM golang:1.20 AS builder | ||
# Set the Go proxy to improve dependency resolution speed | ||
#ENV GOPROXY=https://goproxy.io,direct | ||
|
||
ARG GO111MODULE=on | ||
|
||
WORKDIR /openim/openim-server | ||
|
||
ENV GO111MODULE=$GO111MODULE | ||
ENV GOPROXY=$GOPROXY | ||
# Copy all files from the current directory into the container | ||
COPY . . | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
RUN go mod tidy | ||
|
||
COPY . . | ||
RUN go build -o _output/openim-api ./cmd/openim-api | ||
|
||
RUN make build BINS=openim-api | ||
# Using Alpine Linux for the final image | ||
FROM alpine:latest | ||
|
||
RUN cp /openim/openim-server/_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-api /usr/bin/openim-api | ||
# Install necessary packages, such as bash | ||
RUN apk add --no-cache bash | ||
|
||
# FROM ghcr.io/openim-sigs/openim-bash-image:latest | ||
FROM ghcr.io/openim-sigs/openim-bash-image:latest | ||
# Set the environment and work directory | ||
ENV SERVER_DIR=/openim-server | ||
WORKDIR $SERVER_DIR | ||
|
||
WORKDIR /openim/openim-server | ||
|
||
COPY --from=builder /usr/bin/openim-api ./bin/openim-api | ||
# 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 | ||
|
||
ENTRYPOINT ["./bin/openim-api"] | ||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "_output/openim-api"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,39 @@ | ||
# 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. | ||
# 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 | ||
|
||
# OpenIM base image: https://github.com/openim-sigs/openim-base-image | ||
# Set the working directory inside the container based on the environment variable | ||
WORKDIR $SERVER_DIR | ||
|
||
# Set go mod installation source and proxy | ||
# Set the Go proxy to improve dependency resolution speed | ||
|
||
FROM golang:1.20 AS builder | ||
#ENV GOPROXY=https://goproxy.io,direct | ||
|
||
ARG GO111MODULE=on | ||
# Copy all files from the current directory into the container | ||
COPY . . | ||
|
||
WORKDIR /openim/openim-server | ||
RUN go mod tidy | ||
|
||
ENV GO111MODULE=$GO111MODULE | ||
ENV GOPROXY=$GOPROXY | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
RUN go build -o _output/openim-crontask ./cmd/openim-crontask | ||
|
||
|
||
RUN make build BINS=openim-crontask | ||
# Using Alpine Linux for the final image | ||
FROM alpine:latest | ||
|
||
RUN cp /openim/openim-server/_output/bin/platforms/$(go env GOOS)/$(go env GOARCH)/openim-crontask /usr/bin/openim-crontask | ||
# Install necessary packages, such as bash | ||
RUN apk add --no-cache bash | ||
|
||
# FROM ghcr.io/openim-sigs/openim-bash-image:latest | ||
FROM ghcr.io/openim-sigs/openim-bash-image:latest | ||
# Set the environment and work directory | ||
ENV SERVER_DIR=/openim-server | ||
WORKDIR $SERVER_DIR | ||
|
||
WORKDIR /openim/openim-server | ||
|
||
COPY --from=builder /usr/bin/openim-crontask ./bin/openim-crontask | ||
# 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 | ||
|
||
ENTRYPOINT ["./bin/openim-crontask"] | ||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "_output/openim-crontask"] |
Oops, something went wrong.