'Go build error `signal: killed` when get dependency

I was get some unexpected error when build my golang application gitlab.company.com/nood/monitor-backend on gitlab runner.

The application gitlab.company.com/nood/monitor-backend have a dependency on gitlab.company.com/nood/fountain, this is a private repo.

go: downloading gitlab.company.com/nood/fountain v0.0.12
go: downloading github.com/google/uuid v1.3.0
go: downloading golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
go: downloading github.com/tealeg/xlsx/v3 v3.2.4
go: downloading gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
go: downloading github.com/go-redis/redis/v8 v8.11.5
go: downloading github.com/jmoiron/sqlx v1.3.5
go: downloading github.com/lib/pq v1.10.5
go: downloading github.com/gofiber/fiber/v2 v2.32.0
go: downloading github.com/cespare/xxhash/v2 v2.1.2
go: downloading github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f
go: downloading github.com/onsi/ginkgo v1.16.5
go: downloading github.com/onsi/gomega v1.18.1
go: downloading github.com/go-sql-driver/mysql v1.6.0
go: downloading github.com/mattn/go-sqlite3 v1.14.6
go: downloading github.com/valyala/fasthttp v1.35.0
go: downloading github.com/frankban/quicktest v1.14.3
go: downloading github.com/peterbourgon/diskv v2.0.1+incompatible
go: downloading github.com/rogpeppe/fastuuid v1.2.0
go: downloading github.com/shabbyrobe/xmlwriter v0.0.0-20220218224045-defe0ad214f6
go: downloading github.com/pkg/profile v1.5.0
go: downloading gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b
go: downloading golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
go: downloading github.com/andybalholm/brotli v1.0.4
go: downloading github.com/klauspost/compress v1.15.1
go: downloading github.com/valyala/bytebufferpool v1.0.0
go: downloading github.com/valyala/tcplisten v1.0.0
go: downloading github.com/google/go-cmp v0.5.7
go: downloading github.com/kr/pretty v0.3.0
go: downloading github.com/google/btree v1.0.1
go: downloading golang.org/x/text v0.3.7
go: downloading github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e
go: downloading golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/nxadm/tail v1.4.8
go: downloading golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f
go: downloading github.com/kr/text v0.2.0
go: downloading github.com/rogpeppe/go-internal v1.8.1
go: downloading gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: downloading github.com/fsnotify/fsnotify v1.5.1
gitlab.company.com/nood/monitor-backend imports
    gitlab.company.com/nood/fountain: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core imports
    gitlab.company.com/nood/fountain/baselib/auth_token: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core imports
    gitlab.company.com/nood/fountain/baselib/vpn_managers: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core imports
    gitlab.company.com/nood/fountain/proto/v_proto: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core/auth imports
    gitlab.company.com/nood/fountain/baselib/base: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core/auth imports
    gitlab.company.com/nood/fountain/baselib/constants: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core/auth imports
    gitlab.company.com/nood/fountain/baselib/v_log: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core/auth imports
    gitlab.company.com/nood/fountain/biz/core: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core/profiles imports
    gitlab.company.com/nood/fountain/baselib/cache: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/core/profiles imports
    gitlab.company.com/nood/fountain/baselib/cache/memory_cache: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/dal/dao imports
    gitlab.company.com/nood/fountain/baselib/redis_client: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/biz/dal/dao imports
    gitlab.company.com/nood/fountain/baselib/sql_client: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/server imports
    gitlab.company.com/nood/fountain/baselib/env: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/server imports
    gitlab.company.com/nood/fountain/baselib/ip2geo: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/server imports
    gitlab.company.com/nood/fountain/baselib/v_net/v_api: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/server imports
    gitlab.company.com/nood/fountain/biz/core/auth: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/server imports
    gitlab.company.com/nood/fountain/biz/core/health_check: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
gitlab.company.com/nood/monitor-backend/server imports
    gitlab.company.com/nood/fountain/biz/dal/dao: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
****************************************
******** building applications **********
****************************************
building main.go
go: downloading gitlab.company.com/nood/fountain v0.0.12
main.go:30:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/auth/session.go:30:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/auth/func.go:34:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/profiles/controller.go:30:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/profiles/controller.go:31:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/auth/session.go:31:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/route.go:30:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:31:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:32:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:33:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:34:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:35:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/core.go:31:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:36:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:37:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:38:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
server/server.go:39:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
biz/core/auth/func.go:36:2: git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 930e663b0f80f99e638c621bb72d599ce82f7531 in /go/pkg/mod/cache/vcs/3a00fbd5d1956a156ac1ad852b26361d0781eabcd35cb17623a25fdaf20a6fa0: signal: killed
The command '/bin/sh -c chmod +x scripts/env.sh scripts/build.sh && ./scripts/env.sh && ./scripts/build.sh' returned a non-zero code: 1
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1

I build my application on Gitlab runner(k8s:v1.23.5+1 + gitlab-runner:14.9.0) with docker with image docker:19.03.0 using docker:19.03.0-dind service

gitlab-ci.yml

image: docker:19.03.0

stages:
  - build
  - deploy

variables:
  CI_COMPANY_PRI_KEY: $CI_COMPANY_PRI_KEY
  COMPANY_ECR_REPOSITORY_URL: repo.company.com
  PROJECT: tech
  APP_NAME: monitor-backend
  APP_NAME_ECR: monitor-backend
  IMAGE_TAG: $COMPANY_ECR_REPOSITORY_URL/$PROJECT/$APP_NAME_ECR
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""

services:
  - docker:19.03.0-dind

before_script:
  - docker info

build:
  stage: build
  allow_failure: false
  script:
    - apk add --no-cache curl jq python2 py-pip
    - echo "Building image."
    - docker pull $IMAGE_TAG || echo "Building runtime from scratch"
    - >
      docker build
      --cache-from $IMAGE_TAG
      -t $IMAGE_TAG .
    - docker push $IMAGE_TAG

Dockerfile

FROM golang:1.18.1-alpine3.15

WORKDIR /app

ENV BIN_DIR=/app/bin

RUN apk update && 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/company

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

USER company

COPY --chown=company:company --from=0 ${BIN_DIR} /app
COPY --chown=company:company --from=0 ${DATA_DIR} ${DATA_DIR}
COPY --chown=company:company --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.company.com/*
git config --global --add url."https://tech_deploy:[email protected]".insteadOf "https://gitlab.company.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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source