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

Fixing more docker related stuff #141

Merged
merged 6 commits into from
Aug 7, 2024
Merged

Fixing more docker related stuff #141

merged 6 commits into from
Aug 7, 2024

Conversation

ctr26
Copy link
Contributor

@ctr26 ctr26 commented Aug 6, 2024

  • Old changes broke the deployment for the main api image build.
  • Issue was that the CI was quite specific, modified it to be more general
  • Also make the building caching faster

@ctr26
Copy link
Contributor Author

ctr26 commented Aug 6, 2024

https://github.com/ctr26/bia-integrator/actions/runs/10268180413

Passing build and push on my copy

api/Dockerfile Outdated
RUN poetry lock

# Poetry lock command likely unnecessary as we are copying the whole project
# For local development we only need to solve the lock once
RUN poetry install
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we also need to add poetry.lock to git if we do this. Also, even without resolving dependencies we would still pull all projects every time we build (e.g. on local). Can't we just re-add poetry.lock to git and keep the ADD shenanigans to make it go faster?

It's roughly the usecase at the bottom of this section (https://docs.docker.com/build/cache/#order-your-layers) in the docker docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's no lock file then poetry install will resolve when it installs.

We got rid of the lock file because it kept falling out of date when people make changes but didn't push lock changes.

There was a brief period of time where that was fixed with a pre-commit-hook but I don't think everyone adhered to installing that either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, git should be building with no-cache aswell to ensure it's all deterministic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you're right, forgot about the lockfile thing.

But can we keep the two-step add (lockfile/pyproject first, then install, then everything else on top of that)? That would make it so I don't always pull dependencies (even if they're resolved) when I rebuild on local as I'm changing code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, in my defence, I did not know you could run

poetry install without providing any actual source files and that it then just magically symlinks it all later anyway when you dopoetry run

My original answer was that you need to do ADD before poetry install so that it has your source files to install. But it doesn't, I double checked.

Sorry for wasting time on my own baseless assumptions

Copy link
Contributor

@liviuba liviuba Aug 6, 2024

Choose a reason for hiding this comment

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

This was actually a warning I was always getting but ignoring because it's a warning! Since we just need the dependencies installed and run uvicorn from the project root, I think we could do --no-root so bia-integrator-api itself gets skipped, I didn't catch that / was just thinking of it as installing dependencies, not installing the project itself

Also, should we maybe keep the comment line # only add poetry.lock if it exists (building on local)? It's there because the ADD below is weird, the poetry.lock* is a workaround for 'add if it exists', because otherwise if it's missing Docker errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add --no-root

@ctr26
Copy link
Contributor Author

ctr26 commented Aug 6, 2024

Yeah so til you can runpoetry install a project with no source files, but then when you add them later poetry is happy to find them for you. This is useful for docker stuff because you can cache the lock and toml files early in the build chain.

@ctr26
Copy link
Contributor Author

ctr26 commented Aug 6, 2024

general info here

https://nanmu.me/en/posts/2023/quick-dockerfile-for-python-poetry-projects/

@ctr26
Copy link
Contributor Author

ctr26 commented Aug 7, 2024

@liviuba ready to merge

@liviuba liviuba self-requested a review August 7, 2024 10:40
Copy link
Contributor

@liviuba liviuba left a comment

Choose a reason for hiding this comment

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

LGTM!

@liviuba liviuba merged commit 5d91c7a into main Aug 7, 2024
32 of 33 checks passed
@liviuba liviuba deleted the dockercompose branch August 7, 2024 10:41
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.

2 participants