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
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.
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.