Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(skaffold): buildx builder handles minikube #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions shell-modules/k8s.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ in
];
gcloud.enable = true;
gcloud.extra-components = [ "gke-gcloud-auth-plugin" ];
interactiveShellHook = lib.optionalString (
cfg.cluster != null
) "gcloud container clusters get-credentials ${cfg.cluster} --region ${cfg.region}";
interactiveShellHook = lib.optionalString (cfg.cluster != null) ''
kubectlContext="$(kubectl config current-context)"
gcloud container clusters get-credentials ${cfg.cluster} --region ${cfg.region}
kubectl config use "$kubectlContext"
'';
};
}
23 changes: 18 additions & 5 deletions skaffold-buildx-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@
# docker images, and works on Apple Silicon via rosetta.
PLATFORMS=${PLATFORMS:-linux/amd64}

# `docker buildx build` requires a builder instance, and builder instances also
# have a platform. For each value of PLATFORMS, we create or re-use
# a builder instance.
# `docker buildx build` requires a builder instance. Builder instances have an
# associated set of platforms, and a context. Therefore, we create or re-use a
# builder for each combination of those things
# REF: https://docs.docker.com/reference/cli/docker/buildx/create/

if [[ -n "${MINIKUBE_ACTIVE_DOCKERD:-}" ]]; then
context=minikube
echo "Deploying to a minikube cluster, using '$context' docker context"
# Since minikube instances can change without this context changing, it must
# be kept up-to-date, and the simplest way to do that is by always
# re-creating it.
docker context rm $context &> /dev/null || echo "'$context' docker context not found, creating it"
docker context create $context &> /dev/null
else
context=$(docker context show)
fi

# PLATFORMS can have `/` and `,` characters in it, but builder names can't.
# This shell expansion replaces those with `-` characters
builder="skaffold-${PLATFORMS//[,\/]/-}"
builder="skaffold-${PLATFORMS//[,\/]/-}-$context"

if docker buildx inspect "$builder" >/dev/null 2>&1; then
echo "Using existing builder $builder"
else
echo "Creating builder $builder"
docker buildx create --name "$builder" --platform "$PLATFORMS"
docker buildx create --name "$builder" --platform "$PLATFORMS" --use "$context"
fi

if [ "$PUSH_IMAGE" = "true" ]; then
Expand Down