-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(back): #1351 deploy container manifest
- Add builtin - Add documentation Signed-off-by: Daniel Salazar <[email protected]>
- Loading branch information
Showing
6 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,16 @@ | ||
{ __nixpkgs__, makeScript, toFileYaml, ... }: | ||
{ config, credentials, name, setup, sign }: | ||
makeScript { | ||
replace = { | ||
__argConfig__ = toFileYaml "manifest.yaml " config; | ||
__argCredentialsToken__ = credentials.token; | ||
__argCredentialsUser__ = credentials.user; | ||
__argSign__ = sign; | ||
}; | ||
entrypoint = ./entrypoint.sh; | ||
inherit name; | ||
searchPaths = { | ||
bin = [ __nixpkgs__.cosign __nixpkgs__.manifest-tool __nixpkgs__.yq ]; | ||
source = setup; | ||
}; | ||
} |
This file contains 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,45 @@ | ||
# shellcheck shell=bash | ||
|
||
function deploy { | ||
local config="${1}" | ||
local credentials_token="${2}" | ||
local credentials_user="${3}" | ||
|
||
: && info "Deploying container manifest: ${config}" \ | ||
&& manifest-tool \ | ||
--password "${credentials_token}" \ | ||
--username "${credentials_user}" \ | ||
push from-spec "${config}" | ||
} | ||
|
||
function sign { | ||
local sign="${1}" | ||
local config="${2}" | ||
local credentials_token="${3}" | ||
local credentials_user="${4}" | ||
local image | ||
|
||
if [ "${sign}" = "1" ]; then | ||
: && info "Signing container manifest" \ | ||
&& image="$(yq -rec '.image' "${config}")" \ | ||
&& cosign sign \ | ||
--yes=true \ | ||
--registry-username="${credentials_user}" \ | ||
--registry-password="${credentials_token}" \ | ||
"${image}" | ||
else | ||
: && info "Skipping signing container manifest" | ||
fi | ||
} | ||
|
||
function main { | ||
local config="__argConfig__" | ||
local credentials_token="${__argCredentialsToken__}" | ||
local credentials_user="${__argCredentialsUser__}" | ||
local sign="__argSign__" | ||
|
||
: && deploy "${config}" "${credentials_token}" "${credentials_user}" \ | ||
&& sign "${sign}" "${config}" "${credentials_token}" "${credentials_user}" | ||
} | ||
|
||
main "${@}" |
This file contains 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
60 changes: 60 additions & 0 deletions
60
src/evaluator/modules/deploy-container-manifest/default.nix
This file contains 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,60 @@ | ||
{ __toModuleOutputs__, deployContainerManifest, ... }: | ||
{ config, lib, ... }: | ||
let | ||
makeOutput = name: args: { | ||
name = "/deployContainerManifest/${name}"; | ||
value = deployContainerManifest { | ||
inherit (args) config; | ||
inherit (args) credentials; | ||
inherit name; | ||
inherit (args) setup; | ||
inherit (args) sign; | ||
}; | ||
}; | ||
|
||
manifestType = lib.types.submodule (_: { | ||
options = { | ||
image = lib.mkOption { type = lib.types.str; }; | ||
platform = { | ||
architecture = lib.mkOption { type = lib.types.str; }; | ||
os = lib.mkOption { type = lib.types.str; }; | ||
}; | ||
}; | ||
}); | ||
configType = lib.types.submodule (_: { | ||
options = { | ||
image = lib.mkOption { type = lib.types.str; }; | ||
tags = lib.mkOption { type = lib.types.listOf lib.types.str; }; | ||
manifests = lib.mkOption { type = lib.types.listOf manifestType; }; | ||
}; | ||
}); | ||
credentialsType = lib.types.submodule (_: { | ||
options = { | ||
token = lib.mkOption { type = lib.types.str; }; | ||
user = lib.mkOption { type = lib.types.str; }; | ||
}; | ||
}); | ||
in { | ||
options = { | ||
deployContainerManifest = lib.mkOption { | ||
default = { }; | ||
type = lib.types.attrsOf (lib.types.submodule (_: { | ||
options = { | ||
config = lib.mkOption { type = configType; }; | ||
credentials = lib.mkOption { type = credentialsType; }; | ||
setup = lib.mkOption { | ||
default = [ ]; | ||
type = lib.types.listOf lib.types.package; | ||
}; | ||
sign = lib.mkOption { | ||
default = false; | ||
type = lib.types.bool; | ||
}; | ||
}; | ||
})); | ||
}; | ||
}; | ||
config = { | ||
outputs = __toModuleOutputs__ makeOutput config.deployContainerManifest; | ||
}; | ||
} |