From 91ac85e341f34d8ab13651c4116f5e6d2e508f0d Mon Sep 17 00:00:00 2001 From: ledger <228664584@qq.com> Date: Sun, 20 Oct 2024 17:10:13 +0800 Subject: [PATCH] add ci --- .github/workflows/build-image.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index eab035a..99c47eb 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -29,25 +29,31 @@ jobs: echo "VERSION=$VERSION" >> $GITHUB_ENV echo "The version from .VERSION file is: $VERSION" - # Step 3: Build the Docker image using the version from the .VERSION file + # Step 3: Convert repository name to lowercase and save to GITHUB_ENV + - name: Convert repository name to lowercase + run: | + REPO_NAME=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]') + echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV + echo "Repository name in lowercase: ${REPO_NAME}" + + # Step 4: Build the Docker image using the version from the .VERSION file - name: Build Docker Image run: | - docker build -t ${{ github.event.repository.name }}:${VERSION} . + docker build -t ${REPO_NAME}:${VERSION} . - # Step 4: Check if the Docker image already exists + # Step 5: Check if the Docker image already exists - name: Check if Docker Image Version Exists run: | - IMAGE=registry.cn-hangzhou.aliyuncs.com/ledger_github/${{ github.event.repository.name }}:${VERSION} + IMAGE=registry.cn-hangzhou.aliyuncs.com/ledger_github/${REPO_NAME}:${VERSION} if docker manifest inspect $IMAGE > /dev/null 2>&1; then echo "Error: Docker image $IMAGE already exists. Exiting." exit 1 fi echo "Docker image $IMAGE does not exist. Proceeding to push." - # Step 5: Tag the image with the registry address and version + # Step 6: Tag the image with the registry address and version - name: Tag Docker Image And Push if: success() run: | - REPO_NAME=${{ github.event.repository.name }} docker tag ${REPO_NAME}:${VERSION} registry.cn-hangzhou.aliyuncs.com/ledger_github/${REPO_NAME}:${VERSION} docker push registry.cn-hangzhou.aliyuncs.com/ledger_github/${REPO_NAME}:${VERSION}