在 AWS CodePipeline 的部署阶段,我收到以下错误:
[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
但是,当我通过 eb deploy CMD 部署映像时,它可以正常工作。
此外,本地镜像构建成功。
这是我的docker-compose.yml
version: '3.8'
services:
server:
image: ***********.dkr.ecr.us-east-2.amazonaws.com/some-repo: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
# depends_on:
# - database
# - cache
这是我的 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`"
- docker build -f ./server/backend.Dockerfile -t $IMAGE_REPOSITORY:$IMAGE_TAG ./server
- docker tag $IMAGE_REPOSITORY:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPOSITORY:$IMAGE_TAG
# - docker-compose -f docker-compose.yml build
- 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
我尝试为 Ubuntu 和 Amazon Linux 2 切换配置 CodeBuild 平台。此外,还尝试了 eb deploy cmd。
如果有人感兴趣,该问题已在 AWS re:Post 上得到解决