Skip to content

Commit

Permalink
Problem: testground image not pushed to registry (#1479)
Browse files Browse the repository at this point in the history
* Problem: testground image not pushed to registry

Solution:
- build the current version of the image in root flake
- push to github container registry

* fix entrypoint

* check image validity

* cleanup

* test image
  • Loading branch information
yihuang authored Jun 20, 2024
1 parent 54ae5cf commit 903b590
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 171 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Push Testground Image

on:
push:
branches:
- main
tags:
- "v*.*.*"

env:
IMAGE_NAME: cronos-testground

jobs:

push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=channel:nixos-24.05
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v12
with:
name: cronos
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: build and push image
run: |
# login to ghcr.io
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
echo "VERSION: $VERSION"
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo "IMAGE_ID: $IMAGE_ID"
BUILD_TAG="$(nix eval --raw .#testground-image.imageTag)"
echo "BUILD_TAG: $BUILD_TAG"
docker load -i "$(nix build --no-link --print-out-paths .#testground-image)"
docker run --rm -e TEST_CASE=info $IMAGE_NAME:$BUILD_TAG
docker tag $IMAGE_NAME:$BUILD_TAG $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
in
rec {
packages = pkgs.cronos-matrix // {
inherit (pkgs) rocksdb;
inherit (pkgs) rocksdb testground-image;
};
apps = {
cronosd = mkApp packages.cronosd;
Expand Down Expand Up @@ -72,12 +72,14 @@
(import ./nix/build_overlay.nix)
poetry2nix.overlays.default
gomod2nix.overlays.default
(import ./testground/benchmark/overlay.nix)
(final: super: {
go = super.go_1_22;
test-env = final.callPackage ./nix/testenv.nix { };
cronos-matrix = final.callPackage ./nix/cronos-matrix.nix {
bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { };
};
testground-image = final.callPackage ./nix/testground-image.nix { };
})
];
};
Expand Down
15 changes: 15 additions & 0 deletions nix/testground-image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ dockerTools, cronos-matrix, testground-testcase }:
dockerTools.buildLayeredImage {
name = "cronos-testground";
contents = [
testground-testcase
cronos-matrix.cronosd
];
config = {
Expose = [ 9090 26657 26656 1317 26658 26660 26659 30000 ];
Cmd = [ "/bin/testground-testcase" ];
Env = [
"PYTHONUNBUFFERED=1"
];
};
}
11 changes: 9 additions & 2 deletions testground/benchmark/benchmark/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def __init__(self, params: RunParams = None):
if params is None:
params = run_params()
self.params = params
self.sync = SyncService(params)
self._sync = None

@property
def sync(self) -> SyncService:
if self._sync is None:
self._sync = SyncService(self.params)
return self._sync

def init_common(self):
self.wait_network_ready()
Expand Down Expand Up @@ -107,4 +113,5 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.sync.close()
if self._sync is not None:
self._sync.close()
8 changes: 8 additions & 0 deletions testground/benchmark/benchmark/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ def entrypoint(ctx: Context):
ctx.record_success()


def info(ctx: Context):
"""
Print the runtime configuration, mainly to check if the image is built successfully.
"""
print(ctx.params)


TEST_CASES = {
"entrypoint": entrypoint,
"info": info,
}


Expand Down
145 changes: 15 additions & 130 deletions testground/benchmark/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 903b590

Please sign in to comment.