Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: improve module image build and kubernetes adapt. #616

Merged
merged 9 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/build-and-release-services-images.yml
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
48 changes: 0 additions & 48 deletions build/images/api-admin/Dockerfile

This file was deleted.

48 changes: 0 additions & 48 deletions build/images/api-chat/Dockerfile

This file was deleted.

36 changes: 36 additions & 0 deletions build/images/openim-admin-api/Dockerfile
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"]
36 changes: 36 additions & 0 deletions build/images/openim-admin-rpc/Dockerfile
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"]
36 changes: 36 additions & 0 deletions build/images/openim-chat-api/Dockerfile
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"]
36 changes: 36 additions & 0 deletions build/images/openim-chat-rpc/Dockerfile
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"]
48 changes: 0 additions & 48 deletions build/images/rpc-admin/Dockerfile

This file was deleted.

Loading
Loading