1

I'm using create-react-app for my projects using docker as my dev env.

Now I would like to know how is the best practice to deploy my project into AWS (I'll deploy the docker).

Maybe my question is a dummy but I'm really stuck on it.

My docker file has a command yarn start... for dev it is enough I don't need to build anything, my bundle will run in memory, but for QA or PROD I would like to build using npm run build but as I know it will create a new folder with the files that should be used on prod env.

That said, my question is: what is the best practice for this kind of situation?

Thanks.

2 Answers 2

3

This is what I did:

  1. Use npm run build to build all static files.
  2. Use _/nginx image to customize an HTTP server which serves those static files. (Dockerfile)
  3. Upload the customized image to Amazon EC2 Container Service (ECS).
  4. Load the image in ECS task. Then use ELBv2 to start a load balance server to forward all outside requests to ECS.
  5. (Optional) Enable HTTPS in ELBv2.

One time things:

  1. Figure out the mechanism of ECS. You need to create at least one host server for ECS. I used the Amazon ECS-Optimized AMI.
  2. Create a Docker repository on ECS so you can upload your customized Docker image.
  3. Create ECS task definition(s) for your service.
  4. Create ECS cluster(s) and add task(s).
  5. Configure ELBv2 so it can forward the traffic to your internal ECS dynamic port.
  6. (Optional) Write script to automate everyday deployment.

I would get paid if someone wants me to do those things for her/him. Or you can figure it out by yourself following those clues.

However, if your website is a simple static site, I recommend to use Github pages: it's free and simple. My solution is for multiple static + dynamic applications which may involved other services (e.g. Redis, ElasticSearch) and required daily/hourly deployments.

Sign up to request clarification or add additional context in comments.

Comments

3

You would have to run npm run build and then copy the resulting files into your container. You could use a separate Dockerfile.build to build the files, extract them and add them to your final container. Your final container should be able to serve the files. You can base it on nginx or another server. You can also use it as a data volume container in your existing server container.

Recent versions of Docker make this process easier by allowing you to combine the two Dockerfiles. You can have a build container and then the final container both be defined in the same file.

Here's a simple example for your use case:

FROM node:onbuild AS builder
RUN npm run build

FROM nginx:latest
COPY --from=builder /usr/src/app/build /usr/share/nginx/html

You'd probably want to include your own nginx configuration file.

More on multistage builds here:

https://docs.docker.com/engine/userguide/eng-image/multistage-build/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.