Skip to content

Commit

Permalink
Simplify Docker image
Browse files Browse the repository at this point in the history
Since rectorphp#5665, we might get away with the PHP 8.0 image variant only,
and also no longer need to scope the Rector source code.
  • Loading branch information
mpdude committed Mar 15, 2021
1 parent 28e1e1f commit 3bd6399
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/publish_docker_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ on:
jobs:
publish_images:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['7.3', '7.4', '8.0']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -37,17 +34,11 @@ jobs:
BRANCH=$(echo "${{ github.ref }}" | sed -e '/refs\/heads\//!d; s,refs/.*/\(.*\),\1,')
if [ "master" == "$BRANCH" ]; then
DOCKER_TAGS="$DOCKER_TAGS php${{ matrix.php-version }}"
if [ "8.0" == "${{ matrix.php-version }}" ]; then
DOCKER_TAGS="$DOCKER_TAGS latest"
fi
DOCKER_TAGS="$DOCKER_TAGS latest"
fi
if [ ! -z "$TAG" ]; then
DOCKER_TAGS="$DOCKER_TAGS $TAG-php${{ matrix.php-version }}"
if [ "8.0" == "${{ matrix.php-version }}" ]; then
DOCKER_TAGS="$DOCKER_TAGS $TAG"
fi
DOCKER_TAGS="$DOCKER_TAGS $TAG"
fi
echo "Image will be tagged with: $DOCKER_TAGS"
Expand All @@ -57,13 +48,13 @@ jobs:
DOCKER_TAG_ARG="$DOCKER_TAG_ARG --tag rector/rector:$ARG"
done
docker buildx create --name builder-php${{ matrix.php-version }} --use
docker buildx create --name builder --use
docker buildx build \
--progress plain \
--cache-from=rector/rector:build-cache-php${{ matrix.php-version }} \
--cache-to=type=registry,ref=rector/rector:build-cache-php${{ matrix.php-version }},mode=max,push=true \
--cache-from=rector/rector:build-cache \
--cache-to=type=registry,ref=rector/rector:build-cache,mode=max,push=true \
--target rector \
--push \
$DOCKER_TAG_ARG \
--platform linux/amd64,linux/arm64 \
--build-arg PHP_VERSION=${{ matrix.php-version }} .
--build-arg .
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@ RUN apt-get update && apt-get install -y \
COPY --from=composer:2.0.9 /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_MEMORY_LIMIT=-1 COMPOSER_NO_INTERACTION=1

# Run php-scoper, results go to /scoped
RUN wget https://github.com/humbug/php-scoper/releases/download/0.14.0/php-scoper.phar -N --no-verbose

# This is to make parsing version possible
COPY .git .git

# First copy composer.json only to leverage the build cache (as long as not git-committing)
COPY composer.json composer.json
RUN composer install --no-dev --no-progress --no-autoloader --prefer-dist

# Add source and generate full autoloader
COPY . .
# Copy relevant source paths
COPY bin bin
COPY config config
COPY packages packages
COPY rules rules
COPY src src
COPY templates templates
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev

RUN rm -f "phpstan-for-rector.neon" \
&& php -d memory_limit=-1 php-scoper.phar add-prefix bin config packages rules src templates vendor composer.json --output-dir /scoped --config scoper.php \
&& composer dump-autoload --optimize --classmap-authoritative --no-dev --working-dir /scoped
# Parse versions
COPY .git .git
RUN composer install --no-dev --no-progress --no-autoloader --prefer-dist && rm -rf .git

# Build runtime image
FROM base as rector
Expand All @@ -63,7 +62,7 @@ ENTRYPOINT [ "rector" ]
VOLUME ["/project"]
WORKDIR "/project"

COPY --from=build /scoped /rector
COPY --from=build /build /rector
RUN chmod +x /rector/bin/rector

RUN mkdir -p /tmp/opcache \
Expand Down

0 comments on commit 3bd6399

Please sign in to comment.