From 9107a042dee3b7dba2015b013c9e803ddf4a822d Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Fri, 26 Jun 2020 16:23:52 -0400 Subject: [PATCH] Add cloudbuild configuration for fastcgi test image --- images/fastcgi-helloserver/Makefile | 56 +++++++++++-------- images/fastcgi-helloserver/cloudbuild.yaml | 22 ++++++++ images/fastcgi-helloserver/rootfs/.gitignore | 1 - images/fastcgi-helloserver/rootfs/Dockerfile | 17 +++++- .../fastcgi-helloserver/{ => rootfs}/main.go | 0 5 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 images/fastcgi-helloserver/cloudbuild.yaml delete mode 100644 images/fastcgi-helloserver/rootfs/.gitignore rename images/fastcgi-helloserver/{ => rootfs}/main.go (100%) diff --git a/images/fastcgi-helloserver/Makefile b/images/fastcgi-helloserver/Makefile index af0eed9fc..1d358194b 100644 --- a/images/fastcgi-helloserver/Makefile +++ b/images/fastcgi-helloserver/Makefile @@ -14,34 +14,44 @@ # Docker image for e2e testing. -# Use the 0.0 tag for testing, it shouldn't clobber any release builds -TAG ?= 0.0 +# set default shell +SHELL=/bin/bash -o pipefail -o errexit -HOSTARCH := $(shell uname -m | sed -e s/x86_64/amd64/ \ - -e s/s390x/s390x/ \ - -e s/armv7l/arm/ \ - -e s/aarch64.*/arm64/) +DIR:=$(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))) +INIT_BUILDX=$(DIR)/../../hack/init-buildx.sh -ifndef ARCH -ARCH := $(HOSTARCH) -endif -ifeq ($(ARCH),) - $(error mandatory variable ARCH is empty) -endif +TAG ?=v$(shell date +%m%d%Y)-$(shell git rev-parse --short HEAD) +REGISTRY ?= local -REGISTRY ?= ingress-controller +IMAGE = $(REGISTRY)/e2e-test-fastcgi-helloserver -IMAGE = $(REGISTRY)/fastcgi-helloserver +# required to enable buildx +export DOCKER_CLI_EXPERIMENTAL=enabled -PKG=k8s.io/ingress-nginx/images/fastcgi-helloserver +# build with buildx +PLATFORMS?=linux/amd64 +OUTPUT= +PROGRESS=plain -.PHONY: image -image: build - docker build \ +build: ensure-buildx + docker buildx build \ + --platform=${PLATFORMS} $(OUTPUT) \ + --progress=$(PROGRESS) \ + --pull \ -t $(IMAGE):$(TAG) rootfs -.PHONY: build -build: - GOARCH=$(ARCH) CGO_ENABLED=0 go build -a -installsuffix cgo \ - -ldflags "-s -w" \ - -o rootfs/fastcgi-helloserver ${PKG}/... +# 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 diff --git a/images/fastcgi-helloserver/cloudbuild.yaml b/images/fastcgi-helloserver/cloudbuild.yaml new file mode 100644 index 000000000..2a8f7da65 --- /dev/null +++ b/images/fastcgi-helloserver/cloudbuild.yaml @@ -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" diff --git a/images/fastcgi-helloserver/rootfs/.gitignore b/images/fastcgi-helloserver/rootfs/.gitignore deleted file mode 100644 index 3051bf91d..000000000 --- a/images/fastcgi-helloserver/rootfs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -fastcgi-helloserver diff --git a/images/fastcgi-helloserver/rootfs/Dockerfile b/images/fastcgi-helloserver/rootfs/Dockerfile index b68ef45c3..f572410e7 100755 --- a/images/fastcgi-helloserver/rootfs/Dockerfile +++ b/images/fastcgi-helloserver/rootfs/Dockerfile @@ -12,8 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM scratch +FROM golang:1.14-alpine as builder -COPY . / +WORKDIR /go/src/k8s.io/ingress-nginx/images/fastcgi + +COPY . . + +RUN CGO_ENABLED=0 go build -a -installsuffix cgo \ + -ldflags "-s -w" \ + -o fastcgi-helloserver main.go + +# Use distroless as minimal base image to package the binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/static:nonroot + +COPY --from=builder /go/src/k8s.io/ingress-nginx/images/fastcgi/fastcgi-helloserver / +USER nonroot:nonroot CMD ["/fastcgi-helloserver"] diff --git a/images/fastcgi-helloserver/main.go b/images/fastcgi-helloserver/rootfs/main.go similarity index 100% rename from images/fastcgi-helloserver/main.go rename to images/fastcgi-helloserver/rootfs/main.go