mirror of https://github.com/deuill/go-php.git
Unify Dockerfiles for easier testing across PHP versions
All PHP builds in Docker are now made against a single-unified Dockerfile, which accepts the PHP version to target in the `PHP_VERSION` argument. Source files are currently not verified (other than being downloaded from a secure location, as we will eventually move to using the official `php` Docker images as a base, as soon as these catch up to latest versions of Debian.
This commit is contained in:
parent
a6232d9fa8
commit
cd1c76d08e
|
@ -1,34 +1,29 @@
|
|||
FROM debian:stable-slim
|
||||
|
||||
ENV PHP_VERSION="5.6.31"
|
||||
ENV PHP_URL="https://secure.php.net/get/php-${PHP_VERSION}.tar.xz/from/this/mirror" PHP_ASC_URL="https://secure.php.net/get/php-${PHP_VERSION}.tar.xz.asc/from/this/mirror"
|
||||
# The full PHP version to target, i.e. "7.1.10".
|
||||
ARG PHP_VERSION
|
||||
|
||||
# Environment variables used across the build.
|
||||
ENV PHP_URL="https://secure.php.net/get/php-${PHP_VERSION}.tar.xz/from/this/mirror" PHP_ASC_URL="https://secure.php.net/get/php-${PHP_VERSION}.tar.xz.asc/from/this/mirror"
|
||||
ENV PHP_BASE_DIR="/tmp/php"
|
||||
ENV PHP_SRC_DIR="${PHP_BASE_DIR}/src"
|
||||
|
||||
# Build variables.
|
||||
ENV PHP_LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie"
|
||||
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2"
|
||||
ENV PHP_CPPFLAGS="${PHP_CFLAGS}"
|
||||
|
||||
ENV GPG_KEYS="0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3"
|
||||
ENV PHP_SHA256="c464af61240a9b7729fabe0314cdbdd5a000a4f0c9bd201f89f8628732fe4ae4"
|
||||
|
||||
ENV FETCH_DEPS="ca-certificates wget dirmngr gnupg2"
|
||||
|
||||
# Fetch PHP source code. This step does not currently validate keys or checksums, as this process
|
||||
# will eventually transition to using the base `php` Docker images.
|
||||
ENV FETCH_DEPS="ca-certificates wget"
|
||||
RUN set -xe && \
|
||||
apt-get update && apt-get install -y --no-install-recommends ${FETCH_DEPS} && \
|
||||
mkdir -p ${PHP_BASE_DIR} && cd ${PHP_BASE_DIR} && \
|
||||
wget -O php.tar.xz ${PHP_URL} && \
|
||||
echo "${PHP_SHA256} *php.tar.xz" | sha256sum -c - && \
|
||||
wget -O php.tar.xz.asc "${PHP_ASC_URL}" && \
|
||||
export GNUPGHOME="$(mktemp -d)" && \
|
||||
for key in ${GPG_KEYS}; do gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; done && \
|
||||
gpg --batch --verify php.tar.xz.asc php.tar.xz && \
|
||||
rm -Rf ${GNUPGHOME} && \
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false ${FETCH_DEPS}
|
||||
|
||||
# Build PHP library from source.
|
||||
ENV BUILD_DEPS="build-essential file libpcre3-dev dpkg-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libssl1.0-dev libxml2-dev zlib1g-dev"
|
||||
|
||||
RUN set -xe && \
|
||||
apt-get update && apt-get install -y --no-install-recommends ${BUILD_DEPS} && \
|
||||
export CFLAGS="${PHP_CFLAGS}" CPPFLAGS="${PHP_CPPFLAGS}" LDFLAGS="${PHP_LDFLAGS}" && \
|
||||
|
@ -49,6 +44,7 @@ RUN set -xe && \
|
|||
make -j "$(nproc)" && \
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false ${BUILD_DEPS}
|
||||
|
||||
# Install runtime dependencies for testing, building packages etc, and clean up source.
|
||||
ENV RUNTIME_DEPS="build-essential git golang curl libedit2 libssl1.0 libxml2"
|
||||
ENV SOURCE_REPO="github.com/deuill/go-php"
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
FROM debian:stable-slim
|
||||
|
||||
ENV PHP_VERSION="7.1.10"
|
||||
ENV PHP_URL="https://secure.php.net/get/php-${PHP_VERSION}.tar.xz/from/this/mirror" PHP_ASC_URL="https://secure.php.net/get/php-${PHP_VERSION}.tar.xz.asc/from/this/mirror"
|
||||
|
||||
ENV PHP_BASE_DIR="/tmp/php"
|
||||
ENV PHP_SRC_DIR="${PHP_BASE_DIR}/src"
|
||||
|
||||
ENV PHP_LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie"
|
||||
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2"
|
||||
ENV PHP_CPPFLAGS="${PHP_CFLAGS}"
|
||||
|
||||
ENV GPG_KEYS="A917B1ECDA84AEC2B568FED6F50ABC807BD5DCD0 528995BFEDFBA7191D46839EF9BA0ADA31CBD89E"
|
||||
ENV PHP_SHA256="2b8efa771a2ead0bb3ae67b530ca505b5b286adc873cca9ce97a6e1d6815c50b"
|
||||
|
||||
ENV FETCH_DEPS="ca-certificates wget dirmngr gnupg2"
|
||||
|
||||
RUN set -xe && \
|
||||
apt-get update && apt-get install -y --no-install-recommends ${FETCH_DEPS} && \
|
||||
mkdir -p ${PHP_BASE_DIR} && cd ${PHP_BASE_DIR} && \
|
||||
wget -O php.tar.xz ${PHP_URL} && \
|
||||
echo "${PHP_SHA256} *php.tar.xz" | sha256sum -c - && \
|
||||
wget -O php.tar.xz.asc "${PHP_ASC_URL}" && \
|
||||
export GNUPGHOME="$(mktemp -d)" && \
|
||||
for key in ${GPG_KEYS}; do gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; done && \
|
||||
gpg --batch --verify php.tar.xz.asc php.tar.xz && \
|
||||
rm -Rf ${GNUPGHOME} && \
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false ${FETCH_DEPS}
|
||||
|
||||
ENV BUILD_DEPS="build-essential file libpcre3-dev dpkg-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libssl-dev libxml2-dev zlib1g-dev"
|
||||
|
||||
RUN set -xe && \
|
||||
apt-get update && apt-get install -y --no-install-recommends ${BUILD_DEPS} && \
|
||||
export CFLAGS="${PHP_CFLAGS}" CPPFLAGS="${PHP_CPPFLAGS}" LDFLAGS="${PHP_LDFLAGS}" && \
|
||||
arch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" && multiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)" && \
|
||||
if [ ! -d /usr/include/curl ]; \
|
||||
then ln -sT "/usr/include/$multiarch/curl" /usr/local/include/curl; \
|
||||
fi && \
|
||||
mkdir -p ${PHP_SRC_DIR} && cd ${PHP_SRC_DIR} && \
|
||||
tar -xJf ${PHP_BASE_DIR}/php.tar.xz -C . --strip-components=1 && \
|
||||
./configure \
|
||||
--prefix=/usr --build="$arch" \
|
||||
--with-libdir="lib/$multiarch" \
|
||||
--with-pcre-regex=/usr \
|
||||
--disable-cgi --disable-fpm \
|
||||
--enable-embed --enable-ftp --enable-mbstring \
|
||||
--with-curl --with-libedit --with-openssl --with-zlib \
|
||||
&& \
|
||||
make -j "$(nproc)" && \
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false ${BUILD_DEPS}
|
||||
|
||||
ENV RUNTIME_DEPS="build-essential git golang curl libedit2 libssl1.1 libxml2"
|
||||
ENV SOURCE_REPO="github.com/deuill/go-php"
|
||||
|
||||
RUN set -xe && \
|
||||
apt-get update && apt-get install -y --no-install-recommends ${RUNTIME_DEPS} && \
|
||||
cd ${PHP_SRC_DIR} && make -j "$(nproc)" PHP_SAPI=embed install-sapi install-headers && \
|
||||
cd / && rm -Rf ${PHP_BASE_DIR} ${PHP_SRC_DIR}
|
||||
|
||||
ENTRYPOINT ["/bin/sh", "-c"]
|
19
Makefile
19
Makefile
|
@ -5,11 +5,14 @@ IMPORT_PATH := github.com/deuill/$(NAME)
|
|||
VERSION := $(shell git describe --tags --always --dirty="-dev")
|
||||
DATE := $(shell date '+%Y-%m-%d-%H%M UTC')
|
||||
|
||||
# Build options.
|
||||
# Generic build options.
|
||||
BUILD_OPTIONS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
|
||||
PACKAGE_FORMAT := tar.xz
|
||||
PHP_VERSION := php7
|
||||
GO := go
|
||||
PHP_VERSION := 7.1.10
|
||||
|
||||
# Go build options.
|
||||
GO := go
|
||||
TAGS := -tags 'php$(word 1,$(subst ., ,$(PHP_VERSION)))'
|
||||
|
||||
# Install options.
|
||||
PREFIX := /usr
|
||||
|
@ -22,7 +25,7 @@ all: $(NAME)
|
|||
|
||||
$(NAME): .build/env/GOPATH/.ok
|
||||
@echo "Building '$(NAME)'..."
|
||||
$Q $(GO) install $(if $(VERBOSE),-v) $(BUILD_OPTIONS) $(IMPORT_PATH)
|
||||
$Q $(GO) install $(if $(VERBOSE),-v) $(TAGS) $(BUILD_OPTIONS) $(IMPORT_PATH)
|
||||
|
||||
## Print internal package list.
|
||||
list: .build/env/GOPATH/.ok
|
||||
|
@ -38,9 +41,9 @@ install: $(NAME)
|
|||
## Run test for all local packages or specified PACKAGE.
|
||||
test: .build/env/GOPATH/.ok
|
||||
@echo "Running tests for '$(NAME)'..."
|
||||
$Q $(GO) test -race $(if $(VERBOSE),-v) -tags $(PHP_VERSION) $(if $(PACKAGE),$(PACKAGE),$(PACKAGES))
|
||||
$Q $(GO) test -race $(if $(VERBOSE),-v) $(TAGS) $(if $(PACKAGE),$(PACKAGE),$(PACKAGES))
|
||||
@echo "Running 'vet' for '$(NAME)'..."
|
||||
$Q $(GO) vet $(if $(VERBOSE),-v) -tags $(PHP_VERSION) $(if $(PACKAGE),$(PACKAGE),$(PACKAGES))
|
||||
$Q $(GO) vet $(if $(VERBOSE),-v) $(TAGS) $(if $(PACKAGE),$(PACKAGE),$(PACKAGES))
|
||||
|
||||
## Create test coverage report for all local packages or specified PACKAGE.
|
||||
cover: .build/env/GOPATH/.ok
|
||||
|
@ -50,7 +53,7 @@ cover: .build/env/GOPATH/.ok
|
|||
name=`echo $$pkg.cover | tr '/' '.'`; \
|
||||
imports=`go list -f '{{ join .Imports " " }}' $$pkg`; \
|
||||
coverpkg=`echo "$$imports $(PACKAGES)" | tr ' ' '\n' | sort | uniq -d | tr '\n' ','`; \
|
||||
$(GO) test $(if $(VERBOSE),-v) -tags $(PHP_VERSION) -coverpkg $$coverpkg$$pkg -coverprofile .build/tmp/$$name $$pkg; done
|
||||
$(GO) test $(if $(VERBOSE),-v) $(TAGS) -coverpkg $$coverpkg$$pkg -coverprofile .build/tmp/$$name $$pkg; done
|
||||
$Q awk "$$COVERAGE_MERGE" .build/tmp/*.cover > .build/tmp/cover.merged
|
||||
$Q $(GO) tool cover -html .build/tmp/cover.merged -o .build/tmp/coverage.html
|
||||
@echo "Coverage report written to '.build/tmp/coverage.html'"
|
||||
|
@ -83,7 +86,7 @@ help:
|
|||
$Q $(MAKE) -s -f $(MAKEFILE) help
|
||||
|
||||
docker-image:
|
||||
$Q docker build -t "$(NAME):$(PHP_VERSION)" -f Dockerfile.$(PHP_VERSION) .
|
||||
$Q docker build --build-arg=PHP_VERSION=$(PHP_VERSION) -t "$(NAME):$(PHP_VERSION)" -f Dockerfile .
|
||||
|
||||
docker-test: docker-image
|
||||
$Q docker run --rm \
|
||||
|
|
Loading…
Reference in New Issue