AWS Copilot的manifest.image.context可以设置为项目存储库的根目录吗?

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

How can AWS Copilot's manifest.image.context be set to the project repository's root directory?

问题

如何将AWS Copilot的image.context清单文件参数设置为项目的根目录?我正在将Docker Compose文件翻译成Copilot清单文件,但无论是使用相对路径还是绝对路径,我都无法让Copilot尊重image.context参数。

项目存储库结构示例:

  1. - project_root
  2. - src
  3. - api.py
  4. - copilot
  5. - api
  6. - manifest.yaml
  7. - requirements.txt
  8. - requirements
  9. - base.in
  10. - base.txt
  11. - development.in
  12. - development.txt
  13. - production.in
  14. - production.txt
  15. - dockerfiles
  16. - api
  17. - Dockerfile
  18. - start_agent.sh
  19. - start_api.sh
  20. - docker-compose.yaml

服务的Dockerfile:

  1. FROM python:3.11
  2. RUN mkdir /app
  3. WORKDIR /app
  4. COPY ./requirements/ requirements
  5. COPY ./requirements.txt .
  6. RUN pip install -r requirements.txt
  7. COPY . /app
  8. COPY ./dockerfiles/services/api/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
  9. COPY --chmod=### ./dockerfiles/services/api/start_agent.sh /app/start_agent.sh
  10. COPY --chmod=### ./dockerfiles/services/api/start_api.sh /app/start_api.sh
  11. ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
  12. EXPOSE 8080

服务的Copilot manifest.yaml文件:

  1. name: api
  2. type: Backend Service
  3. image:
  4. build: ./dockerfiles/services/api/Dockerfile
  5. context: .
  6. port: 8080
  7. ...
  8. exec: true
  9. network:
  10. connect: true

已尝试的上下文值:

  • "."
  • "../.."
  • "../../.."
  • "/path/to/project/repo"

使用的Copilot命令:

  1. # 从project_root目录执行
  2. copilot svc deploy --name api --env staging

对于每个image.context,我都收到相同的错误消息,指示找不到任何Dockerfile COPY命令的文件源位置。我看到的唯一两种解决方法是按照文档示例重新构建项目存储库的结构,或者在docker中构建服务映像,将其推送到ECR,然后使用image.location参数。

Copilot错误消息:

  1. [+] 构建中 0.5s (14/14) 完成
  2. => [internal] Dockerfile加载构建定义
  3. => => 传输dockerfile: 37B
  4. => [internal] 加载.dockerignore
  5. => => 传输上下文: 2B
  6. => [internal] docker.io/library/python:3.11加载元数据
  7. => [internal] 加载构建上下文
  8. => => 传输上下文: 2B
  9. => [ 1/10] docker.io/library/python:3.11构建
  10. ...
  11. => ERROR [10/10] COPY requirements.txt .
  12. ------
  13. > [10/10] 复制requirements.txt .:
  14. ------
  15. 无法计算缓存密钥: 未找到"/requirements.txt": 未找到

除了尝试不同的上下文值外,我还使用homebrew aws/tap/copilot-cli tap将Copilot从版本1.25.0升级到1.29.1。

英文:

How can the AWS Copilot image.context manifest file parameter be set to the project’s root directory? I’m translating a Docker Compose file to Copilot manifest files but I’ve been unable to get Copilot to honor the image.context parameter using either relative or absolute paths.

Approximate project repository structure:

  1. - project_root
  2. - src
  3. - api.py
  4. - copilot
  5. - api
  6. - manifest.yaml
  7. - requirements.txt
  8. - requirements
  9. - base.in
  10. - base.txt
  11. - development.in
  12. - development.txt
  13. - production.in
  14. - production.txt
  15. - dockerfiles
  16. - api
  17. - Dockerfile
  18. - start_agent.sh
  19. - start_api.sh
  20. - docker-compose.yaml

Service Dockerfile

  1. FROM python:3.11
  2. RUN mkdir /app
  3. WORKDIR /app
  4. COPY ./requirements/ requirements
  5. COPY ./requirements.txt .
  6. RUN pip install -r requirements.txt
  7. COPY . /app
  8. COPY ./dockerfiles/services/api/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
  9. COPY --chmod=### ./dockerfiles/services/api/start_agent.sh /app/start_agent.sh
  10. COPY --chmod=### ./dockerfiles/services/api/start_api.sh /app/start_api.sh
  11. ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
  12. EXPOSE 8080

Service's Copilot manifest.yaml File

  1. name: api
  2. type: Backend Service
  3. image:
  4. build: ./dockerfiles/services/api/Dockerfile
  5. context: .
  6. port: 8080
  7. ...
  8. exec: true
  9. network:
  10. connect: true

Contexts Tried

  • "."
  • "../.."
  • "../../.."
  • "/path/to/project/repo"

Copilot Command Used

  1. # from project_root
  2. copilot svc deploy --name api --env staging

For each image.context I get the same error that none of the file source locations of any of the Dockerfile COPY commands could be found. The only two workarounds I see are to restructure the project repository following the documentation examples or build the service images in docker, push to ECR, then use the imagee.location parameter instead.

Copilot Error Message

  1. [+] Building 0.5s (14/14) FINISHED
  2. => [internal] load build definition from Dockerfile
  3. => => transferring dockerfile: 37B
  4. => [internal] load .dockerignore
  5. => => transferring context: 2B
  6. => [internal] load metadata for docker.io/library/python:3.11
  7. => [internal] load build context
  8. => => transferring context: 2B
  9. => [ 1/10] FROM docker.io/library/python:3.11
  10. ...
  11. => ERROR [10/10] COPY requirements.txt .
  12. ------
  13. > [10/10] COPY requirements.txt .:
  14. ------
  15. failed to compute cache key: "/requirements.txt" not found: not found

In addition to the different contexts values tried, I've also upgraded copilot from version 1.25.0 to 1.29.1 using the homebrew aws/tap/copilot-cli tap.

答案1

得分: 0

以下是翻译好的部分:

"manifest file context parameter wasn't specified correctly. There are two ways to specify an image build process.

Option One

  1. image:
  2. build: path/to/dockerfile

Option Two

  1. image:
  2. build:
  3. dockerfile: path/to/dockerfile
  4. context: .

The second option accepts a context parameter. In the first option, context is assumed to be the same directory as the Dockerfile specified in the build parameter."

英文:

The manifest file context parameter wasn't specified correctly. There are two ways to specify an image build process.

Option One

  1. image:
  2. build: path/to/dockerfile

Option Two

  1. image:
  2. build:
  3. dockerfile: path/to/dockerfile
  4. context: .

The second option accepts a context parameter. In the first option, context is assumed to be the same directory as the Dockerfile specified in the the build parameter.

huangapple
  • 本文由 发表于 2023年8月11日 03:09:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878696.html
匿名

发表评论

匿名网友

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

确定