Skip to content

Commit

Permalink
fix(blockTypes): don't try to be too smart with kubctl & nomad rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jun 30, 2023
1 parent 53c435a commit f0a9a55
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/local/flake.lock

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

23 changes: 4 additions & 19 deletions src/std/fwlib/blockTypes/kubectl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,15 @@ in

render = ''
declare manifest_path="$PRJ_DATA_HOME/${manifest_path}"
_render() {
render() {
echo "Buiding manifests..."
echo
rm -rf "$manifest_path"
mkdir -p "$manifest_path"
ln -sf "${manifestsWithGitRevision target}" "$manifest_path"
echo
echo "Manifests built in: $manifest_path"
}
render() {
local mode="$1"
mkdir -p "$manifest_path"
if [[ "$mode" == "always" ]]
then
_render
elif [[ "$mode" == "current-revision" ]] \
&& [[ "$(jq -r '.metadata.labels.revision' "$(find "$manifest_path" | head -n1)")" != "$(git rev-parse --short HEAD)" ]]
then
_render
elif [[ "$mode" == "if-not-exists" ]] && [[ ! -d "$manifest_path" ]]
then
_render
fi
}
'';
in [
/*
Expand All @@ -89,12 +75,11 @@ in
*/
(mkCommand currentSystem "render" "Build the JSON manifests" [] ''
${render}
render always
render
'' {})
(mkCommand currentSystem "apply" "Apply the manifests to K8s" [pkgs.kubectl pkgs.jq] ''
${render}
render if-not-exists
render current-revision
render
diff() {
if ! [[ -v CI ]]; then
Expand Down
23 changes: 4 additions & 19 deletions src/std/fwlib/blockTypes/nomad.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,14 @@ in
builtins.toFile "${job_name}.json" (builtins.unsafeDiscardStringContext (builtins.toJSON {inherit job;}));
render = ''
declare job_path="$PRJ_DATA_HOME/${job_path}"
_render() {
render() {
echo "Rendering to $job_path..."
rm -rf "$job_path"
ln -sf "${jobWithGitRevision target}" "$job_path"
if status=$(nomad validate "$job_path"); then
echo "$status for $job_path"
fi
}
render() {
local mode="$1"
if [[ "$mode" == "always" ]]
then
_render
elif [[ "$mode" == "current-revision" ]] \
&& [[ "$(jq -r '.job[].meta.rev' "$job_path")" != "$(git rev-parse --short HEAD)" ]]
then
_render
elif [[ "$mode" == "if-not-exists" ]] && [[ ! -h "$job_path" ]]
then
_render
fi
}
'';
in [
/*
Expand All @@ -76,12 +62,11 @@ in
*/
(mkCommand currentSystem "render" "build the JSON job description" [pkgs.nomad] ''
${render}
render always
render
'' {})
(mkCommand currentSystem "deploy" "Deploy the job to Nomad" [pkgs.nomad pkgs.jq] ''
${render}
render if-not-exists
render current-revision
render
if ! plan_results=$(nomad plan -force-color "$job_path"); then
echo "$plan_results"
run() { echo "$plan_results" | grep 'nomad job run -check-index'; }
Expand All @@ -92,7 +77,7 @@ in
'' {})
(mkCommand currentSystem "explore" "interactively explore the Job defintion" [pkgs.nomad pkgs.fx] ''
${render}
render always
render
fx "$job_path"
'' {})
];
Expand Down
6 changes: 3 additions & 3 deletions src/tests/flake.lock

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

0 comments on commit f0a9a55

Please sign in to comment.