Skip to content

Commit

Permalink
Problem: upgrade test nix package is incorrect (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang authored Apr 9, 2024
1 parent 58ce7f4 commit 073c37e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@
go = super.go_1_22;
test-env = final.callPackage ./nix/testenv.nix { };
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = drv: final.runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with final.buildPackages; [ gnutar gzip ];
} ''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
'';
bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { cronosd = drv; };
} // (with final;
let
Expand Down
11 changes: 5 additions & 6 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ let
# v1.1.1
released = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
current = pkgs.callPackage ../../. { };
farm = pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis/bin"; path = "${released0}/bin"; }
{ name = "v1.1.0/bin"; path = "${released}/bin"; }
{ name = "v1.2/bin"; path = "${current}/bin"; }
];
in
pkgs.make-tarball farm
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released0; }
{ name = "v1.1.0"; path = released; }
{ name = "v1.2"; path = current; }
]
30 changes: 13 additions & 17 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import shutil
import stat
import subprocess
from contextlib import contextmanager
from datetime import datetime, timedelta
Expand Down Expand Up @@ -72,35 +74,29 @@ def setup_cronos_test(tmp_path_factory):
port = 26200
nix_name = "upgrade-test-package"
cfg_name = "cosmovisor"
configdir = Path(__file__).parent
cmd = [
"nix-build",
Path(__file__).parent / f"configs/{nix_name}.nix",
"-o",
path / "upgrades.tar.gz",
configdir / f"configs/{nix_name}.nix",
]
print(*cmd)
subprocess.run(cmd, check=True)

# extract the tarball so the directory is writable.
(path / "upgrades").mkdir()
subprocess.run(
[
"tar",
"xfz",
path / "upgrades.tar.gz",
"-C",
path / "upgrades",
],
check=True,
)
# copy the content so the new directory is writable.
upgrades = path / "upgrades"
shutil.copytree("./result", upgrades)
mod = stat.S_IRWXU
upgrades.chmod(mod)
for d in upgrades.iterdir():
d.chmod(mod)

# init with genesis binary
with contextmanager(setup_custom_cronos)(
path,
port,
Path(__file__).parent / f"configs/{cfg_name}.jsonnet",
configdir / f"configs/{cfg_name}.jsonnet",
post_init=post_init,
chain_binary=str(path / "upgrades/genesis/bin/cronosd"),
chain_binary=str(upgrades / "genesis/bin/cronosd"),
) as cronos:
yield cronos

Expand Down
17 changes: 0 additions & 17 deletions nix/build_overlay.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
# some basic overlays nessesary for the build
final: super: {
rocksdb = final.callPackage ./rocksdb.nix { };

# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = final.callPackage
({ buildPackages
, runCommand
}: drv: runCommand "tarball-${drv.name}"
{
nativeBuildInputs = with buildPackages; [ gnutar gzip ];
}
''
tar cfv - -C "${drv}" \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| gzip -9 > $out
''
)
{ };
}

0 comments on commit 073c37e

Please sign in to comment.