Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Exclude everything except what Docker needs
*
!build/flow.phar
4 changes: 2 additions & 2 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ jobs:
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
build-args: |
FLOW_PHP_VERSION=${{ matrix.php-version }}
tags: |
ghcr.io/flow-php/flow:latest
target: flow
cache-from: type=gha
cache-to: type=gha,mode=max

- name: "Prepare artifact name"
if: ${{ github.event_name == 'push' }}
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/docker-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build Docker Base Image

on:
workflow_dispatch:
schedule:
# Run weekly on Sunday at 2 AM UTC
- cron: '0 2 * * 0'
push:
branches: [ 1.x ]
paths:
- 'Dockerfile.base'

jobs:
build-base-image:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version:
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
uses: actions/checkout@v5

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

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Base Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.base
push: true
platforms: linux/amd64,linux/arm64
build-args: |
FLOW_PHP_VERSION=${{ matrix.php-version }}
tags: |
ghcr.io/flow-php/flow-base:${{ matrix.php-version }}-alpine
ghcr.io/flow-php/flow-base:latest
cache-from: type=registry,ref=ghcr.io/flow-php/flow-base:${{ matrix.php-version }}-alpine
cache-to: type=inline
2 changes: 1 addition & 1 deletion .nix/pkgs/php-snappy/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ php.buildPecl {
owner = "kjdev";
repo = "php-ext-snappy";
tag = "0.2.3";
hash = "sha256-PAKdIcpJKH6d74EulYQepP4XbQvccrj1nEuir47vro4=";
hash = "sha256-W3TJ/bJz1LEPXq8m8YWAYX/2IZoJEpvqzasBiN61hK0=";
fetchSubmodules = true;
};

Expand Down
52 changes: 7 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,16 @@
# Stage 1: Build stage
ARG FLOW_PHP_VERSION=8.3.28
ARG FLOW_BASE_IMAGE_TAG_SUFFIX=cli-alpine3.22
ARG FLOW_BASE_IMAGE_TAG=${FLOW_PHP_VERSION}-${FLOW_BASE_IMAGE_TAG_SUFFIX}
ARG FLOW_BASE_IMAGE=php:${FLOW_BASE_IMAGE_TAG}
# Flow PHP Docker Image
# Uses pre-built base image with all PHP extensions
# Base image is built by .github/workflows/docker-base.yml
ARG FLOW_PHP_VERSION=8.5
ARG FLOW_BASE_IMAGE=ghcr.io/flow-php/flow-base:${FLOW_PHP_VERSION}-alpine

FROM ${FLOW_BASE_IMAGE} AS builder

# Install dependencies and PHP extensions
RUN apk update && apk add --no-cache \
$PHPIZE_DEPS \
gmp-dev \
git \
mariadb-dev \
postgresql-dev \
sqlite-dev \
libpq \
curl \
build-base \
autoconf \
automake \
libtool \
protobuf-dev \
protobuf-c-dev \
&& docker-php-ext-install bcmath gmp pdo_mysql pdo_pgsql pdo_sqlite \
&& curl -L https://github.com/php/pie/releases/latest/download/pie.phar -o /usr/local/bin/pie \
&& chmod +x /usr/local/bin/pie \
&& php /usr/local/bin/pie install kjdev/brotli \
&& php /usr/local/bin/pie install kjdev/lz4 \
&& php /usr/local/bin/pie install kjdev/snappy \
&& php /usr/local/bin/pie install kjdev/zstd \
&& php /usr/local/bin/pie install flow-php/pg-query-ext:1.x-dev

# Stage 2: Final Image
FROM ${FLOW_BASE_IMAGE} AS flow

# Copy the built extensions from the builder stage
COPY --from=builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions
COPY --from=builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.d

# Copy necessary libraries for the extensions
COPY --from=builder /usr/lib/libgmp.so.10 /usr/lib/
COPY --from=builder /usr/lib/libstdc++.so.6 /usr/lib/
COPY --from=builder /usr/lib/libgcc_s.so.1 /usr/lib/
COPY --from=builder /usr/lib/libpq.so.5 /usr/lib/

# Copy your PHP application
# Copy the pre-built PHAR file
COPY build/flow.phar /flow-php/flow.phar
RUN chmod +x /flow-php/flow.phar

# Set the work directory, entrypoint, and volume
WORKDIR /flow-php
ENTRYPOINT ["php", "/flow-php/flow.phar"]
VOLUME ["/flow-php"]
VOLUME ["/flow-php"]
37 changes: 37 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Base image with all PHP extensions pre-compiled for Flow PHP
# This image is built weekly and cached in the registry
# Used by Dockerfile to avoid recompiling extensions on every build
ARG FLOW_PHP_VERSION=8.3
ARG FLOW_BASE_IMAGE_TAG_SUFFIX=cli-alpine3.22

FROM php:${FLOW_PHP_VERSION}-${FLOW_BASE_IMAGE_TAG_SUFFIX}

# Pin PIE version for reproducible builds
ARG PIE_VERSION=1.3.1

# Install dependencies and PHP extensions in a single layer
RUN apk update && apk add --no-cache \
$PHPIZE_DEPS \
gmp-dev \
git \
mariadb-dev \
postgresql-dev \
sqlite-dev \
libpq \
curl \
build-base \
autoconf \
automake \
libtool \
protobuf-dev \
protobuf-c-dev \
&& docker-php-ext-install bcmath gmp pdo_mysql pdo_pgsql pdo_sqlite \
&& curl -L "https://github.com/php/pie/releases/download/${PIE_VERSION}/pie.phar" -o /usr/local/bin/pie \
&& chmod +x /usr/local/bin/pie \
&& php /usr/local/bin/pie install kjdev/brotli \
&& php /usr/local/bin/pie install kjdev/lz4 \
&& php /usr/local/bin/pie install kjdev/snappy \
&& php /usr/local/bin/pie install kjdev/zstd \
&& php /usr/local/bin/pie install flow-php/pg-query-ext:1.x-dev \
&& apk del $PHPIZE_DEPS build-base autoconf automake libtool git \
&& rm -rf /var/cache/apk/* /tmp/*
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
"@build:phar"
],
"build:docker": [
"docker buildx build -t flow-php/flow:latest . --progress=plain --load"
"docker build -f Dockerfile.base -t ghcr.io/flow-php/flow-base:8.5-alpine ."
],
"build:docs": [
"bin/docs.php dsl:dump web/landing/resources/dsl.json",
Expand Down
22 changes: 20 additions & 2 deletions documentation/contributing/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,31 @@ composer build:phar

## Building Docker Image

In order to build docker image and load it to local registry please use:
The Docker setup uses a two-layer approach for faster builds:

1. **Base image** (`Dockerfile.base`) - Contains PHP and all extensions, built weekly in CI
2. **Main image** (`Dockerfile`) - Copies the PHAR into the base image

### Using Pre-built Base Image (Recommended)

Build the main image using the pre-built base from the registry:

```shell
composer build:phar
docker buildx build -t flow-php/flow:latest . --progress=plain --load
```

### Building Base Image Locally

If you need to build the base image locally (e.g., testing extension changes):

```shell
docker buildx build -f Dockerfile.base -t ghcr.io/flow-php/flow-base:8.3-alpine . --progress=plain --load
composer build:phar
docker buildx build -t flow-php/flow:latest . --progress=plain --load
```

Usage:
### Usage

```shell
docker run -v $(pwd):/flow-workspace -it flow-php/flow:latest --version
Expand Down