forked from kubernetes/ingress-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-images.sh
executable file
·63 lines (49 loc) · 3.59 KB
/
build-images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
CONTROLLER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-nginx-ingress-controller}
BACKEND_IMAGE_NAME=${DOCKER_DEFAULT_BACKEND_IMAGE_NAME:-nginx-ingress-default-backend}
WEBHOOK_CERTGEN_IMAGE_NAME=${DOCKER_DEFAULT_WEBHOOK_CERTGEN_IMAGE_NAME:-kube-webhook-certgen}
SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P)
INGRESS_NGINX_DOCKER_BASE_IMAGE=${DOCKER_REPO}/${DOCKER_NAMESPACE}/nginx-ingress
INGRESS_NGINX_DOCKER_IMAGE_AMD64=${DOCKER_REPO}/${DOCKER_NAMESPACE}/nginx-ingress-amd64:${DOCKER_TAG}
DEFAULT_BACKEND_IMAGE=${DOCKER_REPO}/${DOCKER_NAMESPACE}/${BACKEND_IMAGE_NAME}
CONTROLLER_IMAGE=${DOCKER_REPO}/${DOCKER_NAMESPACE}/${CONTROLLER_IMAGE_NAME}
WEBHOOK_CERTGEN_IMAGE=${DOCKER_REPO}/${DOCKER_NAMESPACE}/${WEBHOOK_CERTGEN_IMAGE_NAME}
# Define custom Golang image
GO_CONTAINER_IMAGE=${GOLANG_IMAGE_NAME:-ghcr.io/verrazzano/golang:v1.20.12}
# Use the latest runner image from controller-v1.9.4, as a workaround to build cmd/dbg, cmd/waitshutdown and cmd/waitshutdown with Go 1.21.3
RUNNER_IMAGE=registry.k8s.io/ingress-nginx/e2e-test-runner:v20231011-8b53cabe0@sha256:ed0dad805c635e66469b4ac376010eebdd0b3fe62d753f58db1632d6f12f451d
set -ue
mkdir -p ${GOPATH}/src/k8s.io
ln -f -s "${SCRIPT_DIR}"/ "${GOPATH}"/src/k8s.io/ingress-nginx
cd "${GOPATH}"/src/k8s.io/ingress-nginx
# We need keep this follow line here, otherwise, the final docker image will contain github credential!!!
git remote set-url origin https://github.com/verrazzano/ingress-nginx.git
# Build nginx and its modules from source, and use that as a base image of ingress-nginx
mkdir -p images/nginx/rootfs/stage-licenses
cp LICENSE README.md THIRD_PARTY_LICENSES.txt images/nginx/rootfs/stage-licenses
docker build --rm=true --tag=${INGRESS_NGINX_DOCKER_IMAGE_AMD64} -f images/nginx/rootfs/Dockerfile images/nginx/rootfs/
rm -fr images/nginx/rootfs/stage-licenses
# Push nginx so it can be used as a base image of ingress-nginx
docker push ${INGRESS_NGINX_DOCKER_IMAGE_AMD64}
# Build custom-error-pages and its modules from source
mkdir -p images/custom-error-pages/rootfs/stage-licenses
cp LICENSE README.md THIRD_PARTY_LICENSES.txt images/custom-error-pages/rootfs/stage-licenses
make build -e BASEIMAGE=${INGRESS_NGINX_DOCKER_IMAGE_AMD64} -e TAG=${DOCKER_TAG} -e REGISTRY=${DOCKER_REPO}/${DOCKER_NAMESPACE} -e GO_CONTAINER_IMAGE=${GO_CONTAINER_IMAGE} -C images/custom-error-pages/
rm -fr images/custom-error-pages/rootfs/stage-licenses
# Push the custom-error-pages image
docker tag ${DOCKER_REPO}/${DOCKER_NAMESPACE}/nginx-errors:${DOCKER_TAG} ${DEFAULT_BACKEND_IMAGE}:${DOCKER_TAG}
docker push ${DEFAULT_BACKEND_IMAGE}:${DOCKER_TAG}
# Create the nginx-ingress-controller image
make ARCH=amd64 build image -e BASE_IMAGE=${INGRESS_NGINX_DOCKER_IMAGE_AMD64} -e TAG=${DOCKER_TAG} -e REGISTRY=${DOCKER_REPO}/${DOCKER_NAMESPACE} DOCKER_IN_DOCKER_ENABLED=false -e E2E_IMAGE=${RUNNER_IMAGE}
docker tag ${DOCKER_REPO}/${DOCKER_NAMESPACE}/controller:${DOCKER_TAG} ${CONTROLLER_IMAGE}:${DOCKER_TAG}
docker push ${CONTROLLER_IMAGE}:${DOCKER_TAG}
# Build the kube-webhook-certgen image and push it
mkdir -p images/kube-webhook-certgen/rootfs/stage-licenses
cp LICENSE README.md THIRD_PARTY_LICENSES.txt images/kube-webhook-certgen/rootfs/stage-licenses
make build -e TAG=${DOCKER_TAG} -e REGISTRY=${DOCKER_REPO}/${DOCKER_NAMESPACE} -e GO_CONTAINER_IMAGE=${GO_CONTAINER_IMAGE} -C images/kube-webhook-certgen/
rm -fr images/kube-webhook-certgen/rootfs/stage-licenses
docker tag ${DOCKER_REPO}/${DOCKER_NAMESPACE}/kube-webhook-certgen:${DOCKER_TAG} ${WEBHOOK_CERTGEN_IMAGE}:${DOCKER_TAG}
docker push ${WEBHOOK_CERTGEN_IMAGE}:${DOCKER_TAG}
# Remove symlink
cd "${SCRIPT_DIR}"
rm "${GOPATH}"/src/k8s.io/ingress-nginx