Skip to content

Conversation

@ChristopherChudzicki
Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki commented Aug 3, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5109

Description (What does it do?)

This PR fixes sentry configuration during the frontend build, with the help of some new github secrets that Mike added.

How can this be tested?

I think we will need to do a release to actually test this. Some things worth doing:

  1. Make sure the app runs locally; I changed webpack config a little
  2. Run ./scripts/get_version.sh; it should return the app version

Comment on lines -44 to -47
ENVIRONMENT: str({
choices: ["local", "docker", "production"],
default: "production",
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this variable was confusing. The "docker" option used to be necessary for something, but at this point in our timeline, it isn't used for much.

The only thing this variable was used for is "Should webpack load env files itself"—that's usually not necessary because docker handles it. It is useful if you're running webpack locally outside of docker, so LOAD_ENV_FILES handles that now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes - better to provide flags for specific behaviors where there is little distinction for environments / sets of values.

Is API_DEV_PROXY_BASE_URL still a thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, though as you've mentioned there are issues running against RC with an authenticated user.

Comment on lines 241 to 239
ENVIRONMENT !== "local" && WEBPACK_ANALYZE === "True"
NODE_ENV === "local" && WEBPACK_ANALYZE === "True"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should have been based on NODE_ENV all along, since that's the canonical way to control whether to run a development build or a production-quality (minification, etc) build.

Copy link
Contributor

Choose a reason for hiding this comment

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

In Node.js the convention is that "production" instructs that we are not in development mode. Any other value indicates dev mode. It's more common to see "development", as "local" is an environment - as you say, NODE_ENV is really specifying a mode, not an environment.

Better then to say NODE_ENV !== "production" here. Where do we want / not want this to run though - is the change intended to invert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, yes, that was a mistake, thanks. I'm actually inclined to make this check only on WEBPACK_ANALYZE. It's useful to analyze in both production and dev builds.

Copy link
Contributor

Choose a reason for hiding this comment

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

More importantly - WEBPACK_ANALYZE will be a boolean from envalid, so that will never be set (in main).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm actually inclined to make this check only on WEBPACK_ANALYZE. It's useful to analyze in both production and dev builds.

Agree, the flag is sufficient. I'd only add extra checks if it specifically can't run there for risk of breakage etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't even really think there's any disadvantage to doing it in production other than generating a useless (on server) report.html file.

# Get VERSION from settings.py
grep -Eo -m 1 'VERSION\s+= .*(\d+)\.\d+\.\d+.*' main/settings.py |
head -1 |
grep -Eo "\d+\.\d+\.\d+"
Copy link
Contributor Author

@ChristopherChudzicki ChristopherChudzicki Aug 3, 2024

Choose a reason for hiding this comment

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

This is not ideal. With VERSION defined in settings.py, it's hard to access outside of Python. (e.g., in our JS
build github action).

For using VERSION during the github action, the options I see are:

  1. Add a new job to the currently JS-only action. It would be a python job, install our deps, run ./manage.py shell and print settings.VERSION, then export that for re-use in the next job that actually publishes frontend. This seems like a lot of set up to just get the version.
  2. this bash script
  3. Update Doof so that it also writes the version to something like version.txt

(3) would be my preference, though I know we are reluctant to update doof much.

Copy link
Contributor

Choose a reason for hiding this comment

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

If settings.py is canonical, it's ok to extract it from there (by any means!). I agree that 3 is nicer. It would be useful to also write this to a version.txt file for the front end build as we do with:

- name: Write commit SHA to file
  run: echo $GITHUB_SHA > frontends/mit-open/build/static/hash.txt

@ChristopherChudzicki ChristopherChudzicki marked this pull request as ready for review August 3, 2024 18:11
@ChristopherChudzicki ChristopherChudzicki added the Needs Review An open Pull Request that is ready for review label Aug 5, 2024
POSTHOG_PROJECT_ID: ${{ secrets.POSTHOG_PROJECT_ID_PROD }}
POSTHOG_PROJECT_API_KEY: ${{ secrets.POSTHOG_PROJECT_API_KEY_PROD }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN_PROD }}
SENTRY_ENV: ${{ secrets.MITOPEN_ENV_PROD }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Actions environments would be an improvement here so we are not having env vars that include the environment name - the job would run in the environment context. Outside of the scope of this PR though, given there are others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For us, it is quite canonical. All of our repos have it, and Doof updates it automatically during release via https://github.com/mitodl/release-script/blob/b44bb831e78a5450e3b09e502fd8733b454157f0/version.py#L120

)
.concat(
ENVIRONMENT !== "local" && WEBPACK_ANALYZE === "True"
WEBPACK_ANALYZE === "True"
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a boolean once handled by envalid, never string "True". I think envalid will throw if set as anything other that "true" or "false".

@ChristopherChudzicki ChristopherChudzicki merged commit 8561611 into main Aug 6, 2024
@odlbot odlbot mentioned this pull request Aug 6, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants