From 1103da3414952eda0ef0d1fb62ee34e33b24f989 Mon Sep 17 00:00:00 2001 From: "kim.dev.6789" Date: Thu, 15 Jan 2026 17:08:56 +0800 Subject: [PATCH] chore: pass git creds into docker build --- .gitea/workflows/itom-platform-auto-build.yml | 12 +++++++++++- Dockerfile | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/itom-platform-auto-build.yml b/.gitea/workflows/itom-platform-auto-build.yml index 15999ff..5b42ea7 100644 --- a/.gitea/workflows/itom-platform-auto-build.yml +++ b/.gitea/workflows/itom-platform-auto-build.yml @@ -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" diff --git a/Dockerfile b/Dockerfile index d3c3b0c..3af8c74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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