Skip to content

Commit 8cfcff9

Browse files
authored
Merge pull request #122 from Wirone/codito/docker-builds
feat: CI job for building Docker binary-only images
2 parents 6bf4cc2 + 61ba6a8 commit 8cfcff9

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,77 @@ jobs:
3838
if: ${{startsWith(github.ref, 'refs/tags/') }}
3939
with:
4040
files: pie.phar
41+
42+
docker-binary-only-image:
43+
needs: build-phar
44+
name: Docker binary-only image
45+
runs-on: ubuntu-latest
46+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
47+
48+
permissions:
49+
# attestations:write is required for build provenance attestation.
50+
attestations: write
51+
# id-token:write is required for build provenance attestation.
52+
id-token: write
53+
# packages:write is required to publish Docker images to GitHub's registry.
54+
packages: write
55+
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
- name: Fetch built PHAR from artifacts
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: pie-${{ github.sha }}.phar
64+
65+
- name: Verify the PHAR
66+
env:
67+
GH_TOKEN: ${{ github.token }}
68+
run: gh attestation verify pie.phar --repo ${{ github.repository }}
69+
70+
- name: Set up QEMU
71+
uses: docker/setup-qemu-action@v3
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
76+
- name: Log in to the Container registry
77+
uses: docker/login-action@v3
78+
with:
79+
registry: ghcr.io
80+
username: ${{ github.actor }}
81+
password: ${{ secrets.GITHUB_TOKEN }}
82+
83+
- name: Extract metadata (tags, labels) for Docker
84+
id: meta
85+
uses: docker/metadata-action@v5
86+
with:
87+
flavor: |
88+
latest=false
89+
images: ghcr.io/${{ github.repository }}
90+
# @TODO v1.0 Consider introducing more granular tags (major and major.minor)
91+
# @see https://github.com/php/pie/pull/122#pullrequestreview-2477496308
92+
# @see https://github.com/php/pie/pull/122#discussion_r1867331273
93+
tags: |
94+
type=raw,value=bin
95+
type=semver,pattern={{version}}-bin
96+
97+
- name: Build and push Docker image
98+
id: build-and-push
99+
uses: docker/build-push-action@v5
100+
with:
101+
context: .
102+
platforms: linux/amd64,linux/arm64
103+
file: Dockerfile
104+
target: standalone-binary
105+
push: true
106+
tags: ${{ steps.meta.outputs.tags }}
107+
labels: ${{ steps.meta.outputs.labels }}
108+
109+
- name: Generate artifact attestation
110+
uses: actions/attest-build-provenance@v1
111+
with:
112+
subject-name: ghcr.io/${{ github.repository }}
113+
subject-digest: ${{ steps.build-and-push.outputs.digest }}
114+
push-to-registry: true

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM scratch AS standalone-binary
2+
3+
# @TODO change to --chmod=+x when https://github.com/moby/buildkit/pull/5380 is released
4+
COPY --chmod=0755 pie.phar /pie

docs/usage.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ system:
2727
sudo curl -L --output /usr/local/bin/pie https://github.com/php/pie/releases/latest/download/pie.phar && sudo chmod +x /usr/local/bin/pie
2828
```
2929

30+
### Docker installation
31+
32+
PIE is published as binary-only Docker image, so you can install it easily during your Docker build:
33+
34+
```Dockerfile
35+
COPY --from=ghcr.io/php/pie:bin /pie /usr/bin/pie
36+
```
37+
38+
Instead of `bin` tag (which represents latest binary-only image) you can also use explicit version (in `x.y.z-bin` format). Use [GitHub registry](https://ghcr.io/php/pie) to find available tags.
39+
40+
> [!IMPORTANT]
41+
> Binary-only images don't include PHP runtime so you can't use them for _running_ PIE. This is just an alternative way of distributing PHAR file, you still need to satisfy PIE's runtime requirements on your own.
42+
3043
## Prerequisites for PIE
3144

3245
Running PIE requires PHP 8.1 or newer. However, you may still use PIE to install

0 commit comments

Comments
 (0)