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

Use independent Docker image to build assets #7992

Merged
merged 2 commits into from Mar 8, 2021

Conversation

humitos
Copy link
Member

@humitos humitos commented Mar 7, 2021

Currently to build assets we need to install nodejs locally, install all the
node packages locally and call npm ci && bower update && npm run build. This
has some downsides due that all of this commands are not ran inside the docker
container:

  • we need to have all the Python requirements installed locally
  • manage.py collectstatic is run in the host machine
  • all the static files are not copied to the S3 storage backend
  • we don't know what version of nodejs is the valid one

To avoid all of these issues, this commit creates a new invoke task:

inv docker.buildassets

which pins the version of node used, runs all the node commands in an isolated
docker container and finally runs manage.py collectstatic --noinput inside the
web container, which will copy all the new assets to the S3 storage backend
automatically for us.

(requires a PR in readthedocs/common repository: readthedocs/common#85)

Currently to build assets we need to install nodejs locally, install all the
node packages locally and call `npm ci && bower update && npm run build`. This
has some downsides due that all of this commands are not ran inside the docker
container:

- we need to have all the Python requirements installed locally
- `manage.py collectstatic` is run in the host machine
- all the static files are not copied to the S3 storage backend
- we don't know what version of `nodejs` is the valid one

To avoid all of these issues, this commit creates a new invoke task:

   inv docker.buildassets

which pins the version of node used, runs all the node commands in an isolated
docker container and finally runs `manage.py collectstatic --noinput` inside the
`web` container, which will copy all the new assets to the S3 storage backend
automatically for us.

(requires a PR in readthedocs/common repository)
@humitos humitos requested a review from a team March 7, 2021 18:43
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This is a solid change. 👍

@@ -0,0 +1,8 @@
version: '3'
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a different file? I find it nicer having everything in 1 place, so we don't have to check 6 different files for docker config.

Copy link
Member Author

Choose a reason for hiding this comment

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

The nodejs container is not needed to run the development instance (and vice-versa). We use the same pattern here than the one for search/ext-them, which are optional as well.

@humitos humitos merged commit c987378 into master Mar 8, 2021
@humitos humitos deleted the humitos/buildassets-docker branch March 8, 2021 16:09

services:
assets:
image: node:8.16
Copy link
Member

Choose a reason for hiding this comment

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

This is a really old version, we were generating the assets with 10.17 locally

Copy link
Member Author

Choose a reason for hiding this comment

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

8.16 is the one that I've been using all this time. I know people are using different versions, but I don't know which one is using each of us.

I'm happy to update to any other one, but I haven't test them and I don't want to jump into that if it does not add anything to us. It use to break just randomly 😄

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants