Skip to content

Commit

Permalink
release: publish emojivoto as yml instead of zip
Browse files Browse the repository at this point in the history
  • Loading branch information
davidweisse committed Jun 25, 2024
1 parent 07d9e96 commit 3b33645
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
working-directory: contrast-main
env:
VERSION: ${{ inputs.version }}
run: nix run .#scripts.update-contrast-releases
run: nix run ../contrast-working#scripts.update-contrast-releases
- name: Commit updated contrast-releases.json
working-directory: contrast-main
run: |
Expand Down Expand Up @@ -274,8 +274,7 @@ jobs:
mkdir -p workspace deployment
nix run .#scripts.write-coordinator-yaml -- "${coordinatorImgTagged}" > workspace/coordinator.yml
nix shell .#contrast --command resourcegen --image-replacements ./image-replacements.txt --namespace kube-system runtime > workspace/runtime.yml
nix shell .#contrast --command resourcegen --image-replacements ./image-replacements.txt --add-load-balancers emojivoto-sm-ingress > deployment/emojivoto-demo.yml
zip -r workspace/emojivoto-demo.zip deployment/emojivoto-demo.yml
nix shell .#contrast --command resourcegen --image-replacements ./image-replacements.txt --add-load-balancers emojivoto-sm-ingress > workspace/emojivoto-demo.yml
- name: Update coordinator policy hash
run: |
yq < workspace/coordinator.yml \
Expand Down Expand Up @@ -312,7 +311,7 @@ jobs:
result-cli/bin/contrast
workspace/coordinator.yml
workspace/runtime.yml
workspace/emojivoto-demo.zip
workspace/emojivoto-demo.yml
- name: Reset temporary changes
run: |
git reset --hard ${{ needs.process-inputs.outputs.WORKING_BRANCH }}
Expand Down
8 changes: 2 additions & 6 deletions e2e/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,9 @@ func TestRelease(t *testing.T) {

require.True(t, t.Run("unpack-deployment", func(t *testing.T) {
require := require.New(t)
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

cmd := exec.CommandContext(ctx, "unzip", "emojivoto-demo.zip")
cmd.Dir = dir
out, err := cmd.CombinedOutput()
require.NoError(err, "output:\n%s", string(out))
require.NoError(os.Mkdir(path.Join(dir, "deployment"), 0o777))
require.NoError(os.Rename(path.Join(dir, "emojivoto-demo.yml"), path.Join(dir, "deployment", "emojivoto-demo.yml")))

infos, err := os.ReadDir(path.Join(dir, "deployment"))
require.NoError(err)
Expand Down
17 changes: 14 additions & 3 deletions packages/contrast-releases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ let
passthru.exists = (builtins.compareVersions "v0.6.0" version) <= 0;
};

emojivoto = fetchurl {
emojivoto-zip = fetchurl {
# fetchurl instead of fetchzip since the hashes in contrast-release.json are computed from the zip file
inherit version;
url = "https://github.com/edgelesssys/contrast/releases/download/${version}/emojivoto-demo.zip";
inherit (findVersion json."emojivoto-demo.zip" version) hash;
# emojivoto-demo.zip was introduced in version v0.5.0
passthru.exists = (builtins.compareVersions "v0.5.0" version) <= 0;
passthru.exists = (builtins.compareVersions "v0.5.0" version) <= 0 && (builtins.compareVersions version "v0.8.0") < 0;
};

emojivoto = fetchurl {
inherit version;
url = "https://github.com/edgelesssys/contrast/releases/download/${version}/emojivoto-demo.yml";
inherit (findVersion json."emojivoto-demo.yml" version) hash;
# emojivoto-demo.yml was changed from zip to yml in version v0.8.0
passthru.exists = (builtins.compareVersions "v0.8.0" version) <= 0;
};
in
runCommand version
Expand All @@ -49,12 +57,15 @@ let
}
(''
mkdir -p $out/bin
mkdir -p $out/deployment
install -m 777 ${cli} $out/bin/contrast
install -m 644 ${coordinator} $out/coordinator.yml
'' + lib.optionalString runtime.exists ''
install -m 644 ${runtime} $out/runtime.yml
'' + lib.optionalString emojivoto-zip.exists ''
unzip ${emojivoto-zip} -d $out
'' + lib.optionalString emojivoto.exists ''
unzip ${emojivoto} -d $out
install -m 644 ${emojivoto} $out/deployment/emojivoto-demo.yml
'');
};
releases = builtins.listToAttrs (builtins.map buildContrastRelease json.contrast);
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
update-contrast-releases = writeShellApplication {
name = "update-contrast-releases";
runtimeInputs = with pkgs; [
jq
yq-go
];
text = builtins.readFile ./update-contrast-releases.sh;
};
Expand Down
31 changes: 13 additions & 18 deletions packages/update-contrast-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,35 @@ fields["contrast"]="./result-cli/bin/contrast"
fields["coordinator.yml"]="./workspace/coordinator.yml"
fields["runtime.yml"]="./workspace/runtime.yml"
fields["emojivoto-demo.zip"]="./workspace/emojivoto-demo.zip"
fields["emojivoto-demo.yml"]="./workspace/emojivoto-demo.yml"

for field in "${!fields[@]}"; do
# check if any field contains the given version
out=$(
jq --arg NAME "$field" \
--arg VERSION "$VERSION" \
'.[$NAME] | map(select(.version == $VERSION))' \
"${versionsFile}"
)
# get the file path
file=${fields["$field"]}

# skip files which are not included in current release
if [[ ! -f $file ]]; then
echo "skipping $file"
continue
fi

out=$(yq ".[\"$field\"] | map(select(.version == \"$VERSION\"))" "${versionsFile}")
if [[ $out != "[]" ]]; then
echo "[x] Error: version $VERSION exists for entry $field" >&2
exit 1
fi

# get the file path
file=${fields["$field"]}

echo "[*] Creating hash for $file" >&2
hash=$(nix hash file --sri --type sha256 "$(realpath "$file")")
echo " $hash" >&2

echo "[*] Updating ${versionsFile} for $field" >&2
out=$(
jq --arg NAME "$field" \
--arg HASH "$hash" \
--arg VERSION "$VERSION" \
'.[$NAME] |= . + [{"version": $VERSION,hash: $HASH}]' \
"${versionsFile}"
)
out=$(yq ".[\"$field\"] |= . + [{\"version\": \"$VERSION\", \"hash\": \"$hash\"}]" "${versionsFile}")
echo "$out" >"${versionsFile}"

echo ""
done

echo "[*] Formatting ${versionsFile}"
out=$(jq --indent 2 . "${versionsFile}")
out=$(yq --indent 2 'sort_keys(.)' "${versionsFile}")
echo "$out" >"${versionsFile}"

0 comments on commit 3b33645

Please sign in to comment.