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

Refine deployment process #9

Open
xmedr opened this issue Nov 19, 2024 · 6 comments
Open

Refine deployment process #9

xmedr opened this issue Nov 19, 2024 · 6 comments
Assignees

Comments

@xmedr
Copy link

xmedr commented Nov 19, 2024

Recently used this cookiecutter to deploy an app to heroku, and here are some findings for things to consider or sections to adjust:

  • Had some trouble getting the build command working for the first time. So IIRC I had to specify that it should grab from main (instead of default master) and adjust it to something like: docker build github.com/datamade/cookiecutter-django-app#main -t cookiecutter:latest
  • There were some small linting adjustments that needed to be made. Check out this commit for specifics.
  • pytest needs to be added to requirements.txt
  • Since the test run depends on having an image published to ghcr, the repo's initial commit to main should contain the cookiecutter's output.
  • The clear_cache management command needs to be added. Check out its implementation in la-metro-councilmatic for a solution.

More may come as I finish the heroku deployment.

@xmedr xmedr changed the title Refine usage process Refine deployment process Nov 19, 2024
@xmedr xmedr self-assigned this Nov 22, 2024
@hancush
Copy link
Member

hancush commented Nov 22, 2024

Probably also a good idea to add a note to the usage section indicating that the cookiecutter output should be added to GitHub as one initial commit to main and triggering the publish package job via the Actions UI so the image that the tests and deployments depend on is created! Also making the package public (because our Heroku approach doesn't support building from private images).

@xmedr
Copy link
Author

xmedr commented Nov 22, 2024

Agreed, sounds good. Some more things to adjust:

  • Add gunicorn to the requirements
  • A CSRF_TRUSTED_ORIGINS = ["https://*.herokuapp.com", "http://localhost:8000"] needs to go into settings
  • Should adjust this line to include an argument is_default_site=True to the get_or_create.

@hancush
Copy link
Member

hancush commented Nov 22, 2024

Oh yeah, for Wagtail, ALLOWED_HOSTS also needs to include localhost:8000 for previews to work when editing pages.

@hancush
Copy link
Member

hancush commented Dec 2, 2024

I used this approach to derive trusted CSRF origins from allowed hosts for NOAH: https://github.com/datamade/tpc-ihs-noah-map/blob/e46e67e97957890e0cf57cd370b580ccf1738984/noah_map/settings.py#L35C1-L44C40

@haowens
Copy link

haowens commented Dec 10, 2024

Also recently deployed an app generated w/ cookie cutter to Heroku (my first time working with Heroku), here are my notes:

Notes

  1. This command wasn't anywhere in the docs, but I had to install the manifest plug-in locally myself to get the Heroku create steps to work properly: heroku plugins:install @heroku-cli/plugin-manifest

    • It was kind of hard to locate this command, and doesn't seem like the plugin is super clearly documented or in use (the link to its Github repo from this page gives a 404 error)
    • A manifest is not something I had to directly ever engage with, but apparently it contains metadata and configuration settings necessary for deployment. If this plug-in’s documentation was more intact I might better understand what exactly it’s doing here. But, if you go to the package for your repo and click on the Docker image that was successfully pushed to ghcr, there is a manifest with a bunch of associated json there, so I’m guessing the plugin autogenerated that for us somewhere in this setup/connection process
  2. Connecting to Github

    • We are packaging a Docker image and pushing it to GitHub’s Container Registry (ghcr), b/c it facilitates easier integration with GitHub actions and continuous pipelines/automatic deploys
    • Go to app page in Heroku Cloud and in settings authorize Github. and/or make sure you have admin access to the repo in question
    • Have to make this package public if the repo is private (as Hannah/Xavier figured out above): Datamade org → packages → mccormick-data-portal → change visibility
  3. Linting

    • Make the changes Xavier mentions here: add node modules to flake8 exclusions, add gunicorn, pytest, clear_cache.py
    • Additional linting things: Add Prettier to package.json, and add a prettierignore file so linting checks pass (also prettier pre-commit was not configured in the cookiecutter so you'll probably need to add that as well). And then you also need to tell black to ignore the same files as flake8 in the Github Action job: black_args: "--check . --exclude 'mccormick_data_portal/migrations|node_modules'"

@haowens
Copy link

haowens commented Dec 11, 2024

Also just noting that "noah_map" is hardcoded here instead of the cookie cutter module name

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

No branches or pull requests

3 participants