Skip to content

Commit 1512cb6

Browse files
authored
build: Add a docker image (#884)
1 parent ad9d0e2 commit 1512cb6

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

.github/workflows/release.yaml

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ concurrency:
1515
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1616
cancel-in-progress: true
1717

18+
env:
19+
DOCKERFILE: Dockerfile
20+
DOCKERHUB_USERNAME: humbugphp
21+
1822
jobs:
1923
build-phar:
2024
runs-on: ubuntu-latest
@@ -71,7 +75,6 @@ jobs:
7175
bin/php-scoper.phar
7276
7377
- name: Upload the PHAR artifact
74-
if: github.event_name == 'release'
7578
uses: actions/upload-artifact@v3
7679
with:
7780
name: php-scoper-phar
@@ -94,7 +97,91 @@ jobs:
9497
- name: Upload php-scoper.phar
9598
uses: softprops/action-gh-release@v1
9699
with:
97-
token: ${{ secrets.PHP_SCOPER_GITHUB_TOKEN }}
100+
token: ${{ secrets.GITHUB_TOKEN }}
98101
files: |
99102
php-scoper.phar
100103
php-scoper.phar.asc
104+
105+
publish-docker-image:
106+
runs-on: ubuntu-latest
107+
name: Publish the Docker image
108+
needs:
109+
- build-phar
110+
steps:
111+
- name: Checkout
112+
uses: actions/checkout@v4
113+
114+
- uses: actions/download-artifact@v3
115+
with:
116+
name: php-scoper-phar
117+
path: .
118+
119+
# See https://github.com/actions/download-artifact#limitations
120+
# the permissions are not guaranteed to be preserved
121+
- name: Ensure PHAR is executable
122+
run: |
123+
chmod 755 php-scoper.phar
124+
mv -vf php-scoper.phar bin/php-scoper.phar
125+
./bin/php-scoper.phar --ansi --version
126+
127+
- name: Set up QEMU
128+
uses: docker/setup-qemu-action@v3
129+
130+
- name: Set up Docker Buildx
131+
uses: docker/setup-buildx-action@v3
132+
133+
- name: Login to Docker Container Registry
134+
if: github.event_name == 'release'
135+
uses: docker/login-action@v3
136+
with:
137+
username: ${{ env.DOCKERHUB_USERNAME }}
138+
password: ${{ secrets.DOCKERHUB_TOKEN }}
139+
140+
- name: Setup the Docker (release) tag(s)
141+
if: github.event_name == 'release'
142+
# Selects a random value for $EOF as a delimiter, and sets the DOCKER_TAGS environment variable
143+
# as a multi-line environment variable.
144+
run: |
145+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
146+
147+
echo "DOCKER_TAGS<<$EOF" >> $GITHUB_ENV
148+
echo "${{ env.DOCKERHUB_USERNAME }}/php-scoper:${{ github.ref_name }}" >> $GITHUB_ENV
149+
echo "${{ env.DOCKERHUB_USERNAME }}/php-scoper:latest" >> $GITHUB_ENV
150+
echo "$EOF" >> $GITHUB_ENV
151+
echo "DOCKER_TEST_TAG=${{ env.DOCKERHUB_USERNAME }}/php-scoper:latest" >> $GITHUB_ENV
152+
153+
- name: Login to GitHub Container Registry
154+
if: github.event_name != 'release'
155+
uses: docker/login-action@v2
156+
with:
157+
registry: ghcr.io
158+
username: ${{ github.actor }}
159+
password: ${{ secrets.GITHUB_TOKEN }}
160+
161+
- name: Setup the Docker tag(s)
162+
if: github.event_name != 'release'
163+
run: |
164+
echo "DOCKER_TAGS=ghcr.io/humbugphp/php-scoper" >> $GITHUB_ENV
165+
echo "DOCKER_TEST_TAG=ghcr.io/humbugphp/php-scoper" >> $GITHUB_ENV
166+
167+
- name: Build and export to Docker
168+
uses: docker/build-push-action@v3
169+
with:
170+
context: .
171+
file: ${{ env.DOCKERFILE }}
172+
platforms: linux/amd64
173+
tags: ${{ env.DOCKER_TAGS }}
174+
load: true
175+
176+
- name: Test the (release) image
177+
run: docker run --rm ${{ env.DOCKER_TEST_TAG }} --version
178+
179+
- name: Build and push
180+
if: github.event_name == 'release'
181+
uses: docker/build-push-action@v3
182+
with:
183+
context: .
184+
file: ${{ env.DOCKERFILE }}
185+
platforms: linux/amd64
186+
tags: ${{ env.DOCKER_TAGS }}
187+
push: true

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM php:8.1-cli-alpine
2+
3+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
4+
RUN install-php-extensions zlib phar sodium tokenizer filter
5+
6+
COPY bin/php-scoper.phar /php-scoper.phar
7+
8+
ENTRYPOINT ["/php-scoper.phar"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
3131
- [Installation](docs/installation.md#installation)
3232
- [Phive](docs/installation.md#phive)
3333
- [Composer](docs/installation.md#composer)
34+
- [Docker](docs/installation.md#docker)
3435
- [GitHub](docs/installation.md#github)
3536
- [Usage](#usage)
3637
- [Configuration](docs/configuration.md#configuration)

docs/installation.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ $ composer bin php-scoper require --dev humbug/php-scoper
4545
$ vendor/bin/php-scoper
4646
```
4747

48+
49+
## Docker
50+
51+
The official docker image for the project is [`humbugphp/php-scoper`][docker-image]:
52+
53+
```shell
54+
docker pull humbugphp/php-scoper
55+
```
56+
57+
4858
## GitHub
4959

5060
You may download the Box PHAR directly from the [GitHub release][releases] directly.
@@ -74,6 +84,7 @@ chmod +x php-scoper.phar
7484

7585

7686
[composer]: https://getcomposer.org
87+
[docker-image]: https://hub.docker.com/r/humbugphp/php-scoper
7788
[bamarni/composer-bin-plugin]: https://github.com/bamarni/composer-bin-plugin
7889
[phive]: https://github.com/phar-io/phive
7990
[releases]: https://github.com/humbug/php-scoper/releases

0 commit comments

Comments
 (0)