Simplify build of e2e test image

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-06-24 21:14:40 -04:00
parent d82585917c
commit dcbe3824de
4 changed files with 117 additions and 60 deletions

View file

@ -1,41 +0,0 @@
# Copyright 2018 The Kubernetes 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.
TAG ?=v$(shell date +%m%d%Y)-$(shell git rev-parse --short HEAD)
REGISTRY ?= quay.io/kubernetes-ingress-controller
IMAGE = $(REGISTRY)/e2e
HOST_ARCH = $(shell which go >/dev/null 2>&1 && go env GOARCH)
ARCH ?= $(HOST_ARCH)
ifeq ($(ARCH),)
$(error mandatory variable ARCH is empty, either set it when calling the command or make sure 'go env GOARCH' works)
endif
.PHONY: image
image:
docker build \
--build-arg TARGETARCH="$(ARCH)" \
--build-arg K8S_RELEASE=v1.15.7 \
--build-arg RESTY_CLI_VERSION=0.25rc2 \
--build-arg RESTY_CLI_SHA=a38d850441384fa037a5922ca012dcce8708d0e4abe34ad2fe4164a01b28bdfb \
--build-arg CHART_TESTING_VERSION=3.0.0-beta.1 \
--build-arg YAML_LINT_VERSION=1.13.0 \
--build-arg YAMALE_VERSION=1.8.0 \
--build-arg HELM_VERSION=v3.2.0 \
-t $(IMAGE):$(TAG) rootfs
.PHONY: show-image
show-image:
echo -n $(IMAGE):$(TAG)

View file

@ -0,0 +1,67 @@
# Copyright 2018 The Kubernetes 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.
# set default shell
SHELL=/bin/bash -o pipefail -o errexit
DIR:=$(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
INIT_BUILDX=$(DIR)/../../hack/init-buildx.sh
TAG ?=v$(shell date +%m%d%Y)-$(shell git rev-parse --short HEAD)
REGISTRY ?= local
IMAGE = $(REGISTRY)/e2e-test-runner
# required to enable buildx
export DOCKER_CLI_EXPERIMENTAL=enabled
# build with buildx
PLATFORMS?=linux/amd64
OUTPUT=
PROGRESS=plain
build: ensure-buildx
docker buildx build \
--platform=${PLATFORMS} $(OUTPUT) \
--progress=$(PROGRESS) \
--pull \
--build-arg BASE_IMAGE=gcr.io/k8s-staging-ingress-nginx/nginx@sha256:35da1d3e00f5e763e59cb59159bf88ba0f0b6e8835885ac9d8b63029a478dba7 \
--build-arg GOLANG_VERSION=1.14.4 \
--build-arg ETCD_VERSION=3.4.3-0 \
--build-arg K8S_RELEASE=v1.15.7 \
--build-arg RESTY_CLI_VERSION=0.25rc2 \
--build-arg RESTY_CLI_SHA=a38d850441384fa037a5922ca012dcce8708d0e4abe34ad2fe4164a01b28bdfb \
--build-arg LUAROCKS_VERSION=3.3.1 \
--build-arg LUAROCKS_SHA=837481e408f7c06b59befe7ec194537c657687d624894bca7f79034302141a34 \
--build-arg CHART_TESTING_VERSION=3.0.0-beta.1 \
--build-arg YAML_LINT_VERSION=1.13.0 \
--build-arg YAMALE_VERSION=1.8.0 \
--build-arg HELM_VERSION=v3.2.0 \
-t $(IMAGE):$(TAG) rootfs
# push the cross built image
push: OUTPUT=--push
push: build
# enable buildx
ensure-buildx:
# this is required for cloudbuild
ifeq ("$(wildcard $(INIT_BUILDX))","")
@curl -sSL https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/hack/init-buildx.sh | bash
else
@exec $(INIT_BUILDX)
endif
@echo "done"
.PHONY: build push ensure-buildx

View file

@ -0,0 +1,22 @@
timeout: 600s
options:
substitution_option: ALLOW_LOOSE
steps:
- name: gcr.io/k8s-testimages/gcb-docker-gcloud:v20200619-68869a4
entrypoint: bash
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
- TAG=$_GIT_TAG
- BASE_REF=$_PULL_BASE_REF
- REGISTRY=gcr.io/k8s-staging-ingress-nginx
# default cloudbuild has HOME=/builder/home and docker buildx is in /root/.docker/cli-plugins/docker-buildx
# set the home to /root explicitly to if using docker buildx
- HOME=/root
args:
- -c
- |
gcloud auth configure-docker \
&& make push
substitutions:
_GIT_TAG: "12345"
_PULL_BASE_REF: "master"

View file

@ -12,17 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM golang:1.14.3-alpine3.11 as GO
FROM k8s.gcr.io/etcd:3.4.3-0 as etcd
FROM quay.io/kubernetes-ingress-controller/nginx:e3c49c52f4b74fe47ad65d6f3266a02e8b6b622f
ARG RESTY_CLI_VERSION
ARG RESTY_CLI_SHA
ARG K8S_RELEASE
ARG BASE_IMAGE
ARG GOLANG_VERSION
ARG ETCD_VERSION
ARG CHART_TESTING_VERSION
FROM golang:${GOLANG_VERSION}-alpine as GO
FROM k8s.gcr.io/etcd:${ETCD_VERSION} as etcd
FROM ${BASE_IMAGE}
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
@ -51,14 +48,23 @@ RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
RUN go get github.com/onsi/ginkgo/ginkgo golang.org/x/lint/golint
RUN wget -O /tmp/resty_cli.tgz https://github.com/openresty/resty-cli/archive/v${RESTY_CLI_VERSION}.tar.gz \
ARG RESTY_CLI_VERSION
ARG RESTY_CLI_SHA
RUN wget -O /tmp/resty_cli.tgz \
https://github.com/openresty/resty-cli/archive/v${RESTY_CLI_VERSION}.tar.gz \
&& echo "${RESTY_CLI_SHA} */tmp/resty_cli.tgz" | sha256sum -c - \
&& tar -C /tmp -xzf /tmp/resty_cli.tgz \
&& mv /tmp/resty-cli-${RESTY_CLI_VERSION}/bin/* /usr/local/bin/ \
&& resty -V \
&& rm -rf /tmp/*
RUN wget -O /tmp/luarocks.tgz https://github.com/luarocks/luarocks/archive/v3.3.1.tar.gz \
ARG LUAROCKS_VERSION
ARG LUAROCKS_SHA
RUN wget -O /tmp/luarocks.tgz \
https://github.com/luarocks/luarocks/archive/v${LUAROCKS_VERSION}.tar.gz \
&& echo "${LUAROCKS_SHA} */tmp/luarocks.tgz" | sha256sum -c - \
&& tar -C /tmp -xzf /tmp/luarocks.tgz \
&& cd /tmp/luarocks* \
&& ./configure \
@ -67,11 +73,10 @@ RUN wget -O /tmp/luarocks.tgz https://github.com/luarocks/luarocks/archive/v3.3.
RUN luarocks install busted \
&& luarocks install luacheck
ARG BUSTED_VERSION
ARG BUSTED_SHA
ARG TARGETARCH
ARG K8S_RELEASE
RUN wget -O /usr/local/bin/kubectl \
https://storage.googleapis.com/kubernetes-release/release/${K8S_RELEASE}/bin/linux/${TARGETARCH}/kubectl \
&& chmod +x /usr/local/bin/kubectl
@ -80,6 +85,8 @@ RUN wget -O /usr/local/bin/kube-apiserver \
https://storage.googleapis.com/kubernetes-release/release/${K8S_RELEASE}/bin/linux/${TARGETARCH}/kube-apiserver \
&& chmod +x /usr/local/bin/kube-apiserver
ARG CHART_TESTING_VERSION
RUN wget -O /tmp/ct-${CHART_TESTING_VERSION}-linux-amd64.tar.gz \
https://github.com/helm/chart-testing/releases/download/v${CHART_TESTING_VERSION}/chart-testing_${CHART_TESTING_VERSION}_linux_amd64.tar.gz \
&& mkdir -p /tmp/ct-download \
@ -90,18 +97,20 @@ RUN wget -O /tmp/ct-${CHART_TESTING_VERSION}-linux-amd64.tar.gz \
&& cp -R /tmp/ct-download/etc/* /etc/ct \
&& rm -rf /tmp/*
RUN wget https://raw.githubusercontent.com/openresty/openresty-devel-utils/master/lj-releng -O /usr/local/bin/lj-releng \
RUN wget -O /usr/local/bin/lj-releng \
https://raw.githubusercontent.com/openresty/openresty-devel-utils/master/lj-releng \
&& chmod +x /usr/local/bin/lj-releng
ARG HELM_VERSION
RUN wget -O /tmp/helm.tgz https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz \
RUN wget -O /tmp/helm.tgz \
https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -C /tmp -xzf /tmp/helm.tgz \
&& cp /tmp/linux*/helm /usr/local/bin \
&& rm -rf /tmp/*
RUN curl -sSL -o /usr/local/bin/cfssl https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssl_1.4.1_linux_${TARGETARCH} \
&& curl -sSL -o /usr/local/bin/cfssljson https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssljson_1.4.1_linux_${TARGETARCH} \
RUN wget -O /usr/local/bin/cfssl https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssl_1.4.1_linux_${TARGETARCH} \
&& wget -O /usr/local/bin/cfssljson https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssljson_1.4.1_linux_${TARGETARCH} \
&& chmod +x /usr/local/bin/cfssl*
# Install a YAML Linter