1

I just ran into a super weird issue and I really don't get what's currently happening..

I had a project while some e2e tests, everything was working fine. For some reason, I had to use some privates repositories (from gitlab) of mine as I developed some layers related to databases and others purposes.

The thing is, when I tried to run go test from docker compose command, it's now failing with the following message:

e2e_tests_1 | FAIL       gitlab.com/foo-bar-group/awesome-api/tests/e2e [setup failed]
e2e_tests_1 | # gitlab.com/foo-bar-group/awesome-api/tests/e2e
e2e_tests_1 | internal/domain/models/file_infos.go:7:2: gitlab.com/emixam23-generic-utils/google-cloud-storage@vxxx: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/xxx: exit status 128:
e2e_tests_1 |    fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
e2e_tests_1 | FAIL

I have a simple docker compose that runs 3 containers (mongodb, elasticsearch, custom golang docker image). My Dockerfile has a small script which help me (and which is working) to know when everything is ready for a full test

Dockerfile

FROM golang:1.17.6

WORKDIR /app

ENV GO111MODULE on

# Download wait for it tool.
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /wait-for-it
RUN chmod +x /wait-for-it

docker-compose.tests-e2e.yml

version: "3.7"

services:

  mongodb_e2e_tests:
    image: mongo:5.0.4

  elasticsearch_e2e_tests:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
    environment:
      - "discovery.type=single-node"

  e2e_tests:
    build:
      context: .
      dockerfile: Dockerfile.e2e_tests
    environment:
      # ...
    depends_on:
      - mongodb_e2e_tests
      - elasticsearch_e2e_tests
    volumes:
      - .:/app
    command: sh -c "/wait-for-it elasticsearch_e2e_tests:9200 -- /wait-for-it mongodb_e2e_tests:27017 -- go test ./tests/e2e/... -p 1 -v -count=1"

Everything seems to work as before, until the go test ./tests/e2e/... -p 1 -v -count=1 which from now on, at go get time, cannot fetch my private repository...

Thanks for any help.. I really did search to inject SSH, so setup git and everything but.. It seems to have something to do with docker-compose... not my Dockerfile image or my golang command

Thanks again..

Best,

Max

Emixam23
  • 3,854
  • 8
  • 50
  • 107
  • ssh key based auth is what you want, then it will 'just work' for Go. If you run go build in docker compose, https://medium.com/@tonistiigi/build-secrets-and-ssh-forwarding-in-docker-18-09-ae8161d066 can help you safely and securely expose ssh credentials for git authnz. – erik258 Feb 03 '22 at 03:46

1 Answers1

0

Have you checked this answer?
https://stackoverflow.com/a/38237165/4486909

go get disables the "terminal prompt" by default.
This can be changed by setting an environment variable of git:
env GIT_TERMINAL_PROMPT=1

Try to add the following vars to your docker-compose env section:
GIT_TERMINAL_PROMPT=1

Additionally, you could get a go with this one:
TERM=xterm

Olesya Bolobova
  • 1,573
  • 1
  • 10
  • 21