Hi there,
CodeBuild specs:
- Platform: Ubuntu
- Runtime: Standard
- Image: aws/codebuild/Standard:7.0
During the final Deploy Stage, I'm receiving the following error:
2024/05/01 14:03:50.450964 [ERROR] An error occurred during execution of command [app-deploy] - [Docker Specific Build Application]. Stop running the command. Error: failed to read Dockerfile: open /var/app/staging/server/backend.Dockerfile: no such file or directory
This is my docker-compose.yml
version: '3.8'
services:
server:
image: ************.dkr.ecr.us-east-2.amazonaws.com/howdy-api-production:${IMAGE_TAG:-latest}
container_name: servername
platform: linux/amd64
restart: always
environment:
- RDS_USER=${RDS_USER}
- RDS_PASSWORD=${RDS_PASSWORD}
- RDS_SERVER=${RDS_SERVER}
- RDS_PORT=${RDS_PORT}
- RDS_DB=${RDS_DB}
- REDIS_PORT=${REDIS_PORT}
- SECRET_KEY=${SECRET_KEY}
- SMTP_SENDER_ADDRESS=${SMTP_SENDER_ADDRESS}
- SENDGRID_API_KEY=${SENDGRID_API_KEY}
- AWS_KEY_ID=${AWS_KEY_ID}
- AWS_SECRET_KEY=${AWS_SECRET_KEY}
build:
context: ./server
dockerfile: backend.Dockerfile
volumes:
- ./server/app/:/app/
- public_assets:/app/shared/public
# env_file:
# - ./server/.env
ports:
- 8000:8000
networks:
- howdynetwork
And here's the backend.Dockerfile
FROM python:3.11.1-slim
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /app/requirements.txt
RUN pip3 install --no-cache-dir -r /app/requirements.txt
COPY ./app /app/
CMD ["uvicorn","main:app","--host=0.0.0.0","--port=8000","--reload", "--log-level=debug"]
Finally, here's my buildspec.yml
version: 0.2
phases:
pre_build:
commands:
- echo "Logging in to Amazon ECR..."
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- COMMIT_SHA=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_SHA:-latest}
build:
commands:
- echo "Build started on `date`"
- cd ./server
- docker build -f backend.Dockerfile -t $IMAGE_REPOSITORY:$IMAGE_TAG .
- docker tag $IMAGE_REPOSITORY:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPOSITORY:$IMAGE_TAG
- cd ..
- echo "Build completed on `date`"
post_build:
commands:
- echo "Push the docker image to AWS ECR..."
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPOSITORY:$IMAGE_TAG
- echo "Update IMAGE_TAG in docker-compose.yml..."
- sed -i -e "s/\${IMAGE_TAG:-latest}/$IMAGE_TAG/g" docker-compose.yml
artifacts:
files:
- .ebextensions/**/*
- docker-compose.yml
- nginx.conf
# cache:
# paths:
# - node_modules
Here's my project structure:
If I use AWSCLI such as eb deploy ... the deploy is without any problems.
Finally, as a note, I'm following this tutorial https://bentranz.medium.com/setup-continuous-deployment-pipeline-for-aws-elastic-beanstalk-5f8edb38d872
Can you tell me the structure of your repository? I suspect a problem with the folder structure and file locations.
I just updated the question with a screenshot that shows the folder structure
Can you try adding -w with server directory like this
I updated the buildspec.yml file to reflect the attempt. Unfortunately, the same error persists.
Instead of [docker build -w ...] which I gathered is an unsupported flag, I switched directories during the Build Stage and tried to replicate the effort.