From d52a0556949197264e0b38344b8c7c39a2701eea Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 31 Oct 2022 13:05:18 +0100 Subject: [PATCH 1/7] Alpine based images with /bin/ash support --- Dockerfiles/Dockerfile.latest | 7 +++---- Makefile | 14 ++++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest index 16809d3..fff955b 100644 --- a/Dockerfiles/Dockerfile.latest +++ b/Dockerfiles/Dockerfile.latest @@ -1,10 +1,9 @@ ARG PHP_VERSION -FROM php:${PHP_VERSION} as builder +FROM php:${PHP_VERSION}alpine 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 \ curl \ git \ @@ -23,7 +22,7 @@ RUN set -eux \ && mv /phpcs.phar /usr/bin/phpcs -FROM php:${PHP_VERSION} as production +FROM php:${PHP_VERSION}alpine as production LABEL \ maintainer="cytopia " \ repo="https://github.com/cytopia/docker-phpcs" diff --git a/Makefile b/Makefile index e8fe092..2ef88cf 100644 --- a/Makefile +++ b/Makefile @@ -35,9 +35,11 @@ DIR = Dockerfiles ifeq ($(strip $(VERSION)),latest) PHP_VERSION = latest PCS_VERSION = latest + IMG_VERSION = "" else PHP_VERSION = $(subst PHP-,,$(shell echo "$(VERSION)" | grep -Eo 'PHP-([.0-9]+|latest)')) PCS_VERSION = $(subst PCS-,,$(shell echo "$(VERSION)" | grep -Eo 'PCS-([.0-9]+|latest)')) + IMG_VERSION = $(PHP_VERSION)- endif # Building from master branch: Tag == 'latest' @@ -89,10 +91,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 @@ -120,8 +118,8 @@ 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 \ + @echo "docker pull --platform $(ARCH) php:$(IMG_VERSION)alpine"; \ + while ! docker pull --platform $(ARCH) php:$(IMG_VERSION)alpine; do sleep 1; done \ # ------------------------------------------------------------------------------------------------- @@ -129,12 +127,12 @@ docker-pull-base-image: # ------------------------------------------------------------------------------------------------- .PHONY: build build: ARGS+=--build-arg PCS_VERSION=$(PCS_VERSION) -build: ARGS+=--build-arg PHP_VERSION=$(PHP_VERSION) +build: ARGS+=--build-arg PHP_VERSION=$(IMG_VERSION) build: docker-arch-build .PHONY: rebuild rebuild: ARGS+=--build-arg PCS_VERSION=$(PCS_VERSION) -rebuild: ARGS+=--build-arg PHP_VERSION=$(PHP_VERSION) +rebuild: ARGS+=--build-arg PHP_VERSION=$(IMG_VERSION) rebuild: docker-arch-rebuild .PHONY: push From 045603f86a136e1642a9941773b65a2bdde0410c Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 31 Oct 2022 13:28:25 +0100 Subject: [PATCH 2/7] Use cli-alpine images --- Dockerfiles/Dockerfile.latest | 4 ++-- Makefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest index fff955b..503b41a 100644 --- a/Dockerfiles/Dockerfile.latest +++ b/Dockerfiles/Dockerfile.latest @@ -1,5 +1,5 @@ ARG PHP_VERSION -FROM php:${PHP_VERSION}alpine as builder +FROM php:${PHP_VERSION}cli-alpine as builder # Install build dependencies RUN set -eux \ @@ -22,7 +22,7 @@ RUN set -eux \ && mv /phpcs.phar /usr/bin/phpcs -FROM php:${PHP_VERSION}alpine as production +FROM php:${PHP_VERSION}cli-alpine as production LABEL \ maintainer="cytopia " \ repo="https://github.com/cytopia/docker-phpcs" diff --git a/Makefile b/Makefile index 2ef88cf..ce67626 100644 --- a/Makefile +++ b/Makefile @@ -118,8 +118,8 @@ docker-pull-base-image: @echo "################################################################################" @echo "# Pulling Base Image php:$(PHP_VERSION) (platform: $(ARCH))" @echo "################################################################################" - @echo "docker pull --platform $(ARCH) php:$(IMG_VERSION)alpine"; \ - while ! docker pull --platform $(ARCH) php:$(IMG_VERSION)alpine; do sleep 1; done \ + @echo "docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine"; \ + while ! docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine; do sleep 1; done \ # ------------------------------------------------------------------------------------------------- From 54d54c171078b1501740487d36c157e7e67b9587 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 1 Nov 2022 10:47:25 +0100 Subject: [PATCH 3/7] Ensure coreutils is present for 'sort -V' --- Dockerfiles/Dockerfile.latest | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfiles/Dockerfile.latest b/Dockerfiles/Dockerfile.latest index 503b41a..7860ddd 100644 --- a/Dockerfiles/Dockerfile.latest +++ b/Dockerfiles/Dockerfile.latest @@ -5,6 +5,8 @@ FROM php:${PHP_VERSION}cli-alpine as builder RUN set -eux \ && apk add --no-cache \ ca-certificates \ + # coreutils add 'sort -V' + coreutils \ curl \ git \ && git clone https://github.com/squizlabs/PHP_CodeSniffer @@ -19,7 +21,9 @@ RUN set -eux \ fi \ && curl -sS -L https://github.com/squizlabs/PHP_CodeSniffer/releases/download/${VERSION}/phpcs.phar -o /phpcs.phar \ && chmod +x /phpcs.phar \ - && mv /phpcs.phar /usr/bin/phpcs + && mv /phpcs.phar /usr/bin/phpcs \ + \ + && phpcs --version FROM php:${PHP_VERSION}cli-alpine as production From b2979a1a75cecf51028eca905070d790a87ac883 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 1 Nov 2022 10:47:45 +0100 Subject: [PATCH 4/7] Show correct base image being pulled --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ce67626..240ec03 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ help: .PHONY: docker-pull-base-image docker-pull-base-image: @echo "################################################################################" - @echo "# Pulling Base Image php:$(PHP_VERSION) (platform: $(ARCH))" + @echo "# Pulling Base Image php:$(IMG_VERSION)cli-alpine (platform: $(ARCH))" @echo "################################################################################" @echo "docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine"; \ while ! docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine; do sleep 1; done \ From f8ef01e9117872551f784a0cf440949ccd1a66d2 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 1 Nov 2022 10:52:33 +0100 Subject: [PATCH 5/7] Adjust nightly schedule --- .github/workflows/action_schedule.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/action_schedule.yml b/.github/workflows/action_schedule.yml index c25dfa2..e65ecbb 100644 --- a/.github/workflows/action_schedule.yml +++ b/.github/workflows/action_schedule.yml @@ -10,9 +10,9 @@ name: nightly # When to run # ------------------------------------------------------------------------------------------------- on: - # Runs daily schedule: - - cron: '0 0 * * *' + # Sundays and Wednesdays at 0:00 + - cron: '0 0 * * 0,3' jobs: From 75af12c155855ae4d4ec9cf51f8025991c11e435 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 1 Nov 2022 11:11:54 +0100 Subject: [PATCH 6/7] Revert schedule --- .github/workflows/action_schedule.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/action_schedule.yml b/.github/workflows/action_schedule.yml index e65ecbb..c25dfa2 100644 --- a/.github/workflows/action_schedule.yml +++ b/.github/workflows/action_schedule.yml @@ -10,9 +10,9 @@ name: nightly # When to run # ------------------------------------------------------------------------------------------------- on: + # Runs daily schedule: - # Sundays and Wednesdays at 0:00 - - cron: '0 0 * * 0,3' + - cron: '0 0 * * *' jobs: From b3164c9cc0ea9b791cd73bcbee0b89db8937c4da Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 1 Nov 2022 11:37:40 +0100 Subject: [PATCH 7/7] Pull correct IMG version --- Makefile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 240ec03..50e8efd 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,11 @@ else IMG_VERSION = $(PHP_VERSION)- endif +# Extract Image version +ifeq ($(strip $(PHP_VERSION)),latest) + IMG_VERSION = "" +endif + # Building from master branch: Tag == 'latest' ifeq ($(strip $(TAG)),latest) ifeq ($(strip $(VERSION)),latest) @@ -119,7 +124,17 @@ docker-pull-base-image: @echo "# Pulling Base Image php:$(IMG_VERSION)cli-alpine (platform: $(ARCH))" @echo "################################################################################" @echo "docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine"; \ - while ! docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine; do sleep 1; done \ + SUCC=0; \ + for count in $$(seq 10); do \ + if docker pull --platform $(ARCH) php:$(IMG_VERSION)cli-alpine; then \ + SUCC=1; \ + break; \ + fi; \ + done; \ + if [ "$${SUCC}" != "1" ]; then \ + echo "Failed."; \ + exit 1; \ + fi; # -------------------------------------------------------------------------------------------------