Skip to content

A shell script to run local server without wrapping it in Nix #700

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fsoikin
Copy link
Contributor

@fsoikin fsoikin commented Jun 8, 2025

No description provided.

@f-f f-f requested a review from thomashoneyman June 8, 2025 14:20
@thomashoneyman
Copy link
Member

I don’t love duplicating the Nix wiremock config into a local file too, and I’m hesitant to commit to maintaining it; I’d like it better if we use writeShellScriptBin into the flake to reuse the existing configs instead. I see the usefulness of not having to run in the qemu VM, of course. But if you need to merge it, that’s OK.

@fsoikin
Copy link
Contributor Author

fsoikin commented Jun 9, 2025

I don't have to merge it, I can just use my local copy, but I thought it might be useful to share the script.

As for the first part of your comment, I understood almost none of it due to not understanding Nix at all. I am currently sitting in a lecture on how Nix works, and my confidence is actually decreasing over time.

@fsoikin
Copy link
Contributor Author

fsoikin commented Jun 9, 2025

I'll see if I can extract the wiremock part of the Nix config so it can be run separately from everything else.

@thomashoneyman
Copy link
Member

I meant wrapping this test script in writeShellScriptBin, like:

registry-dev/flake.nix

Lines 264 to 276 in e7269e6

run-tests-script = pkgs.writeShellScriptBin "run-tests-script" ''
set -euo pipefail
WORKDIR=$(mktemp -d)
cp spago.yaml spago.lock $WORKDIR
cp -a app foreign lib scripts types $WORKDIR
ln -s ${pkgs.registry.package-lock}/js/node_modules $WORKDIR/node_modules
pushd $WORKDIR
export HEALTHCHECKS_URL=${defaultEnv.HEALTHCHECKS_URL}
${pkgs.spago-bin.spago-0_93_19}/bin/spago test
popd
'';

...and then instead of reimplementing the wiremock configs, you can import them directly into the script. You'd have to lift them out of the integration test to the top level first, but otherwise they can be unchanged.

This is assuming you want to run a local server with wiremock instances...the reason those instances all exist is for the sake of the integration test, which uses a NixOS environment that matches the one we deploy, and has deterministic outputs for things like Pursuit, git changes, and so on. You should be able to execute a command like this:

curl -X POST http://localhost:8080/api/v1/publish \
    -H "Content-Type: application/json" \
    -d '{
      "name": "effect",
      "ref": "v4.0.0",
      "compiler": "0.15.4",
      "location": {
        "githubOwner": "purescript",
        "githubRepo": "purescript-effect"
      }
    }'

What sort of testing are you looking to do? The registry has pretty robust tests that don't need this whole integration test setup. The integration tests are more of a last resort thing to run in CI with the exact operating system we deploy to DigitalOcean.

@thomashoneyman
Copy link
Member

If you aren't trying to run the integration test, and instead you just want to run the local server such that it can't perform writes, then you can replace the run implementations with no-ops (like what we do in the legacy importer when you provide the dry run flag).

-- Set up interpreters according to the import mode. In dry-run mode we don't
-- allow anyting to be committed or pushed, but data is still written to the
-- local repository checkouts on disk. In generate-registry mode, tarballs are
-- uploaded, but nothing is committed. In update-registry mode, tarballs are
-- uploaded and manifests and metadata are written, committed, and pushed.
runAppEffects <- do
debouncer <- Registry.newDebouncer
let registryEnv pull write = { pull, write, repos: Registry.defaultRepos, workdir: scratchDir, debouncer, cacheRef: registryCacheRef }
case mode of
DryRun -> do
token <- Env.lookupRequired Env.githubToken
octokit <- Octokit.newOctokit token resourceEnv.githubApiUrl
pure do
Registry.interpret (Registry.handle (registryEnv Git.Autostash Registry.ReadOnly))
>>> Storage.interpret (Storage.handleReadOnly cache)
>>> Pursuit.interpret Pursuit.handlePure
>>> Source.interpret Source.handle
>>> GitHub.interpret (GitHub.handle { octokit, cache, ref: githubCacheRef })

I expect this is the easier path to take rather than attempting to reuse the WireMock configs. Those are pretty specific for the integration test.

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