skip to Main Content

I am trying to deploy my create-react-app to elastic bean stalk with docker
I have setup codepipeline with codebuild and elastic beanstalk.

I am getting this error

Stop running the command. Error: Dockerfile and Dockerrun.aws.json are both missing, abort deployment 

My Dockerfile looks like this

FROM tiangolo/node-frontend:10 as build-stage  
# Create app directory  
# RUN mkdir -p /usr/src/app  
# WORKDIR /usr/src/app  
  
WORKDIR /app  
  
  
# # fix npm private module  
# ARG NPM_TOKEN  
# COPY .npmrc /app/  
#COPY package.json package.json  
  
COPY package*.json /app/ 
COPY Dockerrun.aws.json /app/  
RUN npm install  
COPY ./ /app/  
# RUN CI=true npm test  
RUN npm run build  
  
# FROM nginx:1.15  
FROM nginx:1.13.3-alpine   
  
# Install app dependencies  
  
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx  
COPY --from=build-stage /app/build/ /usr/share/nginx/html  
# Copy the default nginx.conf provided by tiangolo/node-frontend  
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf  
  
RUN ls   
EXPOSE 80  

I also have a Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "3",
  "Image": {
    "Name": "something.dkr.ecr.us-east-2.amazonaws.com/subscribili:latest",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "5000"
    }
  ],
  "Logging": "/var/log/nginx"
}

my buildspec.yml file looks like this

version: 0.2
phases:
  pre_build:
    commands:
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
      - REPOSITORY_URI=something.dkr.ecr.us-east-2.amazonaws.com/subscribili
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=${COMMIT_HASH:=latest}
  build:
    commands:
      - docker build -t $REPOSITORY_URI:latest .
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
  post_build:
    commands:
      - docker push $REPOSITORY_URI:latest
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - printf '[{"name":"nginx","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
  files: imagedefinitions.json

I am sure there is some issue with buildspec file but I am just not sure what.

I have read all the documentation still couldn’t figure out how to write the buildspec file Docker.
Is there anything I am missing?

enter image description here

2

Answers


  1. Dockerfile and Dockerrun.aws.json these 2 files need to be in the same directory where the command "COPY Dockerrun.aws.json /app/ " is running. make sure these files exists in that directory and this error should disappear

    Login or Signup to reply.
  2. "eb deploy" command creates a zip file from your code. However, to make it as small as possible, it only takes the file that are commited to git. So, if you did not commit Dockerfile and Dockerrun file, these two files won’t be included in the zip.

    If you do not want it to behave like this, you can add .ebignore file to your projects root directory. This files commands are the same as the gitignore file; you can copy everything from gitignore to ebignore. If there is a .ebignore, cli will not check if the project is commited to a source control.

    Now to check what is included in zip file, watch the .elasticbeanstalk folder after "eb deploy" command. When the zip is prepared, copy it immediately and paste to another folder. Note: the original zip file will be removed after the cli upload that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search