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 Docker support #172

Merged
merged 19 commits into from
Feb 15, 2022
Merged

Add Docker support #172

merged 19 commits into from
Feb 15, 2022

Conversation

ClFeSc
Copy link
Contributor

@ClFeSc ClFeSc commented Feb 5, 2022

Closes #117

Supersedes #144

What did we change in this PR?

  • You can now start the whole app with docker-compose up -d in the root directory. See README.md for more details.
  • We fixed some issues that surfaced while doing this, like the incorrect start:once for the backend.

From #117:

  • pass environment flags (whether production or not) to immer, socket.io, etc. (or make sure they use the Node environment)

@ClFeSc ClFeSc added frontend Issues mainly related to the frontend backend Issues mainly related to the backend meta Issues mainly related to non-TS stuff (e.g. CI) labels Feb 5, 2022
@ClFeSc ClFeSc added this to the 2 milestone Feb 5, 2022
@ClFeSc ClFeSc mentioned this pull request Feb 5, 2022
@ClFeSc ClFeSc marked this pull request as draft February 5, 2022 13:44
@ClFeSc ClFeSc linked an issue Feb 5, 2022 that may be closed by this pull request
docker-compose.yml Outdated Show resolved Hide resolved
@ClFeSc ClFeSc marked this pull request as ready for review February 12, 2022 11:52
@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 13, 2022

Regarding production flags:

Backend

  • class-validator: No production setting
  • cors: No production setting
  • dotenv: No production setting
  • envalid: Should use NODE_ENV. Set to production mode when NODE_ENV=production
  • express: Should use NODE_ENVSet to production when NODE_ENV=production
  • lodah-es: No production setting
  • socket.io: Not sure whether socket.io itself uses production environment, but if it does it takes its information from NODE_ENV with NODE_ENV=production
  • supertest: Accidently a dependency, should be a devDependency...

Frontend

  • Everything angular: I think we are safe by using --configuration deployment (that is identical to production apart from the ports) and ng build that should use productionby default.
  • @ngrx/store: Should have a production mode but I couldn't find a way to enable it. Probably relies on other environments such as angular.
  • bootstrap : No production setting
  • lodash-es: No production setting
  • ol: Production enabled when building the app
  • rxjs: No production setting
  • socket.io-client: No production setting
  • tslib: No production setting
  • zone.js: No production setting

Shared

  • class-transformer: No production setting
  • class-validator: No production setting
  • immer: Appears to be using NODE_ENV' with NODE_ENV=production`
  • lodash-es: No production setting
  • reflect-metadata: No production setting
  • uuid: No production setting

Root

No dependencies

Method

I looked through all dependencies of our four package.jsons. It doesn't seem to be necessary to do anything as far as I can tell.

@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 13, 2022

In my opinion, we should handle deployment in another issue/PR as it is not 100% tied to the dockerization. What are your thoughts on that?

@Dassderdie
Copy link
Collaborator

  • immer: Appears to be using NODE_ENv' with NODE_ENV=production`

Immer is also used in the frontend (because it is in shared).

I found this workaround to make it run in production in the frontend too:
immerjs/immer#557 (comment)

@Dassderdie
Copy link
Collaborator

In my opinion, we should handle deployment in another issue/PR as it is not 100% tied to the dockerization. What are your thoughts on that?

Sure.

@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 13, 2022

  • immer: Appears to be using NODE_ENv' with NODE_ENV=production`

Immer is also used in the frontend (because it is in shared).

I found this workaround to make it run in production in the frontend too: immerjs/immer#557 (comment)

Ah, right. I completely forgot the frontend is no node app... I think this approach should be possible without issues. What would be the best place to add this snippet? There is not really an index.ts, right?

@Dassderdie
Copy link
Collaborator

  • immer: Appears to be using NODE_ENv' with NODE_ENV=production`

Immer is also used in the frontend (because it is in shared).
I found this workaround to make it run in production in the frontend too: immerjs/immer#557 (comment)

Ah, right. I completely forgot the frontend is no node app... I think this approach should be possible without issues. What would be the best place to add this snippet? There is not really an index.ts, right?

frontend\src\main.ts is the place to add it. - (Don't forget to comment why we are doing this)

@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 13, 2022

I have no clue why this fails. VSCode tells me window.process should be of type NodeJS.Process.

@Dassderdie
Copy link
Collaborator

I have no clue why this fails. VSCode tells me window.process should be of type NodeJS.Process.

We don't have the node typings in the frontend, but vscode doesn't get that. I would just use as any a lot...

@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 13, 2022

I have no clue why this fails. VSCode tells me window.process should be of type NodeJS.Process.

We don't have the node typings in the frontend, but vscode doesn't get that. I would just use as any a lot...

Ah, I see. Fixed it by adding some as anys.

docker-compose.yml Outdated Show resolved Hide resolved
@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 14, 2022

@Dassderdie Your issue should be fixed and this PR should be ready for review.

Copy link
Collaborator

@Dassderdie Dassderdie left a comment

Choose a reason for hiding this comment

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

I still get the same error with cannot read env of undefined (probably because of docker-compose reusing some not invalidated cache?).
I set a breakpoint on main.js and manually added window.process = {} and it worked. So if it works for you it's good to go.

@ClFeSc
Copy link
Contributor Author

ClFeSc commented Feb 14, 2022

You can do something like docker volume ls. Copy the volume name containing frontend and run docker volume rm <this copied name>. Then run docker-compose down and docker-compose up -d --build. This should fix it.

@Dassderdie
Copy link
Collaborator

You can do something like docker volume ls. Copy the volume name containing frontend and run docker volume rm <this copied name>. Then run docker-compose down and docker-compose up -d --build. This should fix it.

worked 👍

@ClFeSc ClFeSc merged commit 5c7219e into dev Feb 15, 2022
anonym-HPI pushed a commit that referenced this pull request Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Issues mainly related to the backend frontend Issues mainly related to the frontend meta Issues mainly related to non-TS stuff (e.g. CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build everything in production
3 participants