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

Updated devcontainer to use production container #4039

Merged
merged 11 commits into from
Oct 23, 2024

Conversation

compscidr
Copy link
Contributor

@compscidr compscidr commented Oct 22, 2024

This is part II of the previous PR I made: #4032

In this PR, I updated the Dockerfile.vscode to use the base image we previously published to ghcr. I also tried to make the Dockerfile as close to the production Dockerfile as possible.
Based on @conbrad's suggestion, we now use the production container directly.

A few other changes I made:

  • updated devcontainer to use host networking. This made it possible for the dev container to talk to the database container on my linux system. I set the .env config to use localhost for the database read/write host and it worked.
  • used a postcreate command to change directory to /app so that when vscode terminal launches you are in the correct folder rather than /workspace. If you try to run start.sh from the workspace, you'll have venv issues, but if you run it from the /app folder, it will work.
  • Added a mount so that changes to files within api will be reflected live in the container (otherwise you'd have to rebuild the container to see the changes). Note, I avoided making a workspace mount because otherwise you'll only see the files from api in the vscode editor, and probably you still want to see everything. You could play around with the paths to make this not the case, but it would require updating the paths on the production container.
  • Updated the Dockerfile so that the virtualenv is owned by the worker instead of root (this lets us later on install pytest and other dev packages that we don't install in the prod image because we do a --without dev install.

How I tested:

  • In vscode typed f1 -> open folder in container, selected the wps folder.
  • started up the database container in a linux terminal using: docker compose up db
  • copied the .env.docker in /api/app to .env and set the db host to localhost (for some reason the host.docker.internal didn't work for me.
  • Either:
    • ran: PYTHONPATH=. poetry run alembic upgrade head && poetry run uvicorn app.main:app --host 0.0.0.0 --reload --port 8080 in terminal in vscode
    • ran the start.sh script from the /app directory on the container from the terminal in vscode
  • ran tests using make test
    Everything ran up to a migration that required me to have auth credentials I don't have.

Caveats:

  • if you did local dev directly on your machine and there is a .venv folder already existing in your app folder, it will break things. Ideally you should clobber that beforehand. I tried to solve it with a named volume, similar to how people do with the node_modules folders, but I had no luck, so perhaps this is a future item.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.99%. Comparing base (d3136ca) to head (0c6f91c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4039   +/-   ##
=======================================
  Coverage   79.99%   79.99%           
=======================================
  Files         303      303           
  Lines       11554    11554           
  Branches      549      549           
=======================================
  Hits         9243     9243           
  Misses       2126     2126           
  Partials      185      185           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@compscidr compscidr changed the title Updated devcontainer to be more like production Updated devcontainer to use production container Oct 22, 2024
Copy link

sonarcloud bot commented Oct 23, 2024

@conbrad conbrad merged commit 80235d1 into bcgov:main Oct 23, 2024
15 of 20 checks passed
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.

4 participants