From 57e97cb3fb2d429f74d6e485f2b328324f07e800 Mon Sep 17 00:00:00 2001 From: Wanderson Camargo Date: Fri, 6 Aug 2021 20:56:26 -0300 Subject: [PATCH] Separate base image --- Base.Dockerfile | 31 +++++++++++++++++++++++++++++++ Dockerfile | 34 +++------------------------------- Makefile | 12 +++++++++--- 3 files changed, 43 insertions(+), 34 deletions(-) create mode 100644 Base.Dockerfile diff --git a/Base.Dockerfile b/Base.Dockerfile new file mode 100644 index 0000000..45ab847 --- /dev/null +++ b/Base.Dockerfile @@ -0,0 +1,31 @@ +FROM alpine:3.14 AS builder + +ARG PHP_VERSION + +WORKDIR /usr/src/php + +RUN wget -q https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz \ + && tar --strip-components 1 -xzf php-${PHP_VERSION}.tar.gz \ + && rm php-${PHP_VERSION}.tar.gz + +RUN apk add --no-cache \ + alpine-sdk \ + autoconf \ + automake \ + libc6-compat \ + libtool \ + && apk add --no-cache \ + bison \ + re2c \ + && ./buildconf --force + +RUN ./configure --disable-all \ + --disable-cgi \ + --disable-debug --disable-phpdbg \ + --with-config-file-path="/usr/local/etc/php" \ + --with-config-file-scan-dir="/usr/local/etc/php/conf.d" \ + CFLAGS="-O3 -march=native" \ + && sed -i 's/-export-dynamic/-all-static/g' Makefile + +RUN make \ + && make install diff --git a/Dockerfile b/Dockerfile index b45728d..4467b88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,13 @@ -FROM alpine:3.14 AS builder +ARG DOCKER_IMAGE_TAG -ARG PHP_VERSION - -WORKDIR /usr/src/php - -RUN wget -q https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz \ - && tar --strip-components 1 -xzf php-${PHP_VERSION}.tar.gz \ - && rm php-${PHP_VERSION}.tar.gz - -RUN apk add --no-cache \ - alpine-sdk \ - autoconf \ - automake \ - libc6-compat \ - libtool \ - && apk add --no-cache \ - bison \ - re2c \ - && ./buildconf --force - -RUN ./configure --disable-all \ - --disable-cgi \ - --disable-debug --disable-phpdbg \ - --with-config-file-path="/usr/local/etc/php" \ - --with-config-file-scan-dir="/usr/local/etc/php/conf.d" \ - CFLAGS="-O3 -march=native" \ - && sed -i 's/-export-dynamic/-all-static/g' Makefile - -RUN make \ - && make install +FROM ${DOCKER_IMAGE_TAG} AS base RUN apk add --no-cache upx \ && upx --best /usr/local/bin/php FROM scratch -COPY --from=builder /usr/local/bin/php /usr/local/bin/php +COPY --from=base /usr/local/bin/php /usr/local/bin/php ENTRYPOINT ["/usr/local/bin/php"] diff --git a/Makefile b/Makefile index 349fd04..4e371de 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,19 @@ PHP_VERSION=8.0.9 .PHONY: all all: build +.PHONY: base +base: + docker build . \ + --file Base.Dockerfile \ + --build-arg PHP_VERSION=${PHP_VERSION} \ + --tag wandersonwhcr/php-smallest:${GIT_SHA_SHORT}-base + .PHONY: build -build: +build: base docker build . \ --file Dockerfile \ - --build-arg PHP_VERSION=${PHP_VERSION} \ + --build-arg DOCKER_IMAGE_TAG=wandersonwhcr/php-smallest:${GIT_SHA_SHORT}-base \ --tag wandersonwhcr/php-smallest:${GIT_SHA_SHORT} - docker tag wandersonwhcr/php-smallest:${GIT_SHA_SHORT} wandersonwhcr/php-smallest:latest .PHONY: size size: build