Skip to content

Commit ed3f067

Browse files
authored
Build NGINX v1.25 image (#10629)
1 parent c9c72c4 commit ed3f067

File tree

12 files changed

+1043
-5
lines changed

12 files changed

+1043
-5
lines changed

.github/workflows/nginx125.yaml

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: NGINX v1.25 Image
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*"
7+
paths:
8+
- 'images/nginx-1.25/**'
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- 'images/nginx-1.25/**'
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
changes:
20+
permissions:
21+
contents: read # for dorny/paths-filter to fetch a list of changed files
22+
pull-requests: read # for dorny/paths-filter to read pull requests
23+
runs-on: ubuntu-latest
24+
outputs:
25+
nginx: ${{ steps.filter.outputs.nginx }}
26+
tag: ${{ steps.filter.outputs.tag }}
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
30+
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
31+
id: filter
32+
with:
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
filters: |
35+
nginx:
36+
- 'images/nginx-1.25/**'
37+
tag:
38+
- 'images/nginx-1.25/TAG'
39+
40+
build:
41+
permissions:
42+
contents: read # for dorny/paths-filter to fetch a list of changed files
43+
pull-requests: read # for dorny/paths-filter to read pull requests
44+
runs-on: ubuntu-latest
45+
needs: changes
46+
if: |
47+
(github.event_name != 'push' && github.ref != 'refs/heads/main' && needs.changes.outputs.nginx == 'true')
48+
env:
49+
PLATFORMS: linux/amd64
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
53+
- name: Set up Go
54+
id: go
55+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
56+
with:
57+
go-version: '1.21.5'
58+
check-latest: true
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
61+
- name: Set up Docker Buildx
62+
id: buildx
63+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
64+
with:
65+
version: latest
66+
platforms: ${{ env.PLATFORMS }}
67+
- name: Prepare Host
68+
run: |
69+
curl -LO https://dl.k8s.io/release/v1.27.3/bin/linux/amd64/kubectl
70+
chmod +x ./kubectl
71+
sudo mv ./kubectl /usr/local/bin/kubectl
72+
- name: build-image
73+
run: |
74+
cd images/nginx-1.25/rootfs && docker buildx build --platform=${{ env.PLATFORMS }} --load -t nginx-1.25:1.0.0-dev .
75+
- name: load-image
76+
run: |
77+
make clean-image build
78+
make -C test/e2e-image image
79+
docker build \
80+
--platform linux \
81+
--no-cache \
82+
--build-arg BASE_IMAGE="nginx-1.25:1.0.0-dev" \
83+
--build-arg VERSION="0.0.1-${{ github.sha }}" \
84+
--build-arg TARGETARCH="amd64" \
85+
--build-arg COMMIT_SHA="git-${{ github.sha }}" \
86+
--build-arg BUILD_ID=""UNSET"" \
87+
-t ingress-controller/controller:1.0.0-dev rootfs
88+
docker save \
89+
nginx-ingress-controller:e2e \
90+
ingress-controller/controller:1.0.0-dev \
91+
nginx-1.25:1.0.0-dev \
92+
| gzip > docker.tar.gz
93+
- name: cache
94+
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
95+
with:
96+
name: docker.tar.gz
97+
path: docker.tar.gz
98+
retention-days: 2
99+
100+
e2e-test:
101+
name: Kubernetes
102+
runs-on: ubuntu-latest
103+
needs:
104+
- build
105+
strategy:
106+
matrix:
107+
k8s: [v1.27.3, v1.28.0, v1.29.0]
108+
steps:
109+
- name: Checkout
110+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
111+
112+
- name: cache
113+
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
114+
with:
115+
name: docker.tar.gz
116+
117+
- name: Create Kubernetes ${{ matrix.k8s }} cluster
118+
id: kind
119+
run: |
120+
kind create cluster --image=kindest/node:${{ matrix.k8s }} --config test/e2e/kind.yaml
121+
122+
- name: Load images from cache
123+
run: |
124+
echo "loading docker images..."
125+
gzip -dc docker.tar.gz | docker load
126+
127+
- name: Run e2e tests
128+
env:
129+
KIND_CLUSTER_NAME: kind
130+
SKIP_CLUSTER_CREATION: true
131+
SKIP_IMAGE_CREATION: true
132+
SKIP_OPENTELEMETRY_TESTS: true
133+
run: |
134+
kind get kubeconfig > $HOME/.kube/kind-config-kind
135+
make NGINX_BASE_IMAGE="nginx-1.25:1.0.0-dev" kind-e2e-test
136+
137+
push:
138+
permissions:
139+
contents: write
140+
packages: write
141+
runs-on: ubuntu-latest
142+
needs: changes
143+
if: |
144+
(github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.changes.outputs.tag == 'true')
145+
env:
146+
PLATFORMS: linux/amd64,linux/arm,linux/arm64,linux/s390x
147+
steps:
148+
- name: Checkout
149+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
150+
- name: Set up QEMU
151+
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
152+
- name: Set up Docker Buildx
153+
id: buildx
154+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
155+
with:
156+
version: latest
157+
platforms: ${{ env.PLATFORMS }}
158+
- name: Login to GitHub Container Registry
159+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
160+
with:
161+
username: ${{ secrets.DOCKERHUB_USERNAME }}
162+
password: ${{ secrets.DOCKERHUB_TOKEN }}
163+
- name: build-image
164+
run: |
165+
export TAG=$(cat images/nginx-1.25/TAG)
166+
cd images/nginx-1.25/rootfs && docker buildx build --platform=${{ env.PLATFORMS }} --push --load -t ingressnginx/nginx-1.25:${TAG} .
167+

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ image: clean-image ## Build image for a particular arch.
6868
docker build \
6969
${PLATFORM_FLAG} ${PLATFORM} \
7070
--no-cache \
71-
--pull \
7271
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \
7372
--build-arg VERSION="$(TAG)" \
7473
--build-arg TARGETARCH="$(ARCH)" \
@@ -85,7 +84,6 @@ image-chroot: clean-chroot-image ## Build image for a particular arch.
8584
echo "Building docker image ($(ARCH))..."
8685
docker build \
8786
--no-cache \
88-
--pull \
8987
--build-arg BASE_IMAGE="$(BASE_IMAGE)" \
9088
--build-arg VERSION="$(TAG)" \
9189
--build-arg TARGETARCH="$(ARCH)" \

images/nginx-1.25/Makefile

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2024 The Kubernetes Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
.DEFAULT_GOAL:=build
16+
17+
# set default shell
18+
SHELL=/bin/bash -o pipefail -o errexit
19+
20+
DIR:=$(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
21+
INIT_BUILDX=$(DIR)/../../hack/init-buildx.sh
22+
23+
# 0.0.0 shouldn't clobber any released builds
24+
SHORT_SHA ?=$(shell git rev-parse --short HEAD)
25+
TAG ?=v$(shell date +%Y%m%d)-$(SHORT_SHA)
26+
27+
REGISTRY ?= gcr.io/k8s-staging-ingress-nginx
28+
29+
IMAGE = $(REGISTRY)/nginx
30+
31+
# required to enable buildx
32+
export DOCKER_CLI_EXPERIMENTAL=enabled
33+
34+
# build with buildx
35+
PLATFORMS?=linux/amd64,linux/arm,linux/arm64,linux/s390x
36+
OUTPUT=
37+
PROGRESS=plain
38+
build: ensure-buildx
39+
docker buildx build \
40+
--platform=${PLATFORMS} $(OUTPUT) \
41+
--progress=$(PROGRESS) \
42+
--pull \
43+
--tag $(IMAGE):$(TAG) rootfs
44+
45+
# push the cross built image
46+
push: OUTPUT=--push
47+
push: build
48+
49+
# enable buildx
50+
ensure-buildx:
51+
# this is required for cloudbuild
52+
ifeq ("$(wildcard $(INIT_BUILDX))","")
53+
@curl -sSL https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/hack/init-buildx.sh | bash
54+
else
55+
@exec $(INIT_BUILDX)
56+
endif
57+
@echo "done"
58+
59+
.PHONY: build push ensure-buildx

images/nginx-1.25/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NGINX 1.25 base image
2+
3+
**Don't use in production!!!**

images/nginx-1.25/TAG

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.1

images/nginx-1.25/cloudbuild.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
timeout: 10800s
2+
options:
3+
substitution_option: ALLOW_LOOSE
4+
# job builds a multi-arch docker image for amd64,arm,arm64 and s390x.
5+
machineType: E2_HIGHCPU_32
6+
steps:
7+
- name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20211118-2f2d816b90'
8+
entrypoint: bash
9+
env:
10+
- DOCKER_CLI_EXPERIMENTAL=enabled
11+
- REGISTRY=gcr.io/k8s-staging-ingress-nginx
12+
- HOME=/root
13+
args:
14+
- -c
15+
- |
16+
gcloud auth configure-docker \
17+
&& cd images/nginx-1.25 && make push

images/nginx-1.25/rootfs/Dockerfile

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2024 The Kubernetes Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
FROM alpine:3.19.0 as builder
15+
16+
COPY . /
17+
18+
RUN apk update \
19+
&& apk upgrade \
20+
&& apk add -U bash --no-cache \
21+
&& /build.sh
22+
23+
# Use a multi-stage build
24+
FROM alpine:3.19.0
25+
26+
ENV PATH=$PATH:/usr/local/luajit/bin:/usr/local/nginx/sbin:/usr/local/nginx/bin
27+
28+
ENV LUA_PATH="/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/lib/lua/?.lua;;"
29+
ENV LUA_CPATH="/usr/local/lib/lua/?/?.so;/usr/local/lib/lua/?.so;;"
30+
31+
COPY --from=builder /usr/local /usr/local
32+
COPY --from=builder /opt /opt
33+
COPY --from=builder /etc/nginx /etc/nginx
34+
35+
RUN apk update \
36+
&& apk upgrade \
37+
&& apk add -U --no-cache \
38+
bash \
39+
openssl \
40+
pcre \
41+
zlib \
42+
ca-certificates \
43+
patch \
44+
yajl \
45+
lmdb \
46+
libxml2 \
47+
libmaxminddb \
48+
yaml-cpp \
49+
dumb-init \
50+
tzdata \
51+
&& ln -s /usr/local/nginx/sbin/nginx /sbin/nginx \
52+
&& adduser -S -D -H -u 101 -h /usr/local/nginx \
53+
-s /sbin/nologin -G www-data -g www-data www-data \
54+
&& bash -eu -c ' \
55+
writeDirs=( \
56+
/var/log/nginx \
57+
/var/lib/nginx/body \
58+
/var/lib/nginx/fastcgi \
59+
/var/lib/nginx/proxy \
60+
/var/lib/nginx/scgi \
61+
/var/lib/nginx/uwsgi \
62+
/var/log/audit \
63+
); \
64+
for dir in "${writeDirs[@]}"; do \
65+
mkdir -p ${dir}; \
66+
chown -R www-data.www-data ${dir}; \
67+
done'
68+
69+
EXPOSE 80 443
70+
71+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)