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

Updates codebase to Go 1.14, preps for Heroku deploy #10

Merged
merged 8 commits into from
Apr 7, 2020
Merged

Conversation

krashanoff
Copy link
Contributor

Big PR round two. This is a much more digestible PR -- though it does still touch a great number of files in the repo. Here are all the changes made:

  • Formatting enforcement
    • This PR updates existing code to align with gofmt requirements.
  • Switch our codebase to Go 1.14.
    • The changes that this entails are pretty small. Just makes our package imports absolute.
  • Add a Heroku Procfile.
  • Add a go.mod file for dependencies.
    • This is needed by Heroku.
  • Uses environment variable values for credential retrieval and port setting, instead of a path to a JSON file.
    • This has been a long time coming, but we have it now. This PR makes the server get its Firebase credentials from the $TLACFG environment variable, and set its port from the $PORT variable.
    • If no TLA credentials are provided, the app experiences a runtime failure.
    • If there is no PORT variable set, it defaults to 8081 as always.
  • Consistently uses uid and pid query variables instead of mixing and matching programId, userId, uid, pid.
    • I noticed we were mixing and matching programId, userId, uid, and pid query variables all over the place in the backend. This PR fixes that so that we use uid and pid consistently.
  • Update GitHub Actions workflow to actually work (whoops!).

Copy link
Contributor Author

@krashanoff krashanoff left a comment

Choose a reason for hiding this comment

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

Wanted to publish a quick overview of the two changes that aren't pretty much refactoring or tiny devops files for reference.

Comment on lines -21 to +37
// OpenFromCreds returns a pointer to a database client based on
// JSON credentials pointed to by the provided path.
// OpenFromEnv returns a pointer to a database client based on
// JSON credentials given by the environment variable.
// Returns an error if it fails at any point.
func OpenFromCreds(ctx context.Context, path string) (*DB, error) {
// check, using os.Stat(), that the file exists. If it does not exist,
// then fail.
if _, err := os.Stat(path); err != nil {
return nil, err
func OpenFromEnv(ctx context.Context) (*DB, error) {
cfg := os.Getenv("TLACFG")
if cfg == "" {
return nil, fmt.Errorf("no $TLACFG environment variable provided")
}

// set up the app through which our client will be
// acquired.
opt := option.WithCredentialsFile(path)
opt := option.WithCredentialsJSON([]byte(cfg))
app, err := firebase.NewApp(ctx, nil, opt)
if err != nil {
return nil, err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updates OpenFromEnv to use the TLACFG envvar.

Comment on lines +58 to +64
// check for PORT variable.
port := os.Getenv("PORT")
if port == "" {
log.Printf("no $PORT environment variable provided, defaulting to '%s'", DEFAULTPORT)
port = "8081"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gets port to serve on from envvars; defaults to 8081 if not provided.

@krashanoff krashanoff requested a review from tfukaza April 7, 2020 01:36
Copy link
Contributor

@tfukaza tfukaza left a comment

Choose a reason for hiding this comment

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

Looks good on my end :)

@krashanoff
Copy link
Contributor Author

Thanks Tomo! Will be merging now then and moving on to prepping our first release.

@krashanoff krashanoff merged commit 7388432 into master Apr 7, 2020
@krashanoff krashanoff deleted the 1.14 branch April 7, 2020 03:27
@mizlan
Copy link
Member

mizlan commented Jun 18, 2023

This has been a long time coming, but we have it now. This PR makes the server get its Firebase credentials from the $TLACFG environment variable, and set its port from the $PORT variable.

@krashanoff Why is this a good thing? Doesn't it make it a bit more annoying to test when running go test? The README also specifies use of a credentials JSON file as opposed to an environment variable. Could this be because the environment variable is easier managed by dotenv-esque tooling?

@mizlan
Copy link
Member

mizlan commented Jun 18, 2023

Should there be a note that to run tests, this line must be ran first?

export TLACFG="$(cat credentials.json)"

@krashanoff
Copy link
Contributor Author

krashanoff commented Jun 18, 2023 via email

@mizlan
Copy link
Member

mizlan commented Jun 18, 2023

Gotcha! There's good news though: other maintainers (particularly Timothy to my knowledge) have been working on this exact issue. There is already an interface (TLADB) which db.DB and db.MockDB both implement. Would it better to have 100% of tests use the mock, or would a mix of both be good? (I suppose that having Firebase tests can be used to test the correctness our mock implementation, by comparing the two behaviors.)

Happy to answer other questions, but my contributions are over three years old now and have not crossed my mind in some time. Out of curiosity, what has got you looking into these old changes?

I'm the new maintainer, as Timothy, the previous maintainer, has graduated! This past quarter I've been familiarizing myself with the frontend codebase, but now that I have a pretty good mental model of everything going on in it, I thought I'd dig into the backend code too.

My plans for the near(ish) future are:

  • fully migrate the functions that interact with the database from db/ to handler/ to allow for a mock to be used in place (since handler/ functions works with TLADBs while db/ functions work with db.DBs).
    • add some abstraction for supporting transactions
  • finish a viable implementation of classes

@krashanoff
Copy link
Contributor Author

krashanoff commented Jun 19, 2023 via email

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.

3 participants