[improvement][build] Optimize pushing images through GitHub Actions (#1875)

This commit is contained in:
lexluo09
2024-11-02 21:33:15 +08:00
committed by GitHub
parent 1867447b6e
commit 6a4458a572
3 changed files with 23 additions and 13 deletions

View File

@@ -28,5 +28,7 @@ jobs:
- name: Build and publish Docker image
run: |
VERSION=${{ github.event.inputs.version }}
chmod +x docker/docker-build.sh
chmod +x docker/docker-publish.sh
sh docker/docker-build.sh $VERSION
sh docker/docker-publish.sh
sh docker/docker-publish.sh $VERSION

View File

@@ -4,7 +4,13 @@ sbinDir=$(cd "$(dirname "$0")"; pwd)
chmod +x $sbinDir/supersonic-common.sh
source $sbinDir/supersonic-common.sh
cd $projectDir
MVN_VERSION=$(mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]')
MVN_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '^\[' | sed -n '/^[0-9]/p')
if [ -z "$MVN_VERSION" ]; then
echo "Failed to retrieve Maven project version."
exit 1
fi
echo "Maven project version: $MVN_VERSION"
cd $baseDir
service=$1

View File

@@ -1,20 +1,22 @@
#!/bin/bash
# 确保脚本在出错时退出
#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status
set -e
# 镜像名称
VERSION=$1
# Image name
IMAGE_NAME="supersonicbi/supersonic"
# 默认标签为 latest
TAGS=("latest")
# Default tag is latest
TAGS="latest"
# 如果有 Git 标签,则使用 Git 标签作为额外的镜像标签
if [ -n "$GITHUB_REF" ]; then
GIT_TAG=$(echo $GITHUB_REF | sed 's/refs\/tags\///')
TAGS+=("$GIT_TAG")
# If VERSION is provided, add it to TAGS and tag the image as latest
if [ -n "$VERSION" ]; then
TAGS="$TAGS $VERSION"
docker tag $IMAGE_NAME:$VERSION $IMAGE_NAME:latest
fi
# 推送 Docker 镜像
for TAG in "${TAGS[@]}"; do
# Push Docker images
for TAG in $TAGS; do
echo "Pushing Docker image $IMAGE_NAME:$TAG"
docker push $IMAGE_NAME:$TAG
done