Skip to content

Commit

Permalink
Separate base image
Browse files Browse the repository at this point in the history
  • Loading branch information
wandersonwhcr committed Aug 6, 2021
1 parent 7cb364b commit 57e97cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
31 changes: 31 additions & 0 deletions Base.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
34 changes: 3 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57e97cb

Please sign in to comment.