-
Notifications
You must be signed in to change notification settings - Fork 50
Copy operational files into final docker images #455
Conversation
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.
Very nicely commented, thank you!
So when we attach the same directory as a volume during dev, the copied code is overwritten? |
Yes! The dev version will have a "live" version of the code, while the prod version will have a static set available within the image. More information can be found here, and the Docker docs (say that five times fast) actually describe exactly the scenario that's happening here:
One other thing I forgot to mention - I prefixed the image names with |
api/Dockerfile
Outdated
# Copy the operational code into the final image | ||
COPY run.sh manage.py /api/ | ||
COPY catalog/ /api/catalog/ |
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.
Could we write
COPY . /api
like we did for analytics?
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 would make the COPY
statement
- same in all Dockerfiles
- identical to the
volumes
rules from the Docker-Compose file
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.
My only concern with doing this is that it copies all files in each directory, which includes a number of files which are irrelevant for production use (including all of the tests). I've generally been steered away from that, but it might not be too much extra space. What do you think?
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.
Would a .dockerignore
file help with that? We could reduce a lot of cruft from going into the context.
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.
That is a great question! I'd be curious if the .dockerignore
would also pertain to bind mounts 🤔 I'll try it out - agreed that it'd be better in general!
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.
I also submitted #442 which would make the analytics/
code structure similar to ingestion_server/
. If you could maybe rebase this PR on top of that one, the same exclusion strategy would work for both codebases.
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.
Can do! This is also a good reminder to review that PR 😄
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.
The Docker docs (...Docker docs Docker docs Docker docs Docker docs) were very clear about it, thanks for the reference. LGTM!
@@ -65,7 +65,7 @@ services: | |||
|
|||
web: | |||
build: ./api/ | |||
image: api | |||
image: openverse-api |
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 is really good, 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.
Tried it and works well. The prefix for images makes sense too 👍
0de6e06
to
d726ad7
Compare
I've updated this to point at #442 so we can unify the approach. Tested with |
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 is awesome!
d726ad7
to
fe023ea
Compare
Description
Presently, we are unable to launch the ingestion server in production using only the published image. The current setup assumes that the operational files will be mounted into the containers when they are spun up, which may not be the case for all services running in production.
This PR adds steps in each
Dockerfile
to copy all of the necessary operational files into the image so they are available for the container on its own. Images can now be spun up on their own and run successfully without any attached volumes. This ensures that the images that are pulled from our container registry can be launched directly without requiring a copy of the code locally. It also means that our final images are immutable (at least in production), so we won't have any unexpected changes at runtime even if the repository code were to change.I also added a
just build
recipe for assistance with this work.Testing Instructions
./api:/api
) in thedocker-compose.yml
just build
just up
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin