Skip to content

Commit 2ad0691

Browse files
committed
update publish image and create private submodule
1 parent 28231e9 commit 2ad0691

File tree

4 files changed

+102
-36
lines changed

4 files changed

+102
-36
lines changed

.github/workflows/create-git-branch-package-on-release.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ name: Create Git Branch Package on Release
33
on:
44
release:
55
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
tag_version:
9+
description: "要打包的标签版本 (例如 v1.0.0)"
10+
required: true
11+
type: string
12+
target_branch:
13+
description: "目标分支 (默认: main)"
14+
required: false
15+
default: "fix/private-submodule"
16+
type: string
617

718
jobs:
819
create-package:
@@ -19,7 +30,18 @@ jobs:
1930
# submodules: "recursive"
2031

2132
- name: Safe submodule initialization
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
2236
run: |
37+
# 设置GitHub Actions Bot身份
38+
git config --global user.name "github-actions[bot]"
39+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
40+
41+
# 配置Git使用token进行身份验证
42+
# git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
43+
git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf "git@github.com:"
44+
2345
echo "Checking for submodules..."
2446
if [ -f .gitmodules ]; then
2547
if [ -s .gitmodules ]; then

.github/workflows/publish-docker-image.yml

Lines changed: 76 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ on:
1717

1818
env:
1919
GO_VERSION: "1.21"
20+
IMAGE_LOCAL_CACHE: "openim-server-cache"
21+
# IMAGE_NAME: "openim-server"
22+
IMAGE_NAME: ${{ github.event.repository.name }}
2023

2124
jobs:
2225
publish-docker-images:
@@ -33,12 +36,45 @@ jobs:
3336
- name: Set up Docker Buildx
3437
uses: docker/setup-buildx-action@v3
3538

36-
- name: Build and push Docker image
37-
uses: docker/build-push-action@v5
39+
- name: Extract metadata for Docker
40+
id: meta
41+
uses: docker/metadata-action@v5.5.1
42+
with:
43+
images: |
44+
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
45+
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
46+
registry.cn-hangzhou.aliyuncs.com/openimsdk/${{ env.IMAGE_NAME }}
47+
48+
# tag_args+=(--tag "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME:$tag")
49+
# tag_args+=(--tag "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$tag")
50+
# tag_args+=(--tag "registry.cn-hangzhou.aliyuncs.com/openimsdk/$IMAGE_NAME:$tag")
51+
tags: |
52+
type=ref,event=tag
53+
type=schedule
54+
type=ref,event=branch
55+
type=ref,event=pr
56+
type=semver,pattern={{version}}
57+
type=semver,pattern=v{{version}}
58+
type=semver,pattern={{major}}.{{minor}}
59+
type=semver,pattern={{major}}
60+
type=sha
61+
62+
- name: Build multi-platform Docker image with cache
63+
uses: docker/build-push-action@v6.18.0
3864
with:
3965
context: ./main-repo
40-
load: true
41-
tags: "openim/openim-server:local"
66+
platforms: linux/amd64,linux/arm64
67+
push: false
68+
tags: ${{ env.IMAGE_LOCAL_CACHE }}:latest
69+
labels: ${{ steps.meta.outputs.labels }}
70+
outputs: type=docker,dest=/tmp/openim-server.tar
71+
cache-from: type=gha
72+
cache-to: type=gha,mode=max
73+
74+
- name: Load image for local testing
75+
run: |
76+
docker load < /tmp/openim-server.tar
77+
docker tag ${{ env.IMAGE_LOCAL_CACHE }}:latest openim/openim-server:local
4278
4379
- name: Checkout compose repository
4480
uses: actions/checkout@v4
@@ -51,7 +87,7 @@ jobs:
5187
run: |
5288
IP=$(hostname -I | awk '{print $1}')
5389
echo "The IP Address is: $IP"
54-
echo "::set-output name=ip::$IP"
90+
echo "ip=$IP" >> $GITHUB_OUTPUT
5591
5692
- name: Update .env to use the local image
5793
run: |
@@ -93,29 +129,6 @@ jobs:
93129
exit 0
94130
fi
95131
96-
97-
- name: Extract metadata for Docker # (tags, labels)
98-
if: success()
99-
id: meta
100-
uses: docker/metadata-action@v5.5.1
101-
with:
102-
images: |
103-
openim/openim-server
104-
ghcr.io/openimsdk/openim-server
105-
registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server
106-
107-
# generate Docker tags based on the following events/attributes
108-
tags: |
109-
type=ref,event=tag
110-
type=schedule
111-
type=ref,event=branch
112-
type=ref,event=pr
113-
type=semver,pattern={{version}}
114-
type=semver,pattern=v{{version}}
115-
type=semver,pattern={{major}}.{{minor}}
116-
type=semver,pattern={{major}}
117-
type=sha
118-
119132
- name: Log in to Docker Hub
120133
uses: docker/login-action@v2
121134
with:
@@ -136,11 +149,38 @@ jobs:
136149
username: ${{ secrets.ALIREGISTRY_USERNAME }}
137150
password: ${{ secrets.ALIREGISTRY_TOKEN }}
138151

139-
- name: Build and push Docker images
140-
uses: docker/build-push-action@v5
141-
with:
142-
context: ./main-repo
143-
push: true
144-
platforms: linux/amd64,linux/arm64
145-
tags: ${{ steps.meta.outputs.tags }}
146-
labels: ${{ steps.meta.outputs.labels }}
152+
# 直接推送已经构建的镜像
153+
- name: Push pre-built images to registries
154+
if: success()
155+
run: |
156+
# 重新加载之前保存的镜像
157+
docker load < /tmp/openim-server.tar
158+
159+
# 获取并显示基础镜像
160+
echo "已加载的基础镜像:"
161+
docker images ${{ env.IMAGE_LOCAL_CACHE }}:latest
162+
163+
# 为每个目标标签创建新标签并推送
164+
echo "开始为多个仓库创建标签并推送..."
165+
IFS=',' read -ra TAGS <<< "${{ steps.meta.outputs.tags }}"
166+
for tag in "${TAGS[@]}"; do
167+
echo "创建并推送标签: $tag"
168+
docker tag ${{ env.IMAGE_LOCAL_CACHE }}:latest $tag
169+
docker push $tag
170+
done
171+
172+
# # Push the previously built images
173+
# - name: Push pre-built images to registries
174+
# if: success()
175+
# uses: docker/build-push-action@v6.18.0
176+
# with:
177+
# context: ./main-repo
178+
# push: true
179+
# platforms: linux/amd64,linux/arm64
180+
# tags: ${{ steps.meta.outputs.tags }}
181+
# labels:
182+
# ${{ steps.meta.outputs.labels }}
183+
# # Use the previously built image as the cache source
184+
# cache-from: |
185+
# type=gha
186+
# type=registry,ref=${{ env.IMAGE_LOCAL_CACHE }}:latest

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "protocol-enterprise"]
2+
path = protocol-enterprise
3+
url = git@github.com:openimsdk/protocol-enterprise.git

protocol-enterprise

Submodule protocol-enterprise added at 42a2485

0 commit comments

Comments
 (0)