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

docs(example): add share-services #137

Merged
merged 23 commits into from
Mar 11, 2024
Merged

docs(example): add share-services #137

merged 23 commits into from
Mar 11, 2024

Conversation

shivaraj-bh
Copy link
Member

@shivaraj-bh shivaraj-bh commented Mar 9, 2024

Run services:

nix run "github:juspay/services-flake/share-services?dir=example/share-services"

Run integration-test:

nix run "github:juspay/services-flake/share-services?dir=example/share-services"#integration-test

@shivaraj-bh shivaraj-bh requested a review from srid March 9, 2024 09:07
Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

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

feat(example) or docs(example)? Because this PR doesn't add new features to services-flake.

So this share-services example is more of demonstration of how the process-compose-flake module system can be used to share services, right? I wonder if we can improve it in a couple of ways:

  1. Have two separate flakes -- share-services/common, share-services/foo -- where foo imports services from common. The integration test can just remain in foo. I think this is more clear (re: structure) to the user. In fact, we might as well add a bar flake that imports common again.
  2. Instead of running empty pg1 and r1, what if we had something equally demo-worthy as example/simple (which shows pgweb)?

@srid
Copy link
Member

srid commented Mar 9, 2024

2. Instead of running empty pg1 and r1, what if we had something equally demo-worthy as example/simple (which shows pgweb)?

Perhaps we can just clone example/simple and refactor it. Viz., put the northwind db service in example/share-services/database/flake.nix:

services.postgres."pg1" = {
enable = true;
listen_addresses = "127.0.0.1";
initialDatabases = [
{
name = dbName;
schemas = [ "${inputs.northwind}/northwind.sql" ];
}
];
};

And then use it, for running pgweb, from example/share-services/frontend/flake.nix:

settings.processes.pgweb =
let
pgcfg = config.services.postgres.pg1;
in
{
environment.PGWEB_DATABASE_URL = "postgres://$USER@${pgcfg.listen_addresses}:${builtins.toString pgcfg.port}/${dbName}";
command = pkgs.pgweb;
depends_on."pg1".condition = "process_healthy";
};

? That's one idea.

Interestingly, in future we can create another example to demonstrate creation of new services, by refactoring this pgweb into its own service (services.pgweb.pgservice = config.services.postgres.pg1).

This example comprises of two flakes:
1. databases: defining the two postgres services
2. frontend: reusing the postgres services from `databases` to start `pgweb` and provide a visual DB editor.
@shivaraj-bh shivaraj-bh changed the title feat(example): add share-services docs(example): add share-services Mar 11, 2024
@shivaraj-bh
Copy link
Member Author

@srid I have so far implemented this. Although, I am not super pleased with the way services.nix is being used between databases and frontend, any suggestions?

@srid
Copy link
Member

srid commented Mar 11, 2024

any suggestions?

I'll take a look. I just added a justfile command to run the new example, and I noticed this despite the sockerDir option:

image

Bug somewhere?

@shivaraj-bh
Copy link
Member Author

Its not a bug, data will still remain in pwd, only the socket will be created elsewhere. Hence, the options, dataDir and socketDir are different.

Comment on lines 12 to 13
# Required due to socket length being limited to 100 chars, see: https://github.com/juspay/services-flake/pull/77
socketDir = "$HOME/.services/postgres/pg1";
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this break if running two test builds in parallel?

Also: #139 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

It will, yes! It should probably depend on a tmp path, rather than a pre-defined one. Gotta think about this one.

@shivaraj-bh
Copy link
Member Author

Also, if we move the northwind DB to share-services example, would it make sense to have a much simpler example in simple?

@srid
Copy link
Member

srid commented Mar 11, 2024

Also, if we move the northwind DB to share-services example, would it make sense to have a much simpler example in simple?

Simple, as in ?

@srid

This comment was marked as resolved.

@srid
Copy link
Member

srid commented Mar 11, 2024

n/m - that's just old code in the PR.

@shivaraj-bh
Copy link
Member Author

shivaraj-bh commented Mar 11, 2024

Also, if we move the northwind DB to share-services example, would it make sense to have a much simpler example in simple?

Simple, as in ?

n/m, I was thinking of just having

services.postgres.pg.enable = true;
services.redis.r1.enable = true;

But such simple cases are anyways covered in the "Getting started" section of the service documentation.

@srid
Copy link
Member

srid commented Mar 11, 2024

Good enough, we can always improve our examples later, and add more of them. I'll merge, and flip the branch name in main.

@srid srid merged commit 51ecb71 into main Mar 11, 2024
4 checks passed
@srid srid deleted the share-services branch March 11, 2024 18:05
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.

2 participants