1717
1818env :
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
2124jobs :
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
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
0 commit comments