Skip to content

Commit d75f19f

Browse files
committed
just: inject imagepuller config
1 parent 604a681 commit d75f19f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

justfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ populate target=default_deploy_target platform=default_platform:
103103
if [[ -f ./{{ workspace_dir }}/deployment/deployment.yml ]]; then
104104
echo "---" >> ./{{ workspace_dir }}/deployment/deployment.yml
105105
fi
106+
if [ -n "$CONTRAST_GHCR_READ" ]; then
107+
cat > "./{{ workspace_dir }}/contrast-imagepuller.toml" <<EOF
108+
[registries]
109+
[registries."ghcr.io."]
110+
auth = "$(printf "user-not-required-here:%s" "$CONTRAST_GHCR_READ" | base64 -w0)"
111+
EOF
112+
kubectl create secret generic contrast-node-installer-imagepuller-config \
113+
--from-file "contrast-imagepuller.toml"="./{{ workspace_dir }}/contrast-imagepuller.toml"
114+
--namespace {{ target }}${namespace_suffix-} \
115+
fi
106116
dmesgFlag=""
107117
# For debug, we already add the debugshell container which exposes the full journal.
108118
if [[ "${debug:-}" != "true" ]]; then
@@ -335,12 +345,20 @@ get-credentials platform=default_platform:
335345
;;
336346
esac
337347

348+
token=$(nix run -L .#scripts.get-read-token "projects/796962942582/secrets/ghcr-read-token/versions/latest")
349+
sed -i "s/^CONTRAST_GHCR_READ=.*/CONTRAST_GHCR_READ=\"${token}\"/" justfile.env
350+
338351
# Load the kubeconfig from the dev cluster.
339352
get-credentials-dev:
353+
#!/usr/bin/env bash
354+
set -euo pipefail
340355
nix run -L .#scripts.get-credentials "projects/796962942582/secrets/hetzner-ax162-snp-kubeconfig/versions/latest"
341356
sed -i 's/^default_platform=.*/default_platform="Metal-QEMU-SNP"/' justfile.env
342357
sed -i 's/^node_installer_target_conf_type=.*/node_installer_target_conf_type="k3s"/' justfile.env
343358

359+
token=$(nix run -L .#scripts.get-read-token "projects/796962942582/secrets/ghcr-read-token/versions/latest")
360+
sed -i "s/^CONTRAST_GHCR_READ=.*/CONTRAST_GHCR_READ=\"${token}\"/" justfile.env
361+
344362
# Run code generators.
345363
codegen:
346364
nix run -L .#scripts.generate
@@ -395,6 +413,8 @@ namespace_suffix=""
395413
CONTRAST_CACHE_DIR="./workspace.cache"
396414
# Log level for the CLI.
397415
CONTRAST_LOG_LEVEL=""
416+
# A Github token with read access to Contrast's ghcr.io packages.
417+
CONTRAST_GHCR_READ=""
398418
'''
399419

400420
# Developer onboarding.

packages/scripts.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ lib.makeScope pkgs.newScope (scripts: {
381381

382382
# Usage: get-credentials $gcloudSecretRef
383383
get-credentials = writeShellApplication {
384-
name = "extract-policies";
384+
name = "get-credentials";
385385
runtimeInputs = with pkgs; [
386386
google-cloud-sdk
387387
scripts.merge-kube-config
@@ -394,6 +394,19 @@ lib.makeScope pkgs.newScope (scripts: {
394394
'';
395395
};
396396

397+
# Usage: get-read-token $gcloudSecretRef
398+
get-read-token = writeShellApplication {
399+
name = "get-read-token";
400+
runtimeInputs = with pkgs; [
401+
google-cloud-sdk
402+
];
403+
text = ''
404+
set -euo pipefail
405+
# this is the officially recommended way to get the raw output...
406+
gcloud secrets versions access "$1" --format='get(payload.data)' | tr '_-' '/+' | base64 -d
407+
'';
408+
};
409+
397410
# Usage: get-logs [start | download] $namespaceFile
398411
get-logs = writeShellApplication {
399412
name = "get-logs";

0 commit comments

Comments
 (0)