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

[risk=no] Refactor docker-compose to leverage anchors #3658

Merged
merged 2 commits into from Jun 11, 2020

Conversation

calbach
Copy link
Contributor

@calbach calbach commented Jun 10, 2020

Behavioral change:

  • In a few cases, this adds the GOOGLE_APPLICATION_CREDENTIALS. Based on manual testing of commands, this looks like it had no effect, so I'll prefer just making the configs consistent.
  • Remove some unused services: mysql-cloud, cloud-sql-proxy. @freemabd in case you're aware of some reason we still need these

Manually tested:

  • Ran ./project.rb commands with coverage of the various docker-compose services

Future work:

  • Several of these services are redundant and could be further merged / removed

Copy link
Contributor

@jaycarlton jaycarlton left a comment

Choose a reason for hiding this comment

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

Maybe comment on what the test plan/process was a bit.

I'd also really like to see (or I can do this too) a description associated with each runnable arg. I didn't see a way to do this in the docs yet (e.g. for printing tasks a la gradle), but we could use a fake tag like x-aou-description, or just a comment I guess.

@@ -1,16 +1,22 @@
version: "3"
version: "3.4"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the version change necessary for the other changes? If not, it might be nice to test that independently before or after.

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's needed to have an x- property that docker-compose doesn't complain about. I will add a comment about that below. It's a minor version upgrade, and this file is only applicable to local command lines, so I don't think it adds much value to split out a PR for this.

@@ -1,16 +1,22 @@
version: "3"
version: "3.4"
x-api-defaults: &api-defaults
Copy link
Contributor

Choose a reason for hiding this comment

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

I've started to use workbench-api instead of api for clarity, as pretty much everything has an api.

Also, it sounds like this anchor is more generic than just API tasks, so maybe there's a more generic name. Not a huge deal, but it can be difficult to get your bearings here if you haven't used docker-compose much.

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 should be pretty contextually obvious in this case and it's symmetric to the directory name, I don't think the increased verbosity is worth it.

- ~/.config:/.config:cached
- ~/.gsutil:/.gsutil:cached
command: |
cloud_sql_proxy
Copy link
Contributor

Choose a reason for hiding this comment

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

I do use cloud_sql_proxy locally with the, but I've never done so from docker-compose. @freemabd set me up with a named account on the test db, and I've been doing the same command locally to connect to it in IntelliJ:

./cloud_sql_proxy -instances all-of-us-workbench-test:us-central1:workbenchmaindb=tcp:0.0.0.0:3307 -credential_file=/Users/jaycarlton/repos/workbench/api/sa-key.json

Of course, as written this wouldn't work locally, unless I want to mount /w.

Copy link
Collaborator

@freemabd freemabd Jun 11, 2020

Choose a reason for hiding this comment

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

I also use cloud_sql_proxy to connect to test mysql db when using sequelPro/intellij

- gradle-cache:/.gradle
- ~/.config:/.config:cached
- ~/.gsutil:/.gsutil:cached
<<: *api-defaults
db:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we name this workbench_app_db instead, since we're a multi-db project? I feel like we're starting to need a distinct name for the MySQL DB, like "Workbench Backend DB" or "Application DB". Though maybe it's obvious that we're not launching BQ databases inside Docker.

I suppose that would break compatibility and require doc updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's only one database here, and it feels like a pretty big stretch to think this could be referring to BigQuery. Is there a specific use case you are concerned about? Just reading this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. Just seems like a database should have a name other than database. The confusion isn't so much with this file or even with developers, but when discussing application components with product folks or other stakeholders.

user: ${UID}
working_dir: /w/api
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/w/api/sa-key.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we simply include this line in the envs file?

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 doesn't relate to the database, so I don't think that would be correct. It also refers to a specific mounted path within the docker container.

working_dir: /w/api/db
volumes:
- src-sync:/w:nocopy
- gradle-cache:/.gradle
entrypoint: ['with-uid.sh', 'wait-for-it', 'db:3306', '-t', '30', --]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe parameterize the port number and timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above comment. Also the port is fine, but the timeout is a constant. Creating knobs for things that don't need to change generally just adds noise. If the intent was to avoid duplication with the other services here, see the PR description: my preference is to just eliminate the services with duplicate functionality. If there's a legitimate need for multiple services with this entrypoint, using an anchor can also work to avoid double-encoding of this.

environment:
- GOOGLE_APPLICATION_CREDENTIALS=/w/api/sa-key.json
env_file:
- db/vars.env
ports:
- 127.0.0.1:8081:8081
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe make a named constant for the two different port numbers 8081 and 8001. If order is arbitrary, maybe list them alphabetically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the way to do this in docker-compose would be to push the ports into a .env file. local constants/variables don't seem to be possible in docker-compose, except maybe by further abusing anchors.

AFAICT the suggestion isn't really related to the PR, so I don't intend to make a non-trivial change like that here.

@@ -20,165 +26,52 @@ services:
ports:
- 127.0.0.1:3306:3306
api:
<<: *api-defaults
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 a bit surprised you need to use an anchor. I would've expected docker-compose to have a high-level concept for this kind of reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, they used to have inheritance in docker-compose 2 which I initially tried to use here, but apparently they removed in v3. See moby/moby#31101

@calbach
Copy link
Contributor Author

calbach commented Jun 11, 2020

Puppeteer e2e is broken due to https://precisionmedicineinitiative.atlassian.net/browse/RW-5080 . Merging

@calbach calbach merged commit 6ffa0b4 into master Jun 11, 2020
@calbach calbach deleted the ch/compose-anchors branch June 11, 2020 22:17
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.

None yet

3 participants