-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[cookbook] Dockerize Vue.js App #1483
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
[cookbook] Dockerize Vue.js App #1483
Conversation
Hi! |
Hey @fabriziocucci just checking in here, how do you feel about making this into a full recipe? If you feel like it's too much work for you, we could close it out. Up to you :) We're flexible. |
@sdras sorry for my late reply.
So, please correct me if I'm wrong here, you agree on:
I guess my understanding of cookbook was completely wrong here, apologies! 😄 I thought a cookbook should go straight to the point rather than providing a broader context around the subject. In this specific case, I was giving for granted that the reader is already a Docker user (even newbie) or, at the very list, knows why he/she wants to dockerize a Vue.js app. Basically, what I was trying to avoid is writing yet-another-post-on-docker! 😅
I guess I'm trying to understand with your help the cut of the cookbook. Of course, if you guys are on a tight schedule, please feel free to tackle this intenally, I don't want to slow down this amazing project in any way! ❤️ |
Hi Fabrizio! All of the above is correct. In terms of covering Docker, I don't mean an in-depth-invent-the-universe kind of explanation. One sentence about the benefits of Docker, linking off to one of the other articles you cited here would suffice. If you're confused about what's to be expected of the cookbook beyond the contributing guide, take a look at some of the other examples. We tend to walk people through something simple, explain why we're doing the thing to begin with, then do a real-life implementation that's more specific (like nginx), explaining some caveats and things of note along the way. Then we tackle any alternative patterns. If you read through some of the others, you'll see a pattern there in some of the flow of the recipes. If this seems like too much work or time, just let me know and we can close this out or I can commit on top of it to flesh it out for you. Let me know if you have any further questions. Thanks! |
Now let's build a Docker image for our Vue.js app: | ||
|
||
```bash | ||
docker built -t vuejs-cookbook/dockerize-vuejs-app . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be build
and not built
WORKDIR /app | ||
|
||
# copy both 'package.json' and 'package-lock.json' (if available) | ||
COPY package*.json . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not try, but this should not work as well.
You cannot copy multiple files to .
. It should be a folder and should end with /
.
e2e3a10
to
ceb3ac3
Compare
@fabriziocucci Thanks for your effort! I initially followed along this article: how to deploy vue js app-in one line with docker but ran into issues. Perhaps you can add a more complex setup based on multi-stage docker? |
@robertotru @Anima-t3d |
I think @fabriziocucci has the right idea here. The Spring Boot cookbook is nice, but our cookbook (and guide) is different than theirs. We try to be more conversational in tone. Again, I'm not talking about a deep dive intro to Docker, one line is all that's necessary. This is more about editorial style and flow than anything. It also gives the opportunity to link off to other reading material if the reader is unfamiliar. I love the idea of the NGNIX example as the real-world example. I'm not sure we should include the medium article in the alternative patterns section. I agree that it feels pretty convoluted, and honestly a bit misleading as it's not really one line of code. That's like saying a giant function is one line of code because it returns on the last line. For alternative patterns, you literally talk about not using docker, but I leave it to you if you want it take it in another direction. |
I'm not really familiar with Docker so I just scavenged the web for information. I just thought to highlight the multi-stage build. It seems like the right approach? But I agree with @sdras, the main article feels pretty convoluted. |
@sdras thanks a lot for your feedback.
Apologies if my previous comment was a bit misleading. That wasn't my intention either! 😅 What I actually meant was to show in the Of course, only if it makes sense and if you guys think it could be useful... |
I've added a first draft of the I should probably describe a little bit more the NGINX changes but, before doing that, I'd like to give a shot at the multistage-build approach and see if it things get even simpler. Also, I'd like to fix the NGINX version that gets installed but this also can be done differently if we decide to go with the multistage-build approach. As usual, feedback are more than welcome! 😄 |
Indeed, the multi-stage build looks a little bit neater! 🤓 @robertotru please let me know what you think about it. |
Hi @fabriziocucci, this is much better but it's still not a complete recipe according to the guidelines. Can you please finish the full recipe with all of the required sections before requesting review? That would help us a lot. Thanks! |
Hi @sdras, thanks a lot for your prompt feedback. Based on the guidelines we should be almost there considering the required sections:
Would adding the Also, I've noticed that other cookbooks are not that strict when it comes to the guidelines, like Using Axios to Consume APIs which has the Thanks in advance! |
We can have a little leeway for omitting a section if the flow is still good, omitting one section would be ok, but I don't see a reason to omit several unless there is a good reason for it. Alternative Patterns section is critical: it's what sets The Cookbook apart from other resources. Usually people are "selling" you on an idea- our Cookbook's aim is to talk through the inevitable tradeoffs of any given approach. To be honest, I'm a little concerned that it's taking so much back and forth to get a rough draft. We're all low on time and it would be great if the next revision could come in without more comments needed. This is the most back and forth we've ever done before having a complete rough draft. That said, I do appreciate all the work that it takes to write these, so please let us know if you need help finishing it. Thanks! |
Apologies if it's taking too long and for asking feedback maybe too early in the process. Unfortunately, based on my experience, PRs are a continuous back and forth by definition and, if possible, it's best to ask feedback as early as possible to stay on the right track rather than after days of work maybe in the wrong direction. Perhaps it would be worth outlining how PRs are handled in te Cookbook-Contributions? Anyway, I've added a couple of sections (i.e. Thanks! |
@fabriziocucci there is a typo in By levereging -> By leveraging The rest looks pretty good to me. I am using it my current app. |
@Anima-t3d thanks for your feedback, typo fixed! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMD [ "http-server", "dist" ] don't work in SPA. It isn't fallback index.html
@boggddan thanks for your feedback. I was just checking the documentation for
Would it be sufficient to point that out as a warning and reference that page or should we go for a different approach (e.g. replacing |
@fabriziocucci thanks for this (and this might not the right place for a comment) anyway, thanks, and my apologies if this isn't the right place for this feedback. |
@henripal some feedback is always better than no feedback at all, even if it's not in the right place, so thanks for that! 😉
I think the answer to your question can be found here but maybe it's not clear enough (my bad). Saying that there is a nginx layer on top of node is not quite right. They are actually two separate stages, one is used to build the app for production (e.g. including minification), the other uses nginx to serve the app built from the previous stage. In the nowadays common scenario of using a container orchestration technology like Kubernetes for your production environment, you just need to build a docker image capable of serving your vue.js app and there are many different ways of doing that. What is outlined here is just one way of doing it. The rationale behind my approach is the following:
Please do let me know if that clarifies a bit. |
|
||
## Real-World Example | ||
|
||
In the previous example, we used a simple, zero-configuration command-line [http server](https://github.com/indexzero/http-server) to serve our Vue.js app. Your colleagues are impressed but your boss is still shaking his head because we chose not to stand on the shoulders of some giant like [NGINX](https://www.nginx.com/) or [Apache](https://httpd.apache.org/). Now we are going to make it right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph reads pretty strangely to me- it's not terribly important to be impressive to your colleagues, (not to mention the pronoun should be 'their' for boss), but most helpful to the reader would be an explanation of why we'd use nginx here, @henripal hinted at this. I'm not questioning your use of nginx, but there should be some technical explanation of why we might make a change like this, for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdras, as usual, thanks for your feedback.
I guess the whole point of the fiction scene was to point out that the reader's boss was not impressed by the work we (me and the reader) did in the simple example because he (the boss) already knew about "better" ways to serve the app (e.g. NGINX and Apache)! 😅
Anyway, I've updated the paragraph to be a little bit more formal and explicit, especially in explaining why I've decided to use NGINX for the real-world example.
Please do let me know if this new version makes sense to you.
--- | ||
title: Dockerize Vue.js App | ||
type: cookbook | ||
order: 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting close on this, can you please update the order to the last order so that it doesn't collide with other existing entries? I think this would be 13. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as per review! 😎
I'm wondering if there is a better way to handle this...
We're getting so close! This is looking really tight, thanks for all of your hard work on it. I think the last point is some clarification around your direction for ngnix as mentioned, and then it's good to go :) Thanks @fabriziocucci! |
Much better! Thank you. |
* Update unit-testing-vue-components.md (vuejs#1623) * Fixed a typo (vuejs#1625) Removed an extra 's' to fix a grammatical mistake * fix a typo (vuejs#1627) * Update v-for list example (vuejs#1628) * Add presentation role to style-only li item * fix: code snippet language (close vuejs#1617) (vuejs#1626) * Update todo-list-example for a11y (vuejs#1630) * Update todo-list-example for a11y * Implement review suggestions * Use explicit label instead of aria-label * Move v-model directive to top for improved readability * change NODE_ENV to follow recommendations from webpack (vuejs#1622) * change NODE_ENV to follow recommendations from weback * Update deployment.md * note that modes are not available in transition groups, fixes vuejs#1619 * add examples for in API doc * add comparison note about react-like libraries * Update components.md (vuejs#1632) * Update components.md * Update components.md * improve flow of single root component section * cookbook entry for storage (vuejs#1550) * cookbook entry for storage * minor tweak * updates to article * updates to article * maybe the last tweak * the honest to god really last mod * Update index.md (vuejs#1634) * docs(guide/comparison): correct size stat of Angular CLI project (vuejs#1638) * Update client-side-storage.md (vuejs#1640) * Update creating-custom-scroll-directives.md (vuejs#1639) * chore: update ad code * remove unnecessary word 'know' (vuejs#1641) * Updated broken links for the Vue Test Utils documentation. (vuejs#1643) * Reorganize component props to introduce prop types earlier, fixes vuejs#1644 (vuejs#1646) @BlitZz96 brought up a good point in [this issue](vuejs#1644) about users lacking the necessary background knowledge to fully understand Passing Static and Dynamic Props, at least as it relates to booleans and potentially other types in the future. To fix this, I added a new Prop Types section right before it. * First stab at SFC to npm documentation (vuejs#1558) * First stab at SFC to npm documentation * Clean up sample code, clarify .vue usage with SSR builds * Run build tasks in parallel, fix dependency order * Backtick all instances of .vue, minor edits for clarity * Fix typo on link * Update url to vue-sfc-rollup utility in acknowledgements * Fix order, other edits suggested by @sdras * Additional explanation about sfc-to-npm recipe package.json * Rename packaing-sfc-for-npm.md to packaging-sfc-for-npm.md (vuejs#1652) * Update link in comparison guide (vuejs#1653) The phrase "These state management patterns and even Redux itself can be easily integrated into Vue applications" has a link to a deprecated project. Instead I link to a yarnpkg.com search I saw used in https://vuejs.org/v2/guide/state-management.html, which links all "redux vue" projects (so it's always up to date) * chore: update vue version * Fix link to docs on custom inputs (vuejs#1660) The old link redirected me to https://vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components which was unexpected. I think the correct link is https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components as per this change. * correct wrong link (vuejs#1661) * Update events.md correct wrong link * Update events.md correct wrong link * Feature/vuemeetups (vuejs#1665) * feature: Add link to VueMeetups * feature: Add section on becoming a community leader * minor tweaks to meetup section * Added details about Lifecycle Hooks (vuejs#1664) * Added details about Lifecycle Hooks Mostly a clarification for beginners without prior knowledge about what Lifecycle hooks are. Makes it easier to understand when perhaps only knowing that the developer has a `mounted()` hook. I left out the function syntax because of generality. Add if it makes more sense to add. I am not fully knowledgable in Vue yet. * add (de)activated to lifecycle hooks list in style guide * improve comparisons react scaling down section * add text versions of image code examples * remove extra comma in components * TypeScript project generation in @vue/cli 3.0 (vuejs#1668) * TypeScript project generation in @vue/cli 3.0 update information about generating TypeScript project using new @vue/cli 3.0 * tweaks to Vue CLI 3 TypeScript support docs * chore: update sponsors * Sylvain and Forresst feedbacks Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * chore: update sponsors * update CLI docs link * add Scrimba links for preview * @ForrestT and @raisonblue feedback Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Feedback of @rspt Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Fix example indentation in the Unit Testing Vue Components recipe (vuejs#1683) * Update debugging-in-vscode.md (vuejs#1662) * Added link to vuemeetups.org to the ecosystem drop-down menu on website. (vuejs#1685) * Correct mistake of Migration from Vue 1.x (vuejs#1686) * Fix code style in Form Validation recipe (vuejs#1682) * Fix code style in Form Validation recipe * More style code slight improvement in Form Validation recipe * Fix code style in Client-Side Storage recipe (vuejs#1690) * [Doc EN]: `typescript.md` (vuejs#1679) * New in with + symbol Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Review of 2.5.0 doc Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Review Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Fix syntax typo Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Add space between new line of documentation Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Add @posva review Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Add french str Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Change directeur to director Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Fix EN doc Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Subtitle for typescript.md Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Revert instance.md Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * [cookbook] Dockerize Vue.js App (vuejs#1483) * First draft with 'Simple Example' section * Fix typo on Docker 'build' command * Fix copy of multiple files * Remove unnecessary whitespace * Fix typo in webpack template link * First draft of 'Real-World Example' * Update 'Real-World Example' with multi-stage build * Add 'Why Dockerize a Vue.js App?' section * Rename 'Why Dockerize a Vue.js App?' as 'Additinal Context' * Add 'Alternative Patterns' section * Minor fix on 'Alternative Patterns' * Fixed typo * Update order to avoid collision with other cookbooks * Clarify why NGINX in real-world example * Update debugging-in-vscode.md (vuejs#1663) * remove outdated information about polymer from comparison * update React comparison status * Remove extra part Signed-off-by: Haeresis <bruno.lesieur@gmail.com> * Remove extra content from api/index.md Signed-off-by: Haeresis <bruno.lesieur@gmail.com> * Remove extra merge Signed-off-by: Haeresis <bruno.lesieur@gmail.com>
* Update unit-testing-vue-components.md (vuejs#1623) * Fixed a typo (vuejs#1625) Removed an extra 's' to fix a grammatical mistake * fix a typo (vuejs#1627) * Update v-for list example (vuejs#1628) * Add presentation role to style-only li item * fix: code snippet language (close vuejs#1617) (vuejs#1626) * Update todo-list-example for a11y (vuejs#1630) * Update todo-list-example for a11y * Implement review suggestions * Use explicit label instead of aria-label * Move v-model directive to top for improved readability * change NODE_ENV to follow recommendations from webpack (vuejs#1622) * change NODE_ENV to follow recommendations from weback * Update deployment.md * note that modes are not available in transition groups, fixes vuejs#1619 * add examples for in API doc * add comparison note about react-like libraries * Update components.md (vuejs#1632) * Update components.md * Update components.md * improve flow of single root component section * cookbook entry for storage (vuejs#1550) * cookbook entry for storage * minor tweak * updates to article * updates to article * maybe the last tweak * the honest to god really last mod * Update index.md (vuejs#1634) * docs(guide/comparison): correct size stat of Angular CLI project (vuejs#1638) * Update client-side-storage.md (vuejs#1640) * Update creating-custom-scroll-directives.md (vuejs#1639) * chore: update ad code * remove unnecessary word 'know' (vuejs#1641) * Updated broken links for the Vue Test Utils documentation. (vuejs#1643) * Reorganize component props to introduce prop types earlier, fixes vuejs#1644 (vuejs#1646) @BlitZz96 brought up a good point in [this issue](vuejs#1644) about users lacking the necessary background knowledge to fully understand Passing Static and Dynamic Props, at least as it relates to booleans and potentially other types in the future. To fix this, I added a new Prop Types section right before it. * First stab at SFC to npm documentation (vuejs#1558) * First stab at SFC to npm documentation * Clean up sample code, clarify .vue usage with SSR builds * Run build tasks in parallel, fix dependency order * Backtick all instances of .vue, minor edits for clarity * Fix typo on link * Update url to vue-sfc-rollup utility in acknowledgements * Fix order, other edits suggested by @sdras * Additional explanation about sfc-to-npm recipe package.json * Rename packaing-sfc-for-npm.md to packaging-sfc-for-npm.md (vuejs#1652) * Update link in comparison guide (vuejs#1653) The phrase "These state management patterns and even Redux itself can be easily integrated into Vue applications" has a link to a deprecated project. Instead I link to a yarnpkg.com search I saw used in https://vuejs.org/v2/guide/state-management.html, which links all "redux vue" projects (so it's always up to date) * chore: update vue version * Fix link to docs on custom inputs (vuejs#1660) The old link redirected me to https://vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components which was unexpected. I think the correct link is https://vuejs.org/v2/guide/components.html#Using-v-model-on-Components as per this change. * correct wrong link (vuejs#1661) * Update events.md correct wrong link * Update events.md correct wrong link * Feature/vuemeetups (vuejs#1665) * feature: Add link to VueMeetups * feature: Add section on becoming a community leader * minor tweaks to meetup section * Added details about Lifecycle Hooks (vuejs#1664) * Added details about Lifecycle Hooks Mostly a clarification for beginners without prior knowledge about what Lifecycle hooks are. Makes it easier to understand when perhaps only knowing that the developer has a `mounted()` hook. I left out the function syntax because of generality. Add if it makes more sense to add. I am not fully knowledgable in Vue yet. * add (de)activated to lifecycle hooks list in style guide * improve comparisons react scaling down section * add text versions of image code examples * remove extra comma in components * TypeScript project generation in @vue/cli 3.0 (vuejs#1668) * TypeScript project generation in @vue/cli 3.0 update information about generating TypeScript project using new @vue/cli 3.0 * tweaks to Vue CLI 3 TypeScript support docs * chore: update sponsors * chore: update sponsors * update CLI docs link * add Scrimba links for preview * Fix example indentation in the Unit Testing Vue Components recipe (vuejs#1683) * Update debugging-in-vscode.md (vuejs#1662) * Added link to vuemeetups.org to the ecosystem drop-down menu on website. (vuejs#1685) * Correct mistake of Migration from Vue 1.x (vuejs#1686) * Fix code style in Form Validation recipe (vuejs#1682) * Fix code style in Form Validation recipe * More style code slight improvement in Form Validation recipe * Fix code style in Client-Side Storage recipe (vuejs#1690) * [Doc EN]: `typescript.md` (vuejs#1679) * New in with + symbol Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Review of 2.5.0 doc Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Review Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Fix syntax typo Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Add space between new line of documentation Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Add @posva review Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Add french str Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Change directeur to director Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Fix EN doc Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Subtitle for typescript.md Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * Revert instance.md Signed-off-by: MachinisteWeb <bruno.lesieur@gmail.com> * [cookbook] Dockerize Vue.js App (vuejs#1483) * First draft with 'Simple Example' section * Fix typo on Docker 'build' command * Fix copy of multiple files * Remove unnecessary whitespace * Fix typo in webpack template link * First draft of 'Real-World Example' * Update 'Real-World Example' with multi-stage build * Add 'Why Dockerize a Vue.js App?' section * Rename 'Why Dockerize a Vue.js App?' as 'Additinal Context' * Add 'Alternative Patterns' section * Minor fix on 'Alternative Patterns' * Fixed typo * Update order to avoid collision with other cookbooks * Clarify why NGINX in real-world example * Update debugging-in-vscode.md (vuejs#1663) * remove outdated information about polymer from comparison * update React comparison status * chore: adjust sponsor placement * chore: sponsor meta * adjust sponsor naming on pages * Add alt text to images to help with screen reader accessibility (vuejs#1676) * chore: update sponsors * chore: add tidelift
@sdras
As promised, I've created the first draft of this cookbook idea so that we can start deciding which direction we want it to go, specifically:
Simple Example
is simple enough or should we move the Docker caching layer optimization in aReal-World Example
?Real-World Example
that replaces the simple http-server with something a little bit more "robust" like nginx?(This closes #1357)