Skip to content

Commit ad03ec4

Browse files
authored
Merge pull request spiral#3 from spiral/maintenance/smaller-image
Update Dockerfile to improve image build process
2 parents 6a4e579 + d924c58 commit ad03ec4

File tree

6 files changed

+117
-139
lines changed

6 files changed

+117
-139
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 90 deletions
This file was deleted.

.github/workflows/php81.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
2-
push:
3-
branches:
4-
- 'ghcr'
2+
release:
3+
types:
4+
- created
55

66
name: Build PHP 8.1
77

@@ -30,7 +30,7 @@ jobs:
3030
push: true
3131
platforms: linux/amd64,linux/arm64
3232
build-args: |
33-
PHP_IMAGE=8.1-cli-alpine3.19
33+
PHP_IMAGE=8.1-cli-alpine3.21
3434
tags: |
3535
ghcr.io/spiral/php-grpc:8.1
3636
@@ -58,7 +58,7 @@ jobs:
5858
push: true
5959
platforms: linux/amd64,linux/arm64
6060
build-args: |
61-
PHP_IMAGE=8.1-cli-alpine3.19
61+
PHP_IMAGE=8.1-cli-alpine3.21
6262
XDEBUG_ENABLED=true
6363
tags: |
6464
ghcr.io/spiral/php-grpc:8.1

.github/workflows/php82.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
2-
push:
3-
branches:
4-
- 'ghcr'
2+
release:
3+
types:
4+
- created
55

66
name: Build PHP 8.2
77

@@ -30,7 +30,7 @@ jobs:
3030
push: true
3131
platforms: linux/amd64,linux/arm64
3232
build-args: |
33-
PHP_IMAGE=8.2-cli-alpine3.19
33+
PHP_IMAGE=8.2-cli-alpine3.21
3434
tags: |
3535
ghcr.io/spiral/php-grpc:8.2
3636
@@ -58,7 +58,7 @@ jobs:
5858
push: true
5959
platforms: linux/amd64,linux/arm64
6060
build-args: |
61-
PHP_IMAGE=8.2-cli-alpine3.19
61+
PHP_IMAGE=8.2-cli-alpine3.21
6262
XDEBUG_ENABLED=true
6363
tags: |
6464
ghcr.io/spiral/php-grpc:8.2

.github/workflows/php83.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
2-
push:
3-
branches:
4-
- 'ghcr'
2+
release:
3+
types:
4+
- created
55

66
name: Build PHP 8.3
77

@@ -30,7 +30,7 @@ jobs:
3030
push: true
3131
platforms: linux/amd64,linux/arm64
3232
build-args: |
33-
PHP_IMAGE=8.3-cli-alpine3.19
33+
PHP_IMAGE=8.3-cli-alpine3.21
3434
tags: |
3535
ghcr.io/spiral/php-grpc:8.3
3636
@@ -58,7 +58,7 @@ jobs:
5858
push: true
5959
platforms: linux/amd64,linux/arm64
6060
build-args: |
61-
PHP_IMAGE=8.3-cli-alpine3.19
61+
PHP_IMAGE=8.3-cli-alpine3.21
6262
XDEBUG_ENABLED=true
6363
tags: |
6464
ghcr.io/spiral/php-grpc:8.3

.github/workflows/php84.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
on:
2+
release:
3+
types:
4+
- created
5+
6+
name: Build PHP 8.4
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v1
17+
18+
- name: Login to GitHub Container Registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ secrets.GHCR_LOGIN }}
23+
password: ${{ secrets.GHCR_PASSWORD }}
24+
25+
- name: Build and push PHP 8.4
26+
uses: docker/build-push-action@v2
27+
with:
28+
context: ./
29+
file: ./Dockerfile
30+
push: true
31+
platforms: linux/amd64,linux/arm64
32+
build-args: |
33+
PHP_IMAGE=8.4-cli-alpine3.21
34+
tags: |
35+
ghcr.io/spiral/php-grpc:8.4
36+
37+
build_xdebug:
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v2
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v1
45+
46+
- name: Login to GitHub Container Registry
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ghcr.io
50+
username: ${{ secrets.GHCR_LOGIN }}
51+
password: ${{ secrets.GHCR_PASSWORD }}
52+
53+
- name: Build and push PHP 8.4 with Xdebug
54+
uses: docker/build-push-action@v2
55+
with:
56+
context: ./
57+
file: ./Dockerfile
58+
push: true
59+
platforms: linux/amd64,linux/arm64
60+
build-args: |
61+
PHP_IMAGE=8.4-cli-alpine3.21
62+
XDEBUG_ENABLED=true
63+
tags: |
64+
ghcr.io/spiral/php-grpc:8.4

Dockerfile

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1+
ARG COMPOSER_VERSION="2.8.4"
12
ARG PHP_IMAGE=8.1-cli-alpine3.19
23

3-
FROM --platform=${TARGETPLATFORM:-linux/amd64} php:$PHP_IMAGE as builder
4-
5-
RUN apk update
6-
RUN apk add --no-cache \
7-
icu-dev \
8-
libxslt-dev \
9-
libzip-dev \
10-
linux-headers \
11-
${PHPIZE_DEPS}
12-
13-
RUN rm -rf /var/lib/apt/lists/*
14-
15-
ARG PROTOBUF_VERSION="4.26.1"
16-
RUN pecl channel-update pecl.php.net \
17-
&& MAKEFLAGS="-j $(nproc)" pecl install protobuf-${PROTOBUF_VERSION} grpc
18-
19-
RUN docker-php-ext-install \
20-
opcache \
21-
zip \
22-
xsl \
23-
dom \
24-
exif \
25-
intl \
26-
pcntl \
27-
bcmath \
28-
sockets
29-
30-
RUN docker-php-ext-enable \
31-
protobuf \
32-
grpc
4+
FROM composer:${COMPOSER_VERSION} AS composer_stage
5+
FROM --platform=${TARGETPLATFORM:-linux/amd64} php:${PHP_IMAGE}
336

34-
ARG XDEBUG_ENABLED=false
35-
RUN if [ "${XDEBUG_ENABLED}" == "true" ]; then pecl install xdebug && docker-php-ext-enable xdebug; fi
7+
ENV TZ="UTC"
8+
ENV COMPOSER_ALLOW_SUPERUSER=1
9+
10+
COPY --from=ghcr.io/mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/install-php-extensions
11+
COPY --from=composer_stage /usr/bin/composer /usr/bin/composer
3612

37-
RUN docker-php-source delete \
38-
&& apk del ${BUILD_DEPENDS}
13+
ARG XDEBUG_ENABLED=false
14+
ARG PROTOBUF_VERSION="4.29.1"
15+
ARG GRPC_VERSION="1.68.0"
16+
17+
RUN apk update && apk add --no-cache \
18+
bash \
19+
ca-certificates \
20+
icu-data-full icu-libs \
21+
libzip \
22+
linux-headers \
23+
lz4-libs \
24+
openssh-client \
25+
${PHPIZE_DEPS}
26+
27+
RUN install-php-extensions grpc-${GRPC_VERSION} \
28+
&& install-php-extensions protobuf-${PROTOBUF_VERSION} \
29+
&& install-php-extensions intl \
30+
&& install-php-extensions zip \
31+
&& install-php-extensions curl \
32+
&& install-php-extensions opcache \
33+
&& install-php-extensions pcntl \
34+
&& install-php-extensions sockets \
35+
&& docker-php-ext-enable grpc protobuf
36+
37+
RUN if [ "${XDEBUG_ENABLED}" == "true" ]; then install-php-extensions xdebug && docker-php-ext-enable xdebug; fi
38+
39+
RUN apk del --no-cache ${PHPIZE_DEPS} \
40+
&& rm -rf /tmp/*
41+
42+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

0 commit comments

Comments
 (0)