Skip to content

Commit

Permalink
feat: add lts image, cloud build triggers (#6844)
Browse files Browse the repository at this point in the history
* feat: add lts image, cloud build triggers

* add lts storage buckets, lts makefile target

* indent first build step

* fix sha paths

* rm container structure tests

* fix makefile and actually stop autoexpand tab to spaces

* fix Makefile

* remove latest from lts image

* builder image needs docker

* change base image to gcr.io/gcp-runtimes/ubuntu_20_0_4

* add timeout

* fix the version command
  • Loading branch information
tejal29 authored Nov 16, 2021
1 parent ec848b9 commit 519fb58
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ REPOPATH ?= $(ORG)/$(PROJECT)
RELEASE_BUCKET ?= $(PROJECT)
GSC_BUILD_PATH ?= gs://$(RELEASE_BUCKET)/builds/$(COMMIT)
GSC_BUILD_LATEST ?= gs://$(RELEASE_BUCKET)/builds/latest
GSC_LTS_BUILD_PATH ?= gs://$(RELEASE_BUCKET)/lts/builds/$(COMMIT)
GSC_LTS_BUILD_LATEST ?= gs://$(RELEASE_BUCKET)/lts/builds/latest
GSC_LTS_RELEASE_PATH ?= gs://$(RELEASE_BUCKET)/lts/releases/$(VERSION)
GSC_LTS_RELEASE_LATEST ?= gs://$(RELEASE_BUCKET)/lts/releases/latest
GSC_RELEASE_PATH ?= gs://$(RELEASE_BUCKET)/releases/$(VERSION)
GSC_RELEASE_LATEST ?= gs://$(RELEASE_BUCKET)/releases/latest

Expand Down Expand Up @@ -181,6 +185,30 @@ release-build: cross
gsutil -m cp $(BUILD_DIR)/$(PROJECT)-* $(GSC_BUILD_PATH)/
gsutil -m cp -r $(GSC_BUILD_PATH)/* $(GSC_BUILD_LATEST)

.PHONY: release-lts
release-lts: cross $(BUILD_DIR)/VERSION
docker build \
--build-arg VERSION=$(VERSION) \
-f deploy/skaffold/Dockerfile.lts \
--target release \
-t gcr.io/$(GCP_PROJECT)/skaffold:lts \
-t gcr.io/$(GCP_PROJECT)/skaffold:$(VERSION)-lts \
.
gsutil -m cp $(BUILD_DIR)/$(PROJECT)-* $(GSC_LTS_RELEASE_PATH)/
gsutil -m cp $(BUILD_DIR)/VERSION $(GSC_LTS_RELEASE_PATH)/VERSION
gsutil -m cp -r $(GSC_LTS_RELEASE_PATH)/* $(GSC_LTS_RELEASE_LATEST)

.PHONY: release-lts-build
release-lts-build: cross
docker build \
-f deploy/skaffold/Dockerfile.lts \
--target release \
-t gcr.io/$(GCP_PROJECT)/skaffold:edge-lts \
-t gcr.io/$(GCP_PROJECT)/skaffold:$(COMMIT)-lts \
.
gsutil -m cp $(BUILD_DIR)/$(PROJECT)-* $(GSC_LTS_BUILD_PATH)/
gsutil -m cp -r $(GSC_LTS_BUILD_PATH)/* $(GSC_LTS_BUILD_LATEST)

.PHONY: clean
clean:
rm -rf $(BUILD_DIR) hack/bin $(STATIK_FILES)
Expand Down
54 changes: 54 additions & 0 deletions deploy/cloudbuild-lts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# using default substitutions, provided by Google Cloud Build
# see: https://cloud.google.com/container-builder/docs/configuring-builds/substitute-variable-values#using_default_substitutions
steps:
# Build and tag skaffold-deps image using docker with cache-from
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/build_deps:latest-lts'
- '--cache-from'
- 'gcr.io/$PROJECT_ID/build_deps:latest-lts'
- '-f'
- 'deploy/skaffold/Dockerfile.deps.lts'
- '.'

# Grab secret credentials from gcp bucket
- name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: ['deploy/setup-secret.sh','-p', $PROJECT_ID]

# Build and tag skaffold builder
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/skaffold-builder:latest'
- '--cache-from'
- 'gcr.io/$PROJECT_ID/skaffold-builder:latest'
- '-f'
- 'deploy/skaffold/Dockerfile'
- '.'

# Do the go build & push the results to GCS
- name: 'gcr.io/$PROJECT_ID/skaffold-builder:latest'
args:
- 'make'
- 'release-lts-build'
- 'RELEASE_BUCKET=$_RELEASE_BUCKET'
- 'GCP_PROJECT=$PROJECT_ID'

# Check that skaffold is in the image
- name: 'gcr.io/$PROJECT_ID/skaffold:edge-lts'
args:
- 'skaffold'
- 'version'

images:
- 'gcr.io/$PROJECT_ID/skaffold:edge-lts'
- 'gcr.io/$PROJECT_ID/skaffold:$COMMIT_SHA-lts'

options:
machineType: 'N1_HIGHCPU_8'

timeout: 1500s
55 changes: 55 additions & 0 deletions deploy/cloudbuild-release-lts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# using default substitutions, provided by Google Cloud Build
# see: https://cloud.google.com/container-builder/docs/configuring-builds/substitute-variable-values#using_default_substitutions
steps:

# Build and tag skaffold-deps image using docker with cache-from
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/build_deps:latest-lts'
- '--cache-from'
- 'gcr.io/k8s-skaffold/build_deps:latest-lts'
- '-f'
- 'deploy/skaffold/Dockerfile.deps.lts'
- '.'

# Grab secret credentials from gcp bucket
- name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args: ['deploy/setup-secret.sh','-p', $PROJECT_ID]

# Build and tag skaffold builder
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '--cache-from'
- 'gcr.io/$PROJECT_ID/skaffold-builder:latest'
- '-t'
- 'gcr.io/$PROJECT_ID/skaffold-builder:latest'
- '-f'
- 'deploy/skaffold/Dockerfile'
- '.'

# Do the go build & push the results to GCS
- name: 'gcr.io/$PROJECT_ID/skaffold-builder:latest'
args:
- 'make'
- 'release-lts'
- 'VERSION=$TAG_NAME'
- 'RELEASE_BUCKET=$_RELEASE_BUCKET'
- 'GCP_PROJECT=$PROJECT_ID'

# Check that skaffold is in the image
- name: 'gcr.io/$PROJECT_ID/skaffold:$TAG_NAME-lts'
args:
- 'skaffold'
- 'version'

images:
- 'gcr.io/$PROJECT_ID/skaffold:$TAG_NAME-lts'

options:
machineType: 'N1_HIGHCPU_8'

timeout: 1500s
103 changes: 103 additions & 0 deletions deploy/skaffold/Dockerfile.deps.lts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2019 The Skaffold Authors All rights reserved.
#
# 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.

ARG ARCH=amd64

# Download kubectl
FROM alpine:3.10 as download-kubectl
ARG ARCH
# Track default version installed by Google Cloud SDK: 358.0.0 moved to 1.20(.10)
# https://cloud.google.com/sdk/docs/release-notes
ENV KUBECTL_VERSION v1.20.10
ENV KUBECTL_URL https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl
# SHAs at gs://kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/
COPY deploy/skaffold/digests/kubectl.${ARCH}.sha512 .
RUN wget -O kubectl "${KUBECTL_URL}" && sha512sum -c kubectl.${ARCH}.sha512
RUN chmod +x kubectl

# Download helm (see https://github.com/helm/helm/releases/latest)
FROM alpine:3.10 as download-helm
ARG ARCH
RUN echo arch=$ARCH
ENV HELM_VERSION v3.7.1
ENV HELM_URL https://get.helm.sh/helm-${HELM_VERSION}-linux-${ARCH}.tar.gz
COPY deploy/skaffold/digests/helm.${ARCH}.sha256 .
RUN wget -O helm.tar.gz "${HELM_URL}" && sha256sum -c helm.${ARCH}.sha256
RUN tar -xvf helm.tar.gz --strip-components 1

# Download kustomize
FROM alpine:3.10 as download-kustomize
ARG ARCH
ENV KUSTOMIZE_VERSION 4.4.0
ENV KUSTOMIZE_URL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_${ARCH}.tar.gz
COPY deploy/skaffold/digests/kustomize.${ARCH}.sha256 .
RUN wget -O kustomize.tar.gz "${KUSTOMIZE_URL}" && sha256sum -c kustomize.${ARCH}.sha256
RUN tar -xvf kustomize.tar.gz

# Download kpt
FROM alpine:3.10 as download-kpt
ARG ARCH
ENV KPT_VERSION 0.39.3
ENV KPT_URL https://github.com/GoogleContainerTools/kpt/releases/download/v${KPT_VERSION}/kpt_linux_amd64
COPY deploy/skaffold/digests/kpt.${ARCH}.sha256 .
RUN wget -O kpt "${KPT_URL}" && sha256sum -c kpt.${ARCH}.sha256
RUN chmod +x kpt

# Download gcloud
FROM alpine:3.10 as download-gcloud
ARG ARCH
ENV GCLOUD_VERSION 360.0.0
ENV GCLOUD_URL https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${GCLOUD_VERSION}-linux-GCLOUDARCH.tar.gz
# SHAs listed at https://cloud.google.com/sdk/docs/downloads-versioned-archives
COPY deploy/skaffold/digests/gcloud.${ARCH}.sha256 .
RUN \
GCLOUDARCH=$(case "${ARCH}" in amd64) echo x86_64;; *) echo ${ARCH};; esac); \
wget -O gcloud.tar.gz $(echo "${GCLOUD_URL}" | sed "s/GCLOUDARCH/${GCLOUDARCH}/g") && \
sha256sum -c gcloud.${ARCH}.sha256
RUN tar -zxf gcloud.tar.gz


FROM gcr.io/gcp-runtimes/ubuntu_20_0_4 as runtime_deps

RUN apt-get update && \
apt-get install --no-install-recommends --no-install-suggests -y \
git python unzip && \
rm -rf /var/lib/apt/lists/*

COPY --from=download-kubectl kubectl /usr/local/bin/
COPY --from=download-helm helm /usr/local/bin/
COPY --from=download-kustomize kustomize /usr/local/bin/
COPY --from=download-kpt kpt /usr/local/bin/
COPY --from=download-gcloud google-cloud-sdk/ /google-cloud-sdk/

# Finish installation of gcloud
RUN /google-cloud-sdk/install.sh \
--usage-reporting=false \
--bash-completion=false \
--disable-installation-options
ENV PATH=$PATH:/google-cloud-sdk/bin
RUN gcloud auth configure-docker

FROM runtime_deps
RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y \
build-essential \
python-setuptools \
lsb-release \
openjdk-11-jdk \
software-properties-common \
jq \
apt-transport-https && \
rm -rf /var/lib/apt/lists/*
COPY --from=golang:1.15 /usr/local/go /usr/local/go
ENV PATH /usr/local/go/bin:/root/go/bin:$PATH
26 changes: 26 additions & 0 deletions deploy/skaffold/Dockerfile.lts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019 The Skaffold Authors All rights reserved.
#
# 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.

# This base image is built using docker from cache every single time as build step.
FROM gcr.io/k8s-skaffold/build_deps:latest-lts as build
WORKDIR /skaffold

FROM build as builder
ARG VERSION
COPY . .
RUN make clean out/skaffold VERSION=$VERSION && mv out/skaffold /usr/bin/skaffold && rm -rf secrets $SECRET cmd/skaffold/app/cmd/statik/statik.go

FROM build as release
COPY --from=builder /usr/bin/skaffold /usr/bin/skaffold
RUN skaffold credits -d /THIRD_PARTY_NOTICES

0 comments on commit 519fb58

Please sign in to comment.