Skip to content

Commit 54312dc

Browse files
authored
Call build scripts in the same layer they're needed (#143)
* Call build scripts in the same layer they're needed Each `RUN` instruction creates a new layer, so the removed stuff will still remain in the previous layer. This leads to huge image sizes. Before: 3.61GB, max. variant After: 2.78GB, max. variant The code style was slightly changed as well, in order to sort multi-line arguments. See: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#sort-multi-line-arguments * Merge `RUN` instructions * Enable BuildKit and trim whitespace
1 parent f1b3e3d commit 54312dc

File tree

3 files changed

+159
-84
lines changed

3 files changed

+159
-84
lines changed

.github/workflows/release.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,76 +59,74 @@ jobs:
5959
VERSION_OVERRIDE: "${{ matrix.version-override }}"
6060
run: |
6161
set -eux;
62-
62+
6363
if [[ "${{ matrix.tag }}" =~ ^v?1.[0-9x]+$ ]]; then
6464
imageVariants=("fpm" "debug" "supervisord")
65-
else
65+
else
6666
imageVariants=("min" "default" "max" "debug" "supervisord")
6767
fi
68-
69-
68+
69+
7070
for imageVariant in ${imageVariants[@]}; do
71-
71+
7272
echo "Building image variant $imageVariant"
73-
73+
7474
DOCKER_PLATFORMS=linux/amd64,linux/arm64
7575
PHP_VERSION=${{ matrix.php }}
7676
DEBIAN_VERSION="${{ matrix.distro }}"
7777
VERSION="${{ matrix.tag }}"
7878
# for the latest dev branch we use "dev" as the version and not the name of the branch
7979
if [ ! -z "$VERSION_OVERRIDE" ]; then
8080
VERSION="$VERSION_OVERRIDE"
81-
fi
82-
81+
fi
82+
8383
PHP_SUB_VERSION=$(docker run -i --rm php:${{ matrix.php }}-fpm-${{ matrix.distro }} php -r 'echo PHP_VERSION;')
84-
84+
8585
if [ "$imageVariant" = "fpm" ] || [ "$imageVariant" = "default" ]; then
8686
BASE_TAG="php${{ matrix.php }}"
8787
BASE_TAG_DETAILED="php${PHP_SUB_VERSION}"
8888
else
8989
BASE_TAG="php${{ matrix.php }}-$imageVariant"
9090
BASE_TAG_DETAILED="php${PHP_SUB_VERSION}-$imageVariant"
9191
fi
92-
92+
9393
# DEBUG / TEST
9494
#BASE_TAG="testv3-$BASE_TAG"
9595
#BASE_TAG_DETAILED="testv3-$BASE_TAG_DETAILED"
96-
97-
96+
97+
9898
TAG="${BASE_TAG}-${VERSION}"
9999
TAG_DETAILED="${BASE_TAG_DETAILED}-${VERSION}"
100100
TAGS="--tag ${IMAGE_NAME}:${TAG}"
101101
TAGS="$TAGS --tag ${IMAGE_NAME}:${TAG_DETAILED}"
102-
102+
103103
# Tag latest with Version build too
104104
if [ "true" = "${{ matrix.latest-tag }}" ]; then
105105
TAGS="$TAGS --tag ${IMAGE_NAME}:${BASE_TAG}-latest"
106-
fi
107-
106+
fi
107+
108108
# Create tag for major version
109109
if [[ $VERSION =~ ^v[0-9]+.[0-9]+$ ]]; then
110110
VERSION_MAJOR=${VERSION//.[0-9]/}
111111
TAGS="$TAGS --tag ${IMAGE_NAME}:${BASE_TAG}-${VERSION_MAJOR}"
112112
fi
113-
113+
114114
echo ${TAGS}
115-
116-
115+
116+
117117
docker buildx build --output "type=image,push=true" --platform ${DOCKER_PLATFORMS} \
118118
--target="pimcore_php_$imageVariant" \
119119
--build-arg PHP_VERSION="${PHP_VERSION}" \
120120
--build-arg DEBIAN_VERSION="${DEBIAN_VERSION}" \
121121
--cache-from "type=local,src=/tmp/.buildx-cache" \
122122
--cache-to "type=local,dest=/tmp/.buildx-cache-new" \
123123
${TAGS} .
124-
125-
docker buildx imagetools inspect ${IMAGE_NAME}:${TAG} || true;
124+
125+
docker buildx imagetools inspect ${IMAGE_NAME}:${TAG} || true;
126126
done
127-
127+
128128
129129
- name: Move cache
130130
run: |
131131
rm -rf /tmp/.buildx-cache
132132
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
133-
134-

.github/workflows/test.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
pull_request:
66

77
env:
8+
DOCKER_BUILDKIT: 1
89
IMAGE_NAME: pimcore/pimcore
910

1011
jobs:
@@ -19,12 +20,12 @@ jobs:
1920
- name: Build Image
2021
run: |
2122
set -ex
22-
23+
2324
imageVariants=("min" "default" "max" "debug" "supervisord")
24-
25+
2526
for imageVariant in ${imageVariants[@]}; do
2627
docker build --tag pimcore-image --target="pimcore_php_$imageVariant" --build-arg PHP_VERSION="${{ matrix.php }}" --build-arg DEBIAN_VERSION="${{ matrix.distro }}" .
27-
28+
2829
if [ "$imageVariant" == "debug" ]; then
2930
# Make sure xdebug is installed and configured on debug-build
3031
docker run --rm pimcore-image sh -c 'php -m | grep xdebug'
@@ -37,9 +38,9 @@ jobs:
3738
docker run --rm pimcore-image sh -c '! php -m | grep xdebug'
3839
docker run --rm pimcore-image test ! -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
3940
fi
40-
41+
4142
docker run --rm pimcore-image composer create-project pimcore/skeleton:11.x-dev pimcore --no-scripts
42-
43+
4344
if [ "$imageVariant" != "min" ]; then
4445
docker run -v "$(pwd)/.github/files":/var/www/html --rm pimcore-image php test_heif.php
4546
fi
@@ -52,4 +53,4 @@ jobs:
5253
exit-code: '1'
5354
ignore-unfixed: true
5455
vuln-type: 'os,library'
55-
severity: 'CRITICAL,HIGH'
56+
severity: 'CRITICAL,HIGH'

0 commit comments

Comments
 (0)