-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: improve module image build and kubernetes adapt. (#616)
* build: improve image generate. * build: improve loadConfig and discovery by kubernetes. * move version path. * move build iamges foler name. * build: create release images. * update go pkg and import. * update mongo field. * fix: improve DialOption in Discovery. * revert log input.
- Loading branch information
Showing
33 changed files
with
479 additions
and
367 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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 CHAT_DIR=/openim-chat | ||
|
||
# Set the working directory inside the container based on the environment variable | ||
WORKDIR $CHAT_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 tidy | ||
|
||
RUN go build -o _output/admin-api ./cmd/api/admin-api | ||
|
||
# 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 CHAT_DIR=/openim-chat | ||
WORKDIR $CHAT_DIR | ||
|
||
|
||
# Copy the compiled binaries and mage from the builder image to the final image | ||
COPY --from=builder $CHAT_DIR/_output $CHAT_DIR/_output | ||
COPY --from=builder $CHAT_DIR/config $CHAT_DIR/config | ||
|
||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "_output/admin-api"] |
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,36 @@ | ||
# 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 CHAT_DIR=/openim-chat | ||
|
||
# Set the working directory inside the container based on the environment variable | ||
WORKDIR $CHAT_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 tidy | ||
|
||
RUN go build -o _output/admin-rpc ./cmd/rpc/admin-rpc | ||
|
||
# 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 CHAT_DIR=/openim-chat | ||
WORKDIR $CHAT_DIR | ||
|
||
|
||
# Copy the compiled binaries and mage from the builder image to the final image | ||
COPY --from=builder $CHAT_DIR/_output $CHAT_DIR/_output | ||
COPY --from=builder $CHAT_DIR/config $CHAT_DIR/config | ||
|
||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "_output/admin-rpc"] |
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,36 @@ | ||
# 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 CHAT_DIR=/openim-chat | ||
|
||
# Set the working directory inside the container based on the environment variable | ||
WORKDIR $CHAT_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 tidy | ||
|
||
RUN go build -o _output/chat-api ./cmd/api/chat-api | ||
|
||
# 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 CHAT_DIR=/openim-chat | ||
WORKDIR $CHAT_DIR | ||
|
||
|
||
# Copy the compiled binaries and mage from the builder image to the final image | ||
COPY --from=builder $CHAT_DIR/_output $CHAT_DIR/_output | ||
COPY --from=builder $CHAT_DIR/config $CHAT_DIR/config | ||
|
||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "_output/chat-api"] |
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,36 @@ | ||
# 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 CHAT_DIR=/openim-chat | ||
|
||
# Set the working directory inside the container based on the environment variable | ||
WORKDIR $CHAT_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 tidy | ||
|
||
RUN go build -o _output/chat-rpc ./cmd/rpc/chat-rpc | ||
|
||
# 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 CHAT_DIR=/openim-chat | ||
WORKDIR $CHAT_DIR | ||
|
||
|
||
# Copy the compiled binaries and mage from the builder image to the final image | ||
COPY --from=builder $CHAT_DIR/_output $CHAT_DIR/_output | ||
COPY --from=builder $CHAT_DIR/config $CHAT_DIR/config | ||
|
||
# Set the command to run when the container starts | ||
ENTRYPOINT ["sh", "-c", "_output/chat-rpc"] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.