Skip to content

Instantly share code, notes, and snippets.

@kenichi
Last active November 7, 2022 21:08
Show Gist options
  • Save kenichi/0176d37ed6f66222446f2abf94682823 to your computer and use it in GitHub Desktop.
Save kenichi/0176d37ed6f66222446f2abf94682823 to your computer and use it in GitHub Desktop.
gcloud docker with cli alias for m1
FROM google/cloud-sdk:latest
ARG UID
ARG GID
ARG USERNAME
RUN useradd -u $UID -g $GID $USERNAME
WORKDIR /home/$USERNAME
USER $USERNAME
UID := $(shell id -u)
GID := $(shell id -g)
USERNAME := $(shell id -u -n)
IMAGE := google/cloud-sdk:latest
.PHONY: build pull
build: pull
@docker build \
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
--build-arg USERNAME=$(USERNAME) \
-t $(USERNAME)/gcloud \
.
pull:
@docker pull $(IMAGE)
alias gcloud="docker run --rm -it --user 501:20 \
-v ~/.gcp/config:/home/${USER}/.config \
-v ~/.gcp/kube:/home/${USER}/.kube \
-v ~/.gcp/ssh:/home/${USER}/.ssh \
--platform linux/amd64 ${USER}/gcloud gcloud"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment