无法在docker-compose中克隆存储库。

huangapple go评论146阅读模式
英文:

Unable to clone repository in docker-compose

问题

我正在尝试使用docker-compose在localstack上配置一个应用程序。当我尝试克隆存储库时,出现了一个错误。

  1. setup-resources_1 | make[1]: [/app/ProjectRecipes.mk:35: clean] Error 2 (ignored)
  2. setup-resources_1 | ServiceName=Tests make -C /app/ -f /app/ProjectRecipes.mk deploy
  3. setup-resources_1 | git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
  4. setup-resources_1 | Cloning into '/Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject'...
  5. localstack_1 | Waiting for all LocalStack services to be ready
  6. setup-resources_1 | fatal: could not read Username for 'https://github.com': No such device or address
  7. setup-resources_1 | make[4]: *** [/app/ProjectRecipes.mk:24: /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject] Error 128

docker-compose.yml

  1. version: '3'
  2. services:
  3. localstack:
  4. image: localstack/localstack
  5. ports:
  6. - "53:53"
  7. - "443:443"
  8. - "4510-4520:4510-4520"
  9. - "4566-4620:4566-4620"
  10. - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
  11. environment:
  12. - LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
  13. - SERVICES=serverless,rds,lambda,sqs,dynamodb,s3,apigateway,stepfunctions,cloudformation,appsync,firehose,es
  14. - DEBUG=1
  15. - DATA_DIR=/tmp/localstack/data
  16. - DOCKER_HOST=unix:///var/run/docker.sock
  17. - HOST_TMP_FOLDER=${TMPDIR}
  18. volumes:
  19. - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
  20. - "/var/run/docker.sock:/var/run/docker.sock"
  21. networks:
  22. - default
  23. setup-resources:
  24. image: golang:1.16.4-alpine3.13
  25. entrypoint: /bin/sh -c
  26. working_dir: /app
  27. command: >
  28. "
  29. ls
  30. apk add --update alpine-sdk
  31. make Tests
  32. "
  33. networks:
  34. - default
  35. volumes:
  36. - type: bind
  37. source: ~/go
  38. target: /go
  39. - type: bind
  40. source: ${HOME}
  41. target: /root
  42. - type: bind
  43. source: .
  44. target: /app
  45. - ~/.ssh:/root/.ssh
  46. - ~/.gitconfig:/root/.gitconfig
  47. depends_on:
  48. - localstack

请注意,这是一个错误消息和docker-compose.yml文件的示例。

英文:

I'm trying to configure an app to run on localstack using docker-compose. I'm getting an error when attempting to clone the resository.

  1. setup-resources_1 | make[1]: [/app/ProjectRecipes.mk:35: clean] Error 2 (ignored)
  2. setup-resources_1 | ServiceName=Tests make -C /app/ -f /app/ProjectRecipes.mk deploy
  3. setup-resources_1 | git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject
  4. setup-resources_1 | Cloning into '/Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject'...
  5. localstack_1 | Waiting for all LocalStack services to be ready
  6. setup-resources_1 | fatal: could not read Username for 'https://github.com': No such device or address
  7. setup-resources_1 | make[4]: *** [/app/ProjectRecipes.mk:24: /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject] Error 128

docker-compose.yml

  1. version: '3'
  2. services:
  3. localstack:
  4. image: localstack/localstack
  5. ports:
  6. - "53:53"
  7. - "443:443"
  8. - "4510-4520:4510-4520"
  9. - "4566-4620:4566-4620"
  10. - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
  11. environment:
  12. - LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
  13. - SERVICES=serverless,rds,lambda,sqs,dynamodb,s3,apigateway,stepfunctions,cloudformation,appsync,firehose,es
  14. - DEBUG=1
  15. - DATA_DIR=/tmp/localstack/data
  16. - DOCKER_HOST=unix:///var/run/docker.sock
  17. - HOST_TMP_FOLDER=${TMPDIR}
  18. volumes:
  19. - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
  20. - "/var/run/docker.sock:/var/run/docker.sock"
  21. networks:
  22. - default
  23. setup-resources:
  24. image: golang:1.16.4-alpine3.13
  25. entrypoint: /bin/sh -c
  26. working_dir: /app
  27. command: >
  28. "
  29. ls
  30. apk add --update alpine-sdk
  31. make Tests
  32. "
  33. networks:
  34. - default
  35. volumes:
  36. - type: bind
  37. source: ~/go
  38. target: /go
  39. - type: bind
  40. source: ${HOME}
  41. target: /root
  42. - type: bind
  43. source: .
  44. target: /app
  45. - ~/.ssh:/root/.ssh
  46. - ~/.gitconfig:/root/.gitconfig
  47. depends_on:
  48. - localstack

答案1

得分: 1

问题:

以下命令在容器中失败,因为它是一个交互式命令,需要用户输入GitHub的用户名密码。尽管在本地机器上不是这样,但在容器内是这样的。我不知道这种差异的原因 😕。

  1. git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject

解决方案:

您可以使用以下命令通过SSH克隆您的存储库:

  1. git clone ssh://git@github.com/MyGithOrg/TestProject.git /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject

步骤:

  1. 更新您的克隆命令以使用上述SSH。

  2. 如果您尚未在Github配置SSH密钥,可以按照此文档进行配置。

    > ​⚠️​ 确保在此步骤中,您能够在本地机器上使用SSH克隆存储库。

  3. 更新docker-compose文件中的command以安装SSH客户端

    1. command: >
    2. "
    3. ls
    4. apk add --update alpine-sdk openssh
    5. make Tests
    6. "
  4. 如果您使用的是Mac,请确保在~/.ssh/config文件中将IgnoreUnknown UseKeychain放在UseKeychain yes之前。

    > ℹ️ 原因是您在Golang Alpine镜像中安装的openssh版本不识别UseKeychain选项,并且会抛出Bad configuration option: usekeychain错误。您可以在此文档中了解更多信息。

    正确的~/.ssh/config文件示例:

    1. Host *
    2. AddKeysToAgent yes
    3. IgnoreUnknown UseKeychain
    4. UseKeychain yes
    5. IdentityFile ~/.ssh/id_rsa
  5. 然后按照以下方式更新您的volumes

    1. volumes:
    2. - type: bind
    3. source: ~/go
    4. target: /go
    5. - type: bind
    6. source: .
    7. target: /app
    8. - ~/.ssh:/root/.ssh

    请注意,您不再需要~/.gitconfig:/root/.gitconfig卷。我还删除了将HOME目录映射到容器的/root的映射,因为我仍然怀疑它可能会引起问题。

我相信现在这应该对您有用。祝您好运 🍻 !!!

英文:

Problem:

The following command fails in your container because it is an interactive command that expects the user to enter username and password for GitHub. Although this is not the case in your local machine, that is the case inside the container. I don't know the reason for the difference 😕.

  1. git clone https://github.com/MyGithOrg/TestProject /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject

Solution:

You can clone your repository through SSH using the following command:

  1. git clone ssh://git@github.com/MyGithOrg/TestProject.git /Users/antarr.byrd/go/src/github.com/MyGithOrg/TestProject

Steps:

  1. Update your clone command to use SSH like above.

  2. If you haven't configured an SSH key in your Github profile, you can follow this documentation to do so.

    > ​⚠️​ Make sure at this step you are able to clone the repo using SSH in your local machine.

  3. Update your command in docker-compose file to install an SSH client

    1. command: >
    2. "
    3. ls
    4. apk add --update alpine-sdk openssh
    5. make Tests
    6. "
  4. If you're using a Mac, then make sure you have IgnoreUnknown UseKeychain above UseKeychain yes in your ~/.ssh/config file.

    > ℹ️ The reason is that openssh version that is being installed in your Golang Alpine image does not recognize UseKeychain option and will throw you Bad configuration option: usekeychain error. You can read more about that in this document.

    Example of a correct ~/.ssh/config file:

    1. Host *
    2. AddKeysToAgent yes
    3. IgnoreUnknown UseKeychain
    4. UseKeychain yes
    5. IdentityFile ~/.ssh/id_rsa
  5. Then update your volumes like below:

    1. volumes:
    2. - type: bind
    3. source: ~/go
    4. target: /go
    5. - type: bind
    6. source: .
    7. target: /app
    8. - ~/.ssh:/root/.ssh

    Note that you no longer need ~/.gitconfig:/root/.gitconfig volume. I also removed your mapping of HOME directory to /root of the container because I still doubt that it might cause issues.

I believe this should work for you now. Cheers 🍻 !!!

huangapple
  • 本文由 发表于 2021年5月20日 22:47:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/67622753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定