英文:
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参数。
项目存储库结构示例:
- project_root
- src
- api.py
- copilot
- api
- manifest.yaml
- requirements.txt
- requirements
- base.in
- base.txt
- development.in
- development.txt
- production.in
- production.txt
- dockerfiles
- api
- Dockerfile
- start_agent.sh
- start_api.sh
- docker-compose.yaml
服务的Dockerfile:
FROM python:3.11
RUN mkdir /app
WORKDIR /app
COPY ./requirements/ requirements
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
COPY ./dockerfiles/services/api/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chmod=### ./dockerfiles/services/api/start_agent.sh /app/start_agent.sh
COPY --chmod=### ./dockerfiles/services/api/start_api.sh /app/start_api.sh
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
EXPOSE 8080
服务的Copilot manifest.yaml文件:
name: api
type: Backend Service
image:
build: ./dockerfiles/services/api/Dockerfile
context: .
port: 8080
...
exec: true
network:
connect: true
已尝试的上下文值:
- "."
- "../.."
- "../../.."
- "/path/to/project/repo"
使用的Copilot命令:
# 从project_root目录执行
copilot svc deploy --name api --env staging
对于每个image.context,我都收到相同的错误消息,指示找不到任何Dockerfile COPY命令的文件源位置。我看到的唯一两种解决方法是按照文档示例重新构建项目存储库的结构,或者在docker中构建服务映像,将其推送到ECR,然后使用image.location参数。
Copilot错误消息:
[+] 构建中 0.5s (14/14) 完成
=> [internal] 从Dockerfile加载构建定义
=> => 传输dockerfile: 37B
=> [internal] 加载.dockerignore
=> => 传输上下文: 2B
=> [internal] 为docker.io/library/python:3.11加载元数据
=> [internal] 加载构建上下文
=> => 传输上下文: 2B
=> [ 1/10] 从docker.io/library/python:3.11构建
...
=> ERROR [10/10] COPY requirements.txt .
------
> [10/10] 复制requirements.txt .:
------
无法计算缓存密钥: 未找到"/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:
- project_root
- src
- api.py
- copilot
- api
- manifest.yaml
- requirements.txt
- requirements
- base.in
- base.txt
- development.in
- development.txt
- production.in
- production.txt
- dockerfiles
- api
- Dockerfile
- start_agent.sh
- start_api.sh
- docker-compose.yaml
Service Dockerfile
FROM python:3.11
RUN mkdir /app
WORKDIR /app
COPY ./requirements/ requirements
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
COPY ./dockerfiles/services/api/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chmod=### ./dockerfiles/services/api/start_agent.sh /app/start_agent.sh
COPY --chmod=### ./dockerfiles/services/api/start_api.sh /app/start_api.sh
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
EXPOSE 8080
Service's Copilot manifest.yaml File
name: api
type: Backend Service
image:
build: ./dockerfiles/services/api/Dockerfile
context: .
port: 8080
...
exec: true
network:
connect: true
Contexts Tried
- "."
- "../.."
- "../../.."
- "/path/to/project/repo"
Copilot Command Used
# from project_root
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
[+] Building 0.5s (14/14) FINISHED
=> [internal] load build definition from Dockerfile
=> => transferring dockerfile: 37B
=> [internal] load .dockerignore
=> => transferring context: 2B
=> [internal] load metadata for docker.io/library/python:3.11
=> [internal] load build context
=> => transferring context: 2B
=> [ 1/10] FROM docker.io/library/python:3.11
...
=> ERROR [10/10] COPY requirements.txt .
------
> [10/10] COPY requirements.txt .:
------
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
image:
build: path/to/dockerfile
Option Two
image:
build:
dockerfile: path/to/dockerfile
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
image:
build: path/to/dockerfile
Option Two
image:
build:
dockerfile: path/to/dockerfile
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论