Add cloudbuild configuration for fastcgi test image

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-06-26 16:23:52 -04:00
parent a24ce45b89
commit 9107a042de
5 changed files with 70 additions and 26 deletions

View file

@ -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

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

@ -1 +0,0 @@
fastcgi-helloserver

View file

@ -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"]