From 6999b1273617cd1e4f07d1fde169fdf36cf58964 Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 7 Nov 2022 16:52:38 +0100 Subject: [PATCH] FIx docker build --- Dockerfiles/Dockerfile.latest | 17 +++++++++++------ Makefile | 33 +++++++++++++-------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest index efecb23..3c546a6 100644 --- a/Dockerfiles/Dockerfile.latest +++ b/Dockerfiles/Dockerfile.latest @@ -1,11 +1,12 @@ -ARG PHP_VERSION -FROM php:${PHP_VERSION} as builder +ARG PHP_IMG_TAG +FROM php:${PHP_IMG_TAG} as builder # Install build dependencies RUN set -eux \ - && DEBIAN_FRONTEND=noninteractive apt-get update -qq \ - && DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \ + && apk add --no-cache \ ca-certificates \ + # coreutils add 'sort -V' + coreutils \ curl \ git \ && git clone https://github.com/squizlabs/PHP_CodeSniffer @@ -18,12 +19,16 @@ RUN set -eux \ else \ VERSION="$( git tag | grep -E "^v?${PBF_VERSION}\.[.0-9]+\$" | sort -V | tail -1 )"; \ fi \ + && echo "Version: ${VERSION}" \ && curl -sS -L https://github.com/squizlabs/PHP_CodeSniffer/releases/download/${VERSION}/phpcbf.phar -o /phpcbf.phar \ && chmod +x /phpcbf.phar \ - && mv /phpcbf.phar /usr/bin/phpcbf + && mv /phpcbf.phar /usr/bin/phpcbf \ + \ + && phpcbf --version -FROM php:${PHP_VERSION} as production +ARG PHP_IMG_TAG +FROM php:${PHP_IMG_TAG} as production LABEL \ maintainer="cytopia " \ repo="https://github.com/cytopia/docker-phpcbf" diff --git a/Makefile b/Makefile index a08e13a..74ad4f0 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ include $(MAKEFILES) # Set default Target .DEFAULT_GOAL := help +DOCKER_PULL_VARIABLES = PHP_IMG_TAG=$(PHP_IMG_TAG) + # ------------------------------------------------------------------------------------------------- # Default configuration @@ -35,9 +37,16 @@ DIR = Dockerfiles ifeq ($(strip $(VERSION)),latest) PHP_VERSION = latest PBF_VERSION = latest + PHP_IMG_TAG = "cli-alpine" else PHP_VERSION = $(subst PHP-,,$(shell echo "$(VERSION)" | grep -Eo 'PHP-([.0-9]+|latest)')) PBF_VERSION = $(subst PBF-,,$(shell echo "$(VERSION)" | grep -Eo 'PBF-([.0-9]+|latest)')) + PHP_IMG_TAG = $(PHP_VERSION)-cli-alpine +endif + +# Extract Image version +ifeq ($(strip $(PHP_VERSION)),latest) + PHP_IMG_TAG = "cli-alpine" endif # Building from master branch: Tag == 'latest' @@ -89,10 +98,6 @@ FL_IGNORES = .git/,.github/,tests/ SC_IGNORES = .git/,.github/,tests/ JL_IGNORES = .git/,.github/,./tests/ -out: - @echo "PHP: $(subst PHP-,,$(shell echo "$(VERSION)" | grep -Eo 'PHP-[.0-9]+'))" - @echo "PCS: $(subst PCS-,,$(shell echo "$(VERSION)" | grep -Eo 'PCS-[.0-9]+'))" - # ------------------------------------------------------------------------------------------------- # Default Target @@ -112,29 +117,17 @@ help: @echo -# ------------------------------------------------------------------------------------------------- -# Target Overrides -# ------------------------------------------------------------------------------------------------- -.PHONY: docker-pull-base-image -docker-pull-base-image: - @echo "################################################################################" - @echo "# Pulling Base Image php:$(PHP_VERSION) (platform: $(ARCH))" - @echo "################################################################################" - @echo "docker pull --platform $(ARCH) php:$(PHP_VERSION)"; \ - while ! docker pull --platform $(ARCH) php:$(PHP_VERSION); do sleep 1; done \ - - # ------------------------------------------------------------------------------------------------- # Docker Targets # ------------------------------------------------------------------------------------------------- .PHONY: build build: ARGS+=--build-arg PBF_VERSION=$(PBF_VERSION) -build: ARGS+=--build-arg PHP_VERSION=$(PHP_VERSION) +build: ARGS+=--build-arg PHP_IMG_TAG=$(PHP_IMG_TAG) build: docker-arch-build .PHONY: rebuild rebuild: ARGS+=--build-arg PBF_VERSION=$(PBF_VERSION) -rebuild: ARGS+=--build-arg PHP_VERSION=$(PHP_VERSION) +rebuild: ARGS+=--build-arg PHP_IMG_TAG=$(PHP_IMG_TAG) rebuild: docker-arch-rebuild .PHONY: push @@ -224,7 +217,7 @@ _test-run: .PHONY: _get-php-version _get-php-version: $(eval CURRENT_PHP_VERSION = $(shell \ - if [ "$(PHP)" = "latest" ]; then \ + if [ "$(PHP_VERSION)" = "latest" ]; then \ curl -L -sS https://hub.docker.com/api/content/v1/products/images/php \ | tac | tac \ | grep -Eo '`[.0-9]+-cli-alpine' \ @@ -232,6 +225,6 @@ _get-php-version: | sort -u \ | tail -1; \ else \ - echo $(PHP); \ + echo $(PHP_VERSION); \ fi; \ ))