Skip to content

Commit 6a4458a

Browse files
authored
[improvement][build] Optimize pushing images through GitHub Actions (#1875)
1 parent 1867447 commit 6a4458a

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

.github/workflows/docker-publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ jobs:
2828
- name: Build and publish Docker image
2929
run: |
3030
VERSION=${{ github.event.inputs.version }}
31+
chmod +x docker/docker-build.sh
32+
chmod +x docker/docker-publish.sh
3133
sh docker/docker-build.sh $VERSION
32-
sh docker/docker-publish.sh
34+
sh docker/docker-publish.sh $VERSION

assembly/bin/supersonic-build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ sbinDir=$(cd "$(dirname "$0")"; pwd)
44
chmod +x $sbinDir/supersonic-common.sh
55
source $sbinDir/supersonic-common.sh
66
cd $projectDir
7-
MVN_VERSION=$(mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]')
7+
8+
MVN_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '^\[' | sed -n '/^[0-9]/p')
9+
if [ -z "$MVN_VERSION" ]; then
10+
echo "Failed to retrieve Maven project version."
11+
exit 1
12+
fi
13+
echo "Maven project version: $MVN_VERSION"
814

915
cd $baseDir
1016
service=$1

docker/docker-publish.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
#!/bin/bash
2-
# 确保脚本在出错时退出
1+
#!/usr/bin/env bash
2+
# Exit immediately if a command exits with a non-zero status
33
set -e
4-
# 镜像名称
4+
VERSION=$1
5+
6+
# Image name
57
IMAGE_NAME="supersonicbi/supersonic"
68

7-
# 默认标签为 latest
8-
TAGS=("latest")
9+
# Default tag is latest
10+
TAGS="latest"
911

10-
# 如果有 Git 标签,则使用 Git 标签作为额外的镜像标签
11-
if [ -n "$GITHUB_REF" ]; then
12-
GIT_TAG=$(echo $GITHUB_REF | sed 's/refs\/tags\///')
13-
TAGS+=("$GIT_TAG")
12+
# If VERSION is provided, add it to TAGS and tag the image as latest
13+
if [ -n "$VERSION" ]; then
14+
TAGS="$TAGS $VERSION"
15+
docker tag $IMAGE_NAME:$VERSION $IMAGE_NAME:latest
1416
fi
1517

16-
# 推送 Docker 镜像
17-
for TAG in "${TAGS[@]}"; do
18+
# Push Docker images
19+
for TAG in $TAGS; do
1820
echo "Pushing Docker image $IMAGE_NAME:$TAG"
1921
docker push $IMAGE_NAME:$TAG
2022
done

0 commit comments

Comments
 (0)