Skip to content

Instantly share code, notes, and snippets.

@jeffbryner
Created November 22, 2021 22:42
Show Gist options
  • Save jeffbryner/0bdc90466094e79d86eac609cedc88ff to your computer and use it in GitHub Desktop.
Save jeffbryner/0bdc90466094e79d86eac609cedc88ff to your computer and use it in GitHub Desktop.
cloudbuild with local docker builder
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '--build-arg','TERRAFORM_VERSION=${_TERRAFORM_VERSION}', '--build-arg','CLOUD_SDK_VERSION=${_CLOUD_SDK_VERSION}','-t', 'gcr.io/prj-sample-project-84d9/cloudbuilder', '.' ]
substitutions:
_TERRAFORM_VERSION: 1.0.11
_CLOUD_SDK_VERSION: 354.0.0
images:
- gcr.io/$PROJECT_ID/cloudbuilder
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Download and verify the integrity of the download first
FROM sethvargo/hashicorp-installer:0.2.0 AS installer
# Required to download and install Terraform
ARG TERRAFORM_VERSION
ENV TERRAFORM_VERSION ${TERRAFORM_VERSION}
RUN echo "version ${TERRAFORM_VERSION}"
RUN /install-hashicorp-tool "terraform" "$TERRAFORM_VERSION"
FROM alpine:3.13
RUN apk update && apk add --no-cache \
bash \
git \
wget \
python3 \
py3-pip \
jq
# Install Terraform
COPY --from=installer /software/terraform /usr/local/bin/terraform
# Install cloud SDK
ENV PATH /usr/local/google-cloud-sdk/bin:$PATH
ARG CLOUD_SDK_VERSION=
ENV CLOUD_SDK_VERSION ${CLOUD_SDK_VERSION}
ADD install_cloud_sdk.sh /build/
RUN /build/install_cloud_sdk.sh ${CLOUD_SDK_VERSION}
RUN rm -rf /build
# install pipenv
RUN pip install pipenv
#output versions
RUN terraform version && gcloud version
RUN which terraform
RUN echo $PATH
CMD ["/bin/bash"]
#! /bin/bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
CLOUD_SDK_VERSION=$1
cd /build
wget "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz"
tar -C /usr/local -xzf "google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz"
rm "google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz"
# TODO: Cargo-culted the symlink from a previous method. Would be nice to know
# why this is necessary
ln -s /lib /lib64
gcloud config set core/disable_usage_reporting true
gcloud config set component_manager/disable_update_check true
gcloud config set survey/disable_prompts true
gcloud components install beta --quiet
gcloud components install alpha --quiet
gcloud --version
gsutil version -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment