Skip to content

Commit

Permalink
Fix old tag of custom error pages used in example (#7460)
Browse files Browse the repository at this point in the history
* Fix old tag of custom error pages used in example

* Move nginx-errors to k8s registry

Since the setup for the custom-error-messages was really different from
the other images that are build using cloudbuild, I changed it to "fit
in better"

* Use Go version 1.17 for custom-error-pages

Since Go >= 1.16 required the use of modules, I also initialized the module using the name k8s.io/ingress-nginx/custom-error-pages
  • Loading branch information
DysphoricUnicorn authored Sep 9, 2021
1 parent 7be4015 commit c9a00fb
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
spec:
containers:
- name: nginx-error-server
image: quay.io/kubernetes-ingress-controller/custom-error-pages-amd64:0.3
image: gcr.io/k8s-staging-ingress-nginx/nginx-errors:0.48.1
ports:
- containerPort: 8080
# Setting the environment variable DEBUG we can see the headers sent
Expand Down
156 changes: 54 additions & 102 deletions images/custom-error-pages/Makefile
Original file line number Diff line number Diff line change
@@ -1,105 +1,57 @@
all: all-container

BUILDTAGS=

# Use the 0.0 tag for testing, it shouldn't clobber any release builds
TAG?=0.4
REGISTRY?=quay.io/kubernetes-ingress-controller
GOOS?=linux
DOCKER?=docker
SED_I?=sed -i
GOHOSTOS ?= $(shell go env GOHOSTOS)

PKG=k8s.io/ingress-nginx/images/custom-error-pages

ifeq ($(GOHOSTOS),darwin)
SED_I=sed -i ''
endif

REPO_INFO=$(shell git config --get remote.origin.url)

ifndef COMMIT
COMMIT := git-$(shell git rev-parse --short HEAD)
endif

ARCH ?= $(shell go env GOARCH)
GOARCH = ${ARCH}

BASEIMAGE?=alpine:3.10

ALL_ARCH = amd64 arm arm64

QEMUVERSION=v4.1.0-1

IMGNAME = custom-error-pages
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)

ifeq ($(ARCH),arm)
QEMUARCH=arm
GOARCH=arm
endif
ifeq ($(ARCH),arm64)
QEMUARCH=aarch64
endif

TEMP_DIR := $(shell mktemp -d)

DOCKERFILE := $(TEMP_DIR)/rootfs/Dockerfile

sub-container-%:
$(MAKE) ARCH=$* build container

sub-push-%:
$(MAKE) ARCH=$* push

all-container: $(addprefix sub-container-,$(ALL_ARCH))

all-push: $(addprefix sub-push-,$(ALL_ARCH))

container: .container-$(ARCH)
.container-$(ARCH):
cp -r ./* $(TEMP_DIR)
$(SED_I) 's|BASEIMAGE|$(BASEIMAGE)|g' $(DOCKERFILE)
$(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE)

ifeq ($(ARCH),amd64)
# When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
$(SED_I) "/CROSS_BUILD_/d" $(DOCKERFILE)
# Copyright 2021 The Kubernetes Authors.
#
# 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.

# Container image for nginx-errors.

# 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)/nginx-errors

# required to enable buildx
export DOCKER_CLI_EXPERIMENTAL=enabled

# build with buildx
PLATFORMS?=linux/amd64,linux/arm,linux/arm64
OUTPUT=
PROGRESS=plain

build: ensure-buildx
docker buildx build \
--platform=${PLATFORMS} $(OUTPUT) \
--progress=$(PROGRESS) \
--pull \
-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/main/hack/init-buildx.sh | bash
else
# When cross-building, only the placeholder "CROSS_BUILD_" should be removed
# Register /usr/bin/qemu-ARCH-static as the handler for ARM binaries in the kernel
# $(DOCKER) run --rm --privileged multiarch/qemu-user-static:register --reset
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)/rootfs
$(SED_I) "s/CROSS_BUILD_//g" $(DOCKERFILE)
@exec $(INIT_BUILDX)
endif
@echo "done"

$(DOCKER) build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)/rootfs

ifeq ($(ARCH), amd64)
# This is for to maintain the backward compatibility
$(DOCKER) tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
endif

push: .push-$(ARCH)
.push-$(ARCH):
$(DOCKER) push $(MULTI_ARCH_IMG):$(TAG)
ifeq ($(ARCH), amd64)
$(DOCKER) push $(IMAGE):$(TAG)
endif

clean:
$(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true

build: clean
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -a -installsuffix cgo \
-ldflags "-s -w" \
-o ${TEMP_DIR}/rootfs/custom-error-pages ${PKG}/...

release: all-container all-push
echo "done"

.PHONY: register-qemu
register-qemu:
# Register /usr/bin/qemu-ARCH-static as the handler for binaries in multiple platforms
$(DOCKER) run --rm --privileged multiarch/qemu-user-static:register --reset
.PHONY: build push ensure-buildx
22 changes: 22 additions & 0 deletions images/custom-error-pages/cloudbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
timeout: 600s
options:
substitution_option: ALLOW_LOOSE
steps:
- name: gcr.io/k8s-testimages/gcb-docker-gcloud:v20201130-750d12f
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"
23 changes: 18 additions & 5 deletions images/custom-error-pages/rootfs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 The Kubernetes Authors. All rights reserved.
# Copyright 2021 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.
Expand All @@ -12,10 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM BASEIMAGE
FROM golang:1.17-alpine as builder
RUN apk add git

CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/
WORKDIR /go/src/k8s.io/ingress-nginx/images/custom-error-pages

COPY . /
COPY . .

CMD ["/custom-error-pages"]
RUN go get . && \
CGO_ENABLED=0 go build -a -installsuffix cgo \
-ldflags "-s -w" \
-o nginx-errors .

# 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/custom-error-pages/nginx-errors /
USER nonroot:nonroot

CMD ["/nginx-errors"]
17 changes: 17 additions & 0 deletions images/custom-error-pages/rootfs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module k8s.io/ingress-nginx/custom-error-pages

go 1.17

require github.com/prometheus/client_golang v1.11.0

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
)
Loading

0 comments on commit c9a00fb

Please sign in to comment.