Skip to content

Commit

Permalink
refactor: merge all Dockerfile stages
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmirloup committed Mar 6, 2024
1 parent 9399897 commit 8e6836d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 113 deletions.
53 changes: 10 additions & 43 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ name: Build PHP docker images
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master
schedule:
- cron: '0 12 * * SUN' # every sunday
workflow_dispatch:
Expand All @@ -18,57 +18,24 @@ jobs:
name: PHP
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64

steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

- uses: actions/checkout@v4

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: lephare/php
tags: |
type=raw,${{ matrix.php_version }}
-
name: Set up QEMU
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
id: setup-buildx
uses: docker/setup-buildx-action@v2
with:
platforms: |
linux/amd64
linux/arm64
- name: Build and push
uses: docker/build-push-action@v4
uses: docker/bake-action@v4
with:
context: "{{defaultContext}}:${{ matrix.php_version }}"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ steps.setup-buildx.outputs.platforms }}
cache-from: type=gha
cache-to: type=gha,mode=max
59 changes: 2 additions & 57 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,66 +1,11 @@
FROM php:7.4-fpm as base_php_74
FROM php:8.0-fpm as base_php_80
FROM php:8.1-fpm as base_php_81
FROM php:8.2-fpm as base_php_82
FROM php:8.3-fpm as base_php_83
ARG PHP_VERSION
FROM php:${PHP_VERSION}-fpm

FROM scratch as config
WORKDIR /usr/local/etc/php/conf.d/
COPY --link symfony.ini .
WORKDIR /usr/local/etc/php/pool.d/
COPY --link symfony.pool.conf .

FROM base_php_74 as php_74
COPY --from=config / /

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip

RUN usermod -u 1000 www-data
RUN usermod -G staff www-data

WORKDIR /var/www/symfony

FROM base_php_80 as php_80
COPY --from=config / /

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip

RUN usermod -u 1000 www-data
RUN usermod -G staff www-data

WORKDIR /var/www/symfony

FROM base_php_81 as php_81
COPY --from=config / /

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip

RUN usermod -u 1000 www-data
RUN usermod -G staff www-data

WORKDIR /var/www/symfony

FROM base_php_82 as php_82
COPY --from=config / /

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip

RUN usermod -u 1000 www-data
RUN usermod -G staff www-data

WORKDIR /var/www/symfony

FROM base_php_83 as php_83
COPY --from=config / /

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip
Expand Down
28 changes: 15 additions & 13 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
services:
php_74:
image: lephare/php:7.4
build:
tags:
- lephare/php:7.4
target: php_74
args:
- PHP_VERSION=7.4
x-bake: &build-x-bake
platforms:
- linux/amd64
- linux/arm64

php_80:
image: lephare/php:8.0
build:
tags:
- lephare/php:8.0
target: php_80
args:
- PHP_VERSION=8.0
x-bake: *build-x-bake

php_81:
image: lephare/php:8.1
build:
tags:
- lephare/php:8.1
target: php_81
args:
- PHP_VERSION=8.1
x-bake: *build-x-bake

php_82:
image: lephare/php:8.2
build:
tags:
- lephare/php:8.2
target: php_82
args:
- PHP_VERSION=8.2
x-bake: *build-x-bake

php_83:
image: lephare/php:8.3
build:
args:
- PHP_VERSION=8.3
tags:
- lephare/php:8.3
target: php_83
x-bake: *build-x-bake

0 comments on commit 8e6836d

Please sign in to comment.