chore: pass git creds into docker build
Some checks failed
itom-platform auto build image / build (push) Failing after 3m55s

This commit is contained in:
kim.dev.6789
2026-01-15 17:08:56 +08:00
parent 0ee1b61219
commit 1103da3414
2 changed files with 27 additions and 1 deletions

View File

@@ -161,12 +161,22 @@ jobs:
- name: Build and push images
shell: sh
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
set -eu
cd "${GITHUB_WORKSPACE:-/workspace}"
IMAGE_BRANCH_TAG="$IMAGE:${BRANCH}"
IMAGE_SHA_TAG="$IMAGE:sha-${SHA_SHORT}"
docker build -t "$IMAGE_BRANCH_TAG" -t "$IMAGE_SHA_TAG" -f "$DOCKERFILE_PATH" "$BUILD_CONTEXT"
docker build \
--build-arg GIT_USER="${GIT_USER:-}" \
--build-arg GIT_TOKEN="${GIT_TOKEN:-}" \
--build-arg REGISTRY_USER="${REGISTRY_USER:-}" \
--build-arg REGISTRY_PASSWORD="${REGISTRY_PASSWORD:-}" \
-t "$IMAGE_BRANCH_TAG" -t "$IMAGE_SHA_TAG" -f "$DOCKERFILE_PATH" "$BUILD_CONTEXT"
log_image() {
local tag="$1"

View File

@@ -5,6 +5,15 @@ FROM golang:1.22-alpine AS builder
ENV SERVER_DIR=/openim-server
ENV GOWORK=off
# Credentials for private module access (optional)
ARG GIT_USER
ARG GIT_TOKEN
ARG REGISTRY_USER
ARG REGISTRY_PASSWORD
ENV GOPRIVATE=git.imall.cloud
ENV GONOSUMDB=git.imall.cloud
# Set the working directory inside the container based on the environment variable
WORKDIR $SERVER_DIR
@@ -17,6 +26,13 @@ RUN apk add --no-cache git
# Copy all files from the current directory into the container
COPY . .
RUN set -eu; \
user="${GIT_USER:-$REGISTRY_USER}"; \
token="${GIT_TOKEN:-$REGISTRY_PASSWORD}"; \
if [ -n "$user" ] && [ -n "$token" ]; then \
git config --global url."https://${user}:${token}@git.imall.cloud/".insteadOf "https://git.imall.cloud/"; \
fi
RUN go mod download
# Install Mage to use for building the application