1

Thank you for visiting here.

First of all, I apologize for my bad English, maybe a little wrong, hope you can help me.

Then I had a little problem when deploying a new CI/CD system on k8s platform (v1.23.5+1) with Gitlab runner (14.9.0) and dind (docker:dind)

When deploying CI to Golang apps with private repositories at https://gitlab.domain.com, (I did the go env -w GOPRIVATE configuration), I had a problem with the go mod tidy command. Specifically getting the unexpected EOF error. I've tried go mod tidy -v but it doesn't seem to give any more info.

I did a lot of work to figure out the problem. Specifically, I have done wget and git clone commands with my private repository and they are still able to download successfully. I tried adding a private repository at https://gitlab.com in go.mod, they can still be retrieved without any errors. And actually, without using my new runner, I can still git clone and go mod tidy in another vps. All of this leaves me wondering where am I actually getting the error? Is it my gitlab or my k8s gitlab runner

This is runner output

go: downloading gitlab.domain.com/nood/fountain v0.0.12
unexpected EOF
Cleaning up project directory and file based variables
ERROR: Job failed: command terminated with exit code 1

This is my .gitlab-ci.yml

image: docker:latest

stages:
  - build
  - deploy

variables:
  GTV_ECR_REPOSITORY_URL: repo.domain.com
  PROJECT: nood
  APP_NAME: backend-super-system
  APP_NAME_ECR: backend-super-system
  IMAGE_TAG: $GTV_ECR_REPOSITORY_URL/$PROJECT/$APP_NAME_ECR
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""

services:
  - name: docker:dind
    entrypoint: ["env", "-u", "DOCKER_HOST"]
    command: ["dockerd-entrypoint.sh", "--tls=false"]

build:
  stage: build
  allow_failure: false
  script:
    - echo "Building image."
    - docker pull $IMAGE_TAG || echo "Building runtime from scratch"
    - >
      docker build
      --cache-from $IMAGE_TAG
      -t $IMAGE_TAG --network host .
    - docker push $IMAGE_TAG

Dockerfile

FROM golang:alpine3.15

LABEL maintainer="NoodExe <nood.pr@gmail.com>"

WORKDIR /app

ENV BIN_DIR=/app/bin

RUN apk add --no-cache gcc build-base git

ADD . .

RUN chmod +x scripts/env.sh scripts/build.sh \
    && ./scripts/env.sh \
    && ./scripts/build.sh

# stage 2
FROM alpine:latest

WORKDIR /app

ENV BIN_DIR=/app/bin
ENV SCRIPTS_DIR=/app/scripts
ENV DATA_DIR=/app/data

# Build Args
ARG LOG_DIR=/var/log/nood

# Create log directory
RUN mkdir -p ${BIN_DIR} \
    mkdir -p ${SCRIPTS_DIR} \
    mkdir -p ${DATA_DIR} \
    mkdir -p ${LOG_DIR} \
    && apk update \
    && addgroup -S nood \
    && adduser -S nood -G nood \
    && chown nood:nood /app \
    && chown nood:nood ${LOG_DIR}

USER nood

COPY --chown=nood:nood --from=0 ${BIN_DIR} /app
COPY --chown=nood:nood --from=0 ${DATA_DIR} ${DATA_DIR}
COPY --chown=nood:nood --from=0 ${SCRIPTS_DIR} ${SCRIPTS_DIR}

RUN chmod +x  ${SCRIPTS_DIR}/startup.sh

ENTRYPOINT ["/app/scripts/startup.sh"]

scripts/env.sh

#!/bin/sh

go env -w GOPRIVATE=gitlab.domain.com/*
git config --global --add url."https://nood_deploy:rvbsosecret_Hizt97zQSn@gitlab.domain.com".insteadOf "https://gitlab.domain.com"

scripts/build.sh

#!/bin/sh

grep -v "replace\s.*=>.*" go.mod > tmpfile && mv tmpfile go.mod

go mod tidy

set -e

BIN_DIR=${BIN_DIR:-/app/bin}
mkdir -p "$BIN_DIR"

files=`ls *.go`

echo "****************************************"
echo "******** building applications **********"
echo "****************************************"

for file in $files; do
    echo building $file
    go build -o "$BIN_DIR"/${file%.go} $file
done

Thank you for still being here :3

user11802298
  • 51
  • 1
  • 5
  • 1
    Hi! Welcome to stackoverflow! I'm afraid your question is really pretty vague. We can help only if you provide information about your context, what you're trying to accomplish and what you've tried. Please see https://stackoverflow.com/help/how-to-ask. – Beel Apr 16 '22 at 19:58
  • I said "CI/CD system on k8s platform (v1.23.5+1) with Gitlab runner (14.9.0) and dind (docker:dind)" :/ – user11802298 Apr 17 '22 at 07:32

1 Answers1

0

This is a known issue with installing go modules from gitlab in nested locations. The issue describes several workarounds/solutions. One solution is described as follows:

  • create a gitlab Personal Access Token with at least read_api and read_repository scopes.
  • create a .netrc file:
machine gitlab.com  
 login yourname@gitlab.com  
 password yourpersonalaccesstoken  
  • use go get --insecure to get your module
  • do not use the .gitconfig insteadOf workaround

For self-hosted instances of GitLab, there is also the additional option of using the go proxy, which is what I do to resolve this problem.

For additional context, see this answer to What's the proper way to "go get" a private repository?

sytech
  • 29,298
  • 3
  • 45
  • 86