Repository navigation
feat(nix): publish and install supautils in site profile
#2424
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
brainrake
wants to merge
31
commits into
develop
Choose a base branch
from
martonboros/mpg-12-site-env-update
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−3
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
8e52753
feat(nix): add the site profile with supautils
brainrake 3df19f7
Merge branch 'develop' into martonboros/mpg-12-site-env-update
brainrake 6eb13a7
refactor(nix): drop generation pruning and gc from activate
brainrake c43dedf
docs(nix): describe activate by what it sets up
brainrake 1be6fac
test(nix): run site-nix-gc to the end, restore ami release paths
brainrake 99a9903
feat(nix): prune old profile generations in site-nix-gc
brainrake 78b45e8
Merge branch 'develop' into martonboros/mpg-12-site-env-update
brainrake 6fefb9c
refactor(nix): scope the site profile library path to lib/postgresql
brainrake 33a3d3f
refactor(nix): assume nix is on PATH in site-nix-gc
brainrake 37d8f9f
refactor(nix): run site scripts on the host bash to shrink the closure
brainrake b4d3087
refactor(nix): drop the per-path deletion log from site-nix-gc
brainrake d2777fb
Merge branch 'develop' into martonboros/mpg-12-site-env-update
brainrake 13be08f
fix(nix): define the site check on linux only
brainrake 8039363
refactor(nix): move the site test to its own file
brainrake 829282f
feat(ami): pass the site-env store path to ansible
brainrake 5e18459
docs(nix): describe the site profile update and its failure modes
brainrake dd8cb67
fix(nix): run the site gc to completion and without systemd
brainrake 0c5a273
fix(nix): keep one old site profile generation
brainrake d662fb8
docs(nix): document site profile rollback and the activate rules
brainrake d318635
refactor(nix): simplify site-nix-gc and check supautils comes from th…
brainrake 3862ee0
refactor(nix): move site-nix-gc to a follow-up
brainrake 477425c
fix(ci): publish the site-env path to the shared catalog bucket
brainrake d493f67
refactor(nix): inline the activate script builder
brainrake 9662914
feat(nix): show the configured library settings in activate
brainrake 2b68738
refactor(ci): lay out the site-env catalog by system and name
brainrake ddc901b
Merge branch 'develop' into martonboros/mpg-12-site-env-update
brainrake 3cb7397
Update .github/workflows/ami-release-nix.yml
brainrake a01b76b
Merge remote-tracking branch 'origin/develop' into mpg12-squashed
brainrake 3a08642
fix(ci): write the site-env latest pointer in the sha-first layout
brainrake 29e4bef
refactor(ansible): install and activate the site env in one task
brainrake b24bc8c
docs(nix): trim the site profile docs
brainrake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -695,7 +695,7 @@ jit_provider = 'llvmjit' # JIT library to use | |
|
|
||
| # - Other Defaults - | ||
|
|
||
| #dynamic_library_path = '$libdir' | ||
| dynamic_library_path = '/nix/var/nix/profiles/site/lib/postgresql:$libdir' | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Load supautils from site profile. Safe migration story:
|
||
| #gin_fuzzy_search_limit = 0 | ||
|
|
||
| #------------------------------------------------------------------------------ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Site profile | ||
|
|
||
| The `site-env-15`, `site-env-17`, and `site-env-orioledb-17` package sets are deployed to `/nix/var/nix/profiles/site`. They hold supautils, and `activate`. | ||
|
|
||
| ## Publish | ||
|
|
||
| `ami-release-nix.yml` uploads each store path as a string to the shared artifacts bucket, in the object `nix-catalog/<sha>/<system>/site-env-<major>`. Release branches also upload the git sha as a string to `nix-catalog/latest/<system>/site-env-<major>`. The AMI bake installs the store path passed in as `site_env_path` and runs `activate`. | ||
|
|
||
| ## Update | ||
|
|
||
| ```sh | ||
| nix-env --profile /nix/var/nix/profiles/site --set <store path> | ||
| /nix/var/nix/profiles/site/bin/activate | ||
| ``` | ||
|
|
||
| `--set` downloads the closure from the binary cache if it is missing. It then creates the generation link `site-<N>-link` to the store path and repoints the `site` symlink at that link. If it fails, `nix-env` exits with 1 and the profile is unchanged. This holds when the path can't be fetched, isn't a store path, or the profile directory isn't writable. | ||
|
|
||
| `activate` runs after the switch. It prints the library settings configured in `postgresql.conf`, and is idempotent. If it fails, the new generation stays active. Run `activate` again, or roll back. | ||
|
|
||
| New sessions load supautils from the new profile. Open sessions keep the copy they loaded until they reconnect. Postgres does not restart. A restart applies the change to every session at once. The same holds after a rollback. | ||
|
|
||
| ## Roll back | ||
|
|
||
| ```sh | ||
| nix-env --profile /nix/var/nix/profiles/site --rollback | ||
|
brainrake marked this conversation as resolved.
|
||
| /nix/var/nix/profiles/site/bin/activate | ||
| ``` | ||
|
|
||
| Rollback switches to the previous generation. `activate` then runs from that generation and makes the machine match it. There is no separate rollback script. | ||
|
|
||
| To go further back than the previous generation, install an older version by path. | ||
|
|
||
| ## Install any version by path | ||
|
|
||
| ```sh | ||
| nix-env --profile /nix/var/nix/profiles/site --set <older store path> | ||
| /nix/var/nix/profiles/site/bin/activate | ||
| ``` | ||
|
|
||
| This is the way to roll back past the one kept generation. It is the same as an update with an older path. | ||
|
|
||
| ## `activate` safety | ||
|
|
||
| `activate` must be idempotent, and the previous generation's `activate` must be able to converge the machine back. Safety shall be ensured by comparing snapshots in tests before and after an update and a rollback. | ||
|
|
||
| ## Test | ||
|
|
||
| ```sh | ||
| nix build .#checks.<system>.site -L | ||
| ``` | ||
|
|
||
| The `site` VM test covers loading supautils from the site profile, the `$libdir` fallthrough, and `activate`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| { self, pkgs }: | ||
| let | ||
| system = pkgs.pkgsLinux.stdenv.hostPlatform.system; | ||
| site-env-17 = self.packages.${system}."site-env-17"; | ||
| psql_17 = self.legacyPackages.${system}."psql_17".bin; | ||
| psql_17_slim = self.legacyPackages.${system}."psql_17_slim".bin; | ||
| pgConf = pkgs.writeText "postgresql-test.conf" '' | ||
| dynamic_library_path = '/nix/var/nix/profiles/site/lib/postgresql:$libdir' | ||
| session_preload_libraries = 'supautils' | ||
| unix_socket_directories = '/tmp' | ||
| ''; | ||
| in | ||
| pkgs.testers.runNixOSTest { | ||
| name = "site"; | ||
| nodes.machine = | ||
| { ... }: | ||
| { | ||
| environment.systemPackages = [ site-env-17 ]; | ||
| virtualisation.additionalPaths = [ psql_17 ]; | ||
| users.users.postgres = { | ||
| isSystemUser = true; | ||
| group = "postgres"; | ||
| shell = pkgs.bash; | ||
| }; | ||
| users.groups.postgres = { }; | ||
| }; | ||
| testScript = '' | ||
| # site profile absent: supautils loads from $libdir | ||
| machine.succeed("install -d -o postgres -g postgres /tmp/pgdata-slim") | ||
| machine.succeed("su postgres -c '${psql_17_slim}/bin/initdb -D /tmp/pgdata-slim'") | ||
| machine.succeed("install -o postgres -g postgres ${pgConf} /tmp/pgdata-slim/postgresql.conf") | ||
| machine.succeed("su postgres -c '${psql_17_slim}/bin/pg_ctl -D /tmp/pgdata-slim -l /tmp/pg-slim.log start'") | ||
| machine.succeed("su postgres -c '${psql_17_slim}/bin/psql -h /tmp -d postgres -c \"select 1\"'") | ||
| machine.succeed("su postgres -c '${psql_17_slim}/bin/pg_ctl -D /tmp/pgdata-slim stop'") | ||
|
|
||
| machine.succeed("nix-env --profile /nix/var/nix/profiles/site --set ${site-env-17}") | ||
|
|
||
| # without $libdir in the path, supautils can only come from the site profile | ||
| machine.succeed("install -d -o postgres -g postgres /tmp/pgdata") | ||
| machine.succeed("su postgres -c '${psql_17}/bin/initdb -D /tmp/pgdata'") | ||
| machine.succeed("install -o postgres -g postgres ${pgConf} /tmp/pgdata/postgresql.conf") | ||
| machine.succeed("sed -i 's/:\\$libdir//' /tmp/pgdata/postgresql.conf") | ||
| machine.succeed("grep -qx \"dynamic_library_path = '/nix/var/nix/profiles/site/lib/postgresql'\" /tmp/pgdata/postgresql.conf") | ||
| machine.succeed("su postgres -c '${psql_17}/bin/pg_ctl -D /tmp/pgdata -l /tmp/pg.log start'") | ||
| machine.succeed("su postgres -c '${psql_17}/bin/psql -h /tmp -d postgres -c \"select 1\"'") | ||
| machine.succeed("su postgres -c '${psql_17}/bin/pg_ctl -D /tmp/pgdata stop'") | ||
|
|
||
| machine.succeed("${site-env-17}/bin/activate") | ||
| ''; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This publishes the output paths of the site-env package to public S3 bucket as simple strings in files. It is only used by a scheduled workflow that updates the pins. The pins are the /nix/store path strings themselves so S3 is not part of the update / download.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so this is why not using a json like the above catalog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Structured data is not needed here. Plain text is simpler and more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counterpoint: the structure is stringly typed in the file name.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code to publish and consume it does end up smaller and with fewer failure modes.