Skip to content

Instantly share code, notes, and snippets.

@9bic
Created January 6, 2018 17:22
Show Gist options
  • Save 9bic/cae49ec5c51dab06583e81c95461f0c5 to your computer and use it in GitHub Desktop.
Save 9bic/cae49ec5c51dab06583e81c95461f0c5 to your computer and use it in GitHub Desktop.
gcloud and gsutil for Google Container Optimized OS
#cloud-config
users:
- name: cloudservice
groups: docker
uid: 2000
write_files:
- path: /home/cloudservice/currentdir/gcloud-sdk-setup
permissions: '0644'
owner: cloudservice:cloudservice
content: |
export GCLOUDSDK_TAG="alpine"
export GCLOUDSDK_IMAGE="google/cloud-sdk:${GCLOUDSDK_TAG}"
docker pull ${GCLOUDSDK_IMAGE}
gsutil() {
docker run --rm -it \
-v $(pwd):$(pwd) \
-v $HOME:$HOME \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v /mnt:/mnt \
-w $(pwd) \
-u $(id -u):$(id -g) \
${GCLOUDSDK_IMAGE} gsutil "$@";
}
gcloud() {
docker run --rm -it \
-v $(pwd):$(pwd) \
-v $HOME:$HOME \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v /mnt:/mnt \
-w $(pwd) \
-u $(id -u):$(id -g) \
${GCLOUDSDK_IMAGE} gcloud "$@";
}
runcmd:
- "cat /home/cloudservice/currentdir/gcloud-sdk-setup > /etc/profile.d/cloud-sdk-setup.sh"
gcloud compute instances create $name \
--zone "asia-northeast1-a" \
--machine-type "f1-micro" \
--subnet "default" \
--image "cos-stable-63-10032-71-0" \
--image-project "cos-cloud" \
--boot-disk-size "10" \
--boot-disk-type "pd-standard" \
--boot-disk-device-name $name \
--metadata-from-file user-data=cloud-config.yaml \
--scopes "https://www.googleapis.com/auth/devstorage.read_write,https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/logging.write"
@appunni-m
Copy link

"user-data" is not allowed when running containerized VM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment