purescript / registry-dev

Development work related to the PureScript Registry
https://github.com/purescript/registry
97 stars 80 forks source link

Add Nix builds for the full registry #619

Closed thomashoneyman closed 1 year ago

thomashoneyman commented 1 year ago

Extends #618 by additionally providing:

What's the point of all this? In short:

Note that all packages in the registry can still be run locally. You don't have to use a VM. Things still work fine in the GitHub Actions environment.

You can run any of the existing scripts with their module name swapped to lower-cased, hyphenated attribute names. For example, Registry.Scripts.LegacyImporter:

nix run .#legacy-importer -- dry-run

Or the server (not in a virtual machine), assuming you have your env vars set up properly:

nix run .#server

You can deploy the server to a VM and run it on localhost:8080, and then load that in your browser or curl to the api endpoint:

nix run

You can still get into your Nix shell as usual:

nix develop
thomashoneyman commented 1 year ago

The latest commits add a full integration test using the local VM. That local module definition should also be sufficient to implement deployments to our Digital Ocean server, so I'll take care of that next. At that point all that's left to do is polish this up!

thomashoneyman commented 1 year ago

The latest commit supports deployments to the registry NixOS server on Digital Ocean — you can deploy with colmena apply. The first deployment takes forever because we build on the target machine, and I got an underpowered machine for testing, but subsequent deploys take 2-3 minutes or so if you change the PureScript source code.

Available right now here: http://161.35.111.85

For example:

$ curl 161.35.111.85/api/v1/jobs/0
TODO

Next I'll set up certificates and auto-deploys on commits to master when all the garnix checks complete successfully. At that point we're all set up for continuous deployments.

thomashoneyman commented 1 year ago

I've verified that we can deploy with Let's Encrypt and force secure connections, though with a bare IP address the certs are invalid. I've commented them out, but once we have an e.g. https://registry.purescript.org domain then we can enable it again.

thomashoneyman commented 1 year ago

Note: deployments are working from non-x86_64-linux systems because we're running the build on the server, not locally. However, you won't be able to run the integration test on a darwin system unless you're running a remote builder as per https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder

I'm going to assume no one is doing that so I'm going to disable the integration test for darwin systems. It will still run in CI, so you can still open a PR to run it. It will also be runnable on any Linux system.

f-f commented 1 year ago

This looks good - one last thing that we should take care of before merging is some kind of developer documentation, i.e. how to use all of this Nix machinery for folks that are not intimately familiar with Nix and/or with this specific setup.

You added some details in the PR description, but let's have a CONTRIBUTING.md file with instructions on how to run tests, deploy, etc.

thomashoneyman commented 1 year ago

Developer documentation is on the way in the next PR.