Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx docker build #8

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Dockerfiles/Dockerfile.latest
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <[email protected]>" \
repo="https://github.com/cytopia/docker-phpcbf"
Expand Down
33 changes: 13 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ include $(MAKEFILES)
# Set default Target
.DEFAULT_GOAL := help

DOCKER_PULL_VARIABLES = PHP_IMG_TAG=$(PHP_IMG_TAG)


# -------------------------------------------------------------------------------------------------
# Default configuration
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -224,14 +217,14 @@ _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' \
| grep -Eo '[.0-9]+' \
| sort -u \
| tail -1; \
else \
echo $(PHP); \
echo $(PHP_VERSION); \
fi; \
))