chore: pass git creds into docker build
Some checks failed
itom-platform auto build image / build (push) Failing after 3m55s
Some checks failed
itom-platform auto build image / build (push) Failing after 3m55s
This commit is contained in:
@@ -161,12 +161,22 @@ jobs:
|
|||||||
|
|
||||||
- name: Build and push images
|
- name: Build and push images
|
||||||
shell: sh
|
shell: sh
|
||||||
|
env:
|
||||||
|
GIT_USER: ${{ secrets.GIT_USER }}
|
||||||
|
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
||||||
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
cd "${GITHUB_WORKSPACE:-/workspace}"
|
cd "${GITHUB_WORKSPACE:-/workspace}"
|
||||||
IMAGE_BRANCH_TAG="$IMAGE:${BRANCH}"
|
IMAGE_BRANCH_TAG="$IMAGE:${BRANCH}"
|
||||||
IMAGE_SHA_TAG="$IMAGE:sha-${SHA_SHORT}"
|
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() {
|
log_image() {
|
||||||
local tag="$1"
|
local tag="$1"
|
||||||
|
|||||||
16
Dockerfile
16
Dockerfile
@@ -5,6 +5,15 @@ FROM golang:1.22-alpine AS builder
|
|||||||
ENV SERVER_DIR=/openim-server
|
ENV SERVER_DIR=/openim-server
|
||||||
ENV GOWORK=off
|
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
|
# Set the working directory inside the container based on the environment variable
|
||||||
WORKDIR $SERVER_DIR
|
WORKDIR $SERVER_DIR
|
||||||
|
|
||||||
@@ -17,6 +26,13 @@ RUN apk add --no-cache git
|
|||||||
# Copy all files from the current directory into the container
|
# Copy all files from the current directory into the container
|
||||||
COPY . .
|
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
|
RUN go mod download
|
||||||
|
|
||||||
# Install Mage to use for building the application
|
# Install Mage to use for building the application
|
||||||
|
|||||||
Reference in New Issue
Block a user