Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add with-docker-compose example #32668

Merged
merged 12 commits into from
Jun 14, 2022

Conversation

maxproske
Copy link
Contributor

@maxproske maxproske commented Dec 20, 2021

with-docker-compose contains everything needed to get Next.js up and running with Docker Compose.

This example aims to provide an easy-to-use, Next.js app development and production environment, all without Node.js being installed on the host machine. This ensures a consistent development environment across Windows, MacOS, and Linux teams.

I was inspired to create this, because the existing with-docker example only uses Docker to build the final production artifacts, not provide a development environment. Docker Compose easily syncs changes with containers for Hot Reloading, parallel builds, and networking, making it a powerful and consistent development tool.

Developers can easily extend this example by modifying the YAML files to include Nginx, Postgres, and other Docker images.

This example takes advantage of Docker multistage builds combined with the Next 12.1 Output Standalone feature, to create up to 80% smaller apps (Approximately 110 MB compared to 1 GB with create-next-app). I also included an example without multistage builds, for developers who don't want to get into the weeds.

I have been tweaking this Docker Compose setup over 3 years of real world use, but please let me know if anything can be improved.

@ijjk ijjk added the examples Issue/PR related to examples label Dec 20, 2021
@leerob
Copy link
Member

leerob commented Dec 20, 2021

Could you explain more where there's both a JS and TS apps? All examples will be TypeScript first going forward, so if you were worried about not having a vanilla JS one, that's okay 👍

@maxproske
Copy link
Contributor Author

Hi @leerob! My example contains separate directories for JS and TS apps, with Docker Compose files located at the root.

with-docker-compose/
├── next-js-app/
├── next-ts-app/
└── docker-compose.yml

I used this project structure instead of creating separate examples for JS and TS, because I wanted to demonstrate how Docker Compose can be used to successfully manage monorepos containing both JS and TS apps. I'm primarily a JavaScript developer, so I wanted to give others the option to create multiple JS or TS apps, or both.

Let me know what you think!

@supriome

This comment has been minimized.

@leerob
Copy link
Member

leerob commented Dec 21, 2021

I used this project structure instead of creating separate examples for JS and TS, because I wanted to demonstrate how Docker Compose can be used to successfully manage monorepos containing both JS and TS apps. I'm primarily a JavaScript developer, so I wanted to give others the option to create multiple JS or TS apps, or both.

Having a Docker Compose example is great - but I think we can simplify this to just the TypeScript app 👍

@maxproske
Copy link
Contributor Author

@leerob Thanks for your feedback! I have removed the JS app and updated the README.

@maxproske
Copy link
Contributor Author

@leerob Thanks again for your feedback. Hopefully I'm not creating extra pressure by asking when this example will be merged.

examples/with-docker-compose/.gitignore Outdated Show resolved Hide resolved
examples/with-docker-compose/README.md Show resolved Hide resolved
examples/with-docker-compose/README.md Outdated Show resolved Hide resolved
examples/with-docker-compose/README.md Outdated Show resolved Hide resolved
examples/with-docker-compose/next-app/package.json Outdated Show resolved Hide resolved
examples/with-docker-compose/next-app/dev.Dockerfile Outdated Show resolved Hide resolved
@maxproske
Copy link
Contributor Author

Thanks @leerob! I made all your requested changes.


export const getServerSideProps: GetServerSideProps<Props> = async () => {
return {
props: { serverOnlyVariable: process.env.ENV_VARIABLE },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this might give the wrong impression to developers about how to use environment variables and some might accidentally expose secrets this way. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I've removed this, since there's no need to showcase a basic feature of Next.js.

Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added some comments. Mostly to remove some files/packages that do not showcase anything in this example, to match our Example requirements:

https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples

@maxproske
Copy link
Contributor Author

Thank you @balazsorban44! It's pretty cool you ask new contributors what they think. I've made your requested changes, and re-read the examples guidelines.

Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kodiakhq kodiakhq bot merged commit 78809a3 into vercel:canary Jun 14, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants