Skip to content

Commit

Permalink
base gcloud builder on google/cloud-sdk (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored Feb 7, 2019
1 parent a3d23b2 commit 3d11322
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 74 deletions.
32 changes: 2 additions & 30 deletions gcloud/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
FROM gcloud-slim

RUN apt-get -y update && \
# JRE is required for cloud-datastore-emulator
apt-get -y install default-jre && \

# Install all available components
/builder/google-cloud-sdk/bin/gcloud -q components install \
alpha beta \
app-engine-go \
app-engine-java \
app-engine-php \
app-engine-python \
app-engine-python-extras \
bigtable \
cbt \
cloud-datastore-emulator \
cloud-build-local \
datalab \
docker-credential-gcr \
emulator-reverse-proxy \
kubectl \
pubsub-emulator \
&& \

/builder/google-cloud-sdk/bin/gcloud -q components update && \
/builder/google-cloud-sdk/bin/gcloud components list && \

# Clean up
rm -rf /var/lib/apt/lists/*
FROM google/cloud-sdk
ENTRYPOINT ["gcloud"]
33 changes: 2 additions & 31 deletions gcloud/Dockerfile.slim
Original file line number Diff line number Diff line change
@@ -1,31 +1,2 @@
FROM launcher.gcr.io/google/ubuntu16_04

RUN apt-get -y update && \
apt-get -y install gcc python2.7 python-dev python-setuptools wget ca-certificates \
# These are necessary for add-apt-respository
software-properties-common python-software-properties && \

# Install Git >2.0.1
add-apt-repository ppa:git-core/ppa && \
apt-get -y update && \
apt-get -y install git && \

# Setup Google Cloud SDK (latest)
mkdir -p /builder && \
wget -qO- https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz | tar zxv -C /builder && \
CLOUDSDK_PYTHON="python2.7" /builder/google-cloud-sdk/install.sh --usage-reporting=false \
--bash-completion=false \
--disable-installation-options && \
# install crcmod: https://cloud.google.com/storage/docs/gsutil/addlhelp/CRC32CandInstallingcrcmod
easy_install -U pip && \
pip install -U crcmod && \

# Clean up
apt-get -y remove gcc python-dev python-setuptools wget && \
rm -rf /var/lib/apt/lists/* && \
rm -rf ~/.config/gcloud

ENV PATH=/builder/google-cloud-sdk/bin/:$PATH

ENTRYPOINT ["/builder/google-cloud-sdk/bin/gcloud"]
FROM google/cloud-sdk:slim
ENTRYPOINT ["gcloud"]
28 changes: 17 additions & 11 deletions gcloud/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# gcloud
# Tool builder: `gcr.io/cloud-builders/gcloud`

This is a tool builder to simply invoke
[`gcloud`](https://cloud.google.com/sdk/gcloud/) commands.

Arguments passed to this builder will be passed to `gcloud` directly, allowing
callers to run [any `gcloud`
command](https://cloud.google.com/sdk/gcloud/reference/).
This Cloud Build builder runs the
[`gcloud`](https://cloud.google.com/sdk/gcloud/) tool to interact with Google
Cloud Platform resources.

When executed in the Cloud Build environment, commands are executed with
credentials of the [builder service
account](https://cloud.google.com/cloud-build/docs/permissions) for the
project.
project. The latest released version of `gcloud` is used.

You should consider instead using an [official `google/cloud-sdk`
image](https://hub.docker.com/r/google/cloud-sdk) and specifying the `gcloud` entrypoint:

```yaml
steps:
- name: google/cloud-sdk:230.0.0
entrypoint: 'gcloud'
args: ['version']
```
The latest released version of `gcloud` is used.
This allows you to use any supported version of `gcloud`.

## Examples

Expand All @@ -29,12 +36,11 @@ steps:
args: ['source', 'repos', 'clone', 'default']
```

## `gcloud` vs `gcloud-slim`
There are two variants of the `gcloud` builder:
* `gcloud` installs all optional gcloud components, and is much larger.
* `gcloud` has all optional gcloud components installed, and is much larger.
* `gcloud-slim` installs only the `gcloud` CLI and no components, and is
smaller.
Expand Down
5 changes: 5 additions & 0 deletions gcloud/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ steps:
- name: 'gcr.io/$PROJECT_ID/gcloud'
args: ['source', 'repos', 'clone', 'default']

# Demonstrate using the official gcloud image.
- name: google/cloud-sdk:230.0.0
entrypoint: 'gcloud'
args: ['version']

images:
- 'gcr.io/$PROJECT_ID/gcloud'
- 'gcr.io/$PROJECT_ID/gcloud-slim'
Expand Down
5 changes: 3 additions & 2 deletions kubectl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM gcr.io/cloud-builders/gcloud-slim

# Install kubectl component
RUN /builder/google-cloud-sdk/bin/gcloud -q components install kubectl
# Install kubectl. gcloud's component manager is disabled, so we have to
# install it from apt-get.
RUN apt-get install kubectl

COPY kubectl.bash /builder/kubectl.bash

Expand Down
7 changes: 7 additions & 0 deletions kubectl/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--tag=gcr.io/$PROJECT_ID/kubectl', '.']

# Minimally invoke kubectl.
# We need to bypass kubectl.bash and only request client version because there
# is no cluster to connect to.
- name: 'gcr.io/$PROJECT_ID/kubectl'
entrypoint: 'kubectl' # Bypass kubectl.bash
args: ['version', '--client']

images: ['gcr.io/$PROJECT_ID/kubectl']

0 comments on commit 3d11322

Please sign in to comment.