Skip to content

Commit c056ad1

Browse files
committed
Docker: made dockerfiles use a single stage build process.
1 parent fec469d commit c056ad1

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

pkg/docker/Makefile

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,49 @@ VERSION_minimal ?=
1515
CONTAINER_minimal ?= debian:bullseye-slim
1616
CONFIGURE_minimal ?=
1717
INSTALL_minimal ?= version
18-
define COPY_minimal
19-
endef
18+
RUN_minimal ?= /bin/true
2019

2120
VERSION_go ?= 1.19
2221
CONTAINER_go ?= golang:$(VERSION_go)
2322
CONFIGURE_go ?= go --go-path=$$GOPATH
2423
INSTALL_go ?= go-install-src libunit-install
25-
define COPY_go
26-
COPY --from=BUILDER /usr/lib/\*-linux-gnu/libunit.a /tmp/\n\$
27-
COPY --from=BUILDER /usr/include/nxt_* /usr/include/\n\$
28-
COPY --from=BUILDER /go/src/ /go/src/
29-
endef
24+
RUN_go ?= /bin/true
3025

3126
VERSION_jsc ?= 11
3227
CONTAINER_jsc ?= eclipse-temurin:$(VERSION_jsc)-jdk
3328
CONFIGURE_jsc ?= java --jars=/usr/share/unit-jsc-common/
3429
INSTALL_jsc ?= java-shared-install java-install
35-
COPY_jsc = COPY --from=BUILDER /usr/share/unit-jsc-common/ /usr/share/unit-jsc-common/
30+
RUN_jsc ?= /bin/true
3631

3732
VERSION_node ?= 18
3833
CONTAINER_node ?= node:$(VERSION_node)
3934
CONFIGURE_node ?= nodejs --node-gyp=/usr/local/lib/node_modules/npm/bin/node-gyp-bin/node-gyp
4035
INSTALL_node ?= node node-install libunit-install
41-
define COPY_node
42-
COPY --from=BUILDER /usr/lib/\*-linux-gnu/libunit.a /tmp/\n\$
43-
COPY --from=BUILDER /usr/include/nxt_* /usr/include/\n\$
44-
COPY --from=BUILDER /usr/local/lib/node_modules/unit-http/ /usr/local/lib/node_modules/unit-http/
45-
endef
36+
RUN_node ?= /bin/true
4637

4738
VERSION_perl ?= 5.36
4839
CONTAINER_perl ?= perl:$(VERSION_perl)
4940
CONFIGURE_perl ?= perl
5041
INSTALL_perl ?= perl-install
51-
COPY_perl =
42+
RUN_perl ?= /bin/true
5243

5344
VERSION_php ?= 8.1
5445
CONTAINER_php ?= php:$(VERSION_php)-cli
5546
CONFIGURE_php ?= php
5647
INSTALL_php ?= php-install
57-
COPY_php = RUN ldconfig
48+
RUN_php ?= ldconfig
5849

5950
VERSION_python ?= 3.11
6051
CONTAINER_python ?= python:$(VERSION_python)
6152
CONFIGURE_python ?= python --config=/usr/local/bin/python3-config
6253
INSTALL_python ?= python3-install
63-
COPY_python =
54+
RUN_python ?= /bin/true
6455

6556
VERSION_ruby ?= 3.1
6657
CONTAINER_ruby ?= ruby:$(VERSION_ruby)
6758
CONFIGURE_ruby ?= ruby
6859
INSTALL_ruby ?= ruby-install
69-
COPY_ruby = RUN gem install rack
60+
RUN_ruby ?= gem install rack
7061

7162
default:
7263
@echo "valid targets: all build dockerfiles clean"
@@ -78,14 +69,14 @@ modname = $(shell echo $1 | /usr/bin/tr -d '.01234567890-')
7869
dockerfiles: $(addprefix Dockerfile., $(MODVERSIONS))
7970
build: $(addprefix build-,$(MODVERSIONS))
8071

81-
Dockerfile.%: ../../version
72+
Dockerfile.%: ../../version template.Dockerfile
8273
@echo "===> Building $@"
8374
cat template.Dockerfile | sed \
8475
-e 's,@@VERSION@@,$(VERSION),g' \
8576
-e 's,@@CONTAINER@@,$(CONTAINER_$(call modname, $*)),g' \
8677
-e 's,@@CONFIGURE@@,$(CONFIGURE_$(call modname, $*)),g' \
8778
-e 's,@@INSTALL@@,$(INSTALL_$(call modname, $*)),g' \
88-
-e 's,@@COPY@@,$(COPY_$(call modname, $*)),g' \
79+
-e 's,@@RUN@@,$(RUN_$(call modname, $*)),g' \
8980
> $@
9081

9182
build-%: Dockerfile.%

pkg/docker/template.Dockerfile

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM @@CONTAINER@@ as BUILDER
33
LABEL maintainer="NGINX Docker Maintainers <[email protected]>"
44

55
RUN set -ex \
6+
&& savedAptMark="$(apt-mark showmanual)" \
67
&& apt-get update \
78
&& apt-get install --no-install-recommends --no-install-suggests -y ca-certificates mercurial build-essential libssl-dev libpcre2-dev \
89
&& mkdir -p /usr/lib/unit/modules /usr/lib/unit/debug-modules \
@@ -38,20 +39,12 @@ RUN set -ex \
3839
&& ./configure $CONFIGURE_ARGS --cc-opt="$CC_OPT" --modules=/usr/lib/unit/modules \
3940
&& ./configure @@CONFIGURE@@ \
4041
&& make -j $NCPU @@INSTALL@@ \
41-
&& ldd /usr/sbin/unitd | awk '/=>/{print $(NF-1)}' | while read n; do dpkg-query -S $n; done | sed 's/^\([^:]\+\):.*$/\1/' | sort | uniq > /requirements.apt
42-
43-
FROM @@CONTAINER@@
44-
COPY docker-entrypoint.sh /usr/local/bin/
45-
COPY --from=BUILDER /usr/sbin/unitd /usr/sbin/unitd
46-
COPY --from=BUILDER /usr/sbin/unitd-debug /usr/sbin/unitd-debug
47-
COPY --from=BUILDER /usr/lib/unit/ /usr/lib/unit/
48-
COPY --from=BUILDER /requirements.apt /requirements.apt
49-
@@COPY@@
50-
RUN set -x \
51-
&& if [ -f "/tmp/libunit.a" ]; then \
52-
mv /tmp/libunit.a /usr/lib/$(dpkg-architecture -q DEB_HOST_MULTIARCH)/libunit.a; \
53-
rm -f /tmp/libunit.a; \
54-
fi \
42+
&& for f in /usr/sbin/unitd /usr/lib/unit/modules/*.unit.so; do \
43+
ldd $f | awk '/=>/{print $(NF-1)}' | while read n; do dpkg-query -S $n; done | sed 's/^\([^:]\+\):.*$/\1/' | sort | uniq >> /requirements.apt; \
44+
done \
45+
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
46+
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
47+
&& @@RUN@@ \
5548
&& mkdir -p /var/lib/unit/ \
5649
&& mkdir /docker-entrypoint.d/ \
5750
&& addgroup --system unit \
@@ -64,12 +57,15 @@ RUN set -x \
6457
--gecos "unit user" \
6558
--shell /bin/false \
6659
unit \
67-
&& apt update \
68-
&& apt --no-install-recommends --no-install-suggests -y install curl $(cat /requirements.apt) \
60+
&& apt-get update \
61+
&& apt-get --no-install-recommends --no-install-suggests -y install curl $(cat /requirements.apt) \
62+
&& apt-get purge -y --auto-remove \
6963
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
7064
&& rm -f /requirements.apt \
7165
&& ln -sf /dev/stdout /var/log/unit.log
7266

67+
COPY docker-entrypoint.sh /usr/local/bin/
68+
7369
STOPSIGNAL SIGTERM
7470

7571
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

0 commit comments

Comments
 (0)