0
votes

My docker container works locally, I'm trying to deploy it on elastic beanstalk using travis. My travis build is successful. The docker container has been tested locally and it works. On AWS Elastic Beanstalk I get a "Not a file/Directory error" for my build directory.

Dockerfile

FROM node:alpine as builder

WORKDIR '/app'

COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "build"]

#Run Phase
FROM nginx 
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html

Dockerfile.dev

FROM node:alpine

WORKDIR '/app'

COPY package.json .
RUN npm install 

COPY . .

CMD ["npm", "run", "start"]

travis.yml

sudo: required
services:
    - docker

before_install:
    - docker build -t *******/docker -f Dockerfile.dev .
script:
    - docker run -e CI=true *******/docker npm run test -- --coverage

deploy:
    provider: elasticbeanstalk
    region: "ap-south-1"
    app: "docker"
    env: "Docker-env-2"
    bucket_name: "***********************"
    bucket_path: "docker"
    on:
        branch: master
    access_key_id: $AWS_ACCESS_KEY
    secret_access_key: $AWS_SECRET_KEY

Following are the logs -

Travis output

Elastic Beanstalk output

Any help would be appreciated, thanks!

To run it locally, I run the following commands-

1) docker build -t *******/docker .
2) docker run -it <port>:80 <container_id>

It works as expected and I can reach the server on localhost:. I've put the same commands on the travis.yml file as well.

There are two dockerfiles because I would only be needing the "build" directory in the production container and I can ignore the rest of the directories to save space.

1
What does the application do differently in the two environments; how are the two image attachments different, and what code produces them? (If they are log files, please edit the question to include the actual text, not an image and not as an attachment or link.) Why are there two separate Dockerfiles? When you say "it works locally", how do you build and run it?David Maze
Thank you for taking your time to reply, I'll answer your questions one by one, The application doesn't do anything different in both the environments. I'm using travis-ci, that is linked to my github repo, to pull, run tests and deploy onto AWS whenever I push code into the master branch. These are not log files per se, they are basically the "event history" in AWS and job log (as part of the UI on travis-ci.org). I don't have enough reputation to embed so I had to attach it as a link. There are two separate docker files as one of them is for dev, the other is for production.Praneeth Katuri
Okay I'm haven't done any react, I ran the create-react-app command to generate a sample app and deploy it on AWS using travis-ci (The course instructor taught this). I realized that there is already a build directory in my project root folder, which was created with the "create-react-app" command. This build directory isn't in the running container which is why the copy is failing.Praneeth Katuri
Okay I was very stupid. I assumed the build directory would automatically be generated when I run react-app build command, and moreover the build directory was in the .gitignore file and hence Travis could no access it. I solved it now, thanks for the help anyway!Praneeth Katuri
You should consider posting an answer for your own question and accepting it for the sake of anyone, who has similar problems in the future.Konrad Botor

1 Answers

0
votes

I realized that the build directory was listed in the .gitignore file, thereby preventing travis-ci from accessing it as it isn't in the repo. Once I removed it and re-deployed it, worked perfectly.