Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 6
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b422983

Browse files
authoredMar 20, 2024··
fix: make phar in docker (#568)
1 parent 6c690b8 commit b422983

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed
 

‎.github/workflows/docker.yml

+24-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
steps:
2121
- name: Checkout repository
2222
uses: actions/checkout@v4
23+
with:
24+
fetch-tags: true
25+
fetch-depth: 0
2326

2427
- name: Log in to the Container registry
2528
uses: docker/login-action@master
@@ -28,33 +31,42 @@ jobs:
2831
username: ${{ github.actor }}
2932
password: ${{ secrets.GITHUB_TOKEN }}
3033

31-
- name: Extract metadata (tags, labels) for Docker
34+
- name: Extract metadata (tags, labels) for Drafter
3235
id: meta-drafter
3336
uses: docker/metadata-action@master
3437
with:
3538
images: ${{ env.REGISTRY }}/${{ github.repository }}/drafter
3639

37-
- name: Extract metadata (tags, labels) for Docker
38-
id: meta
39-
uses: docker/metadata-action@master
40-
with:
41-
images: ${{ env.REGISTRY }}/${{ github.repository }}
42-
43-
- name: Build and push Docker image
40+
- name: Build and push drafter Docker image
4441
uses: docker/build-push-action@master
4542
with:
4643
context: .
4744
push: true
4845
tags: ${{ steps.meta-drafter.outputs.tags }}
4946
labels: ${{ steps.meta-drafter.outputs.labels }}
50-
target: drafter-build
47+
target: drafter
48+
no-cache-filters: drafter-build,drafter
5149
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}/drafter:latest
5250

53-
- name: Build and push Docker image
51+
- name: Extract metadata (tags, labels) for PHPDraft
52+
id: meta
53+
uses: docker/metadata-action@master
54+
with:
55+
images: ${{ env.REGISTRY }}/${{ github.repository }}
56+
57+
- name: Last tag
58+
id: tag-info
59+
run: |
60+
echo "latest=$(git describe --tags --always --abbrev=0)" >> "$GITHUB_OUTPUT"
61+
62+
- name: Build and push PHPDraft Docker image
5463
uses: docker/build-push-action@master
5564
with:
56-
context: .
5765
push: true
5866
tags: ${{ steps.meta.outputs.tags }}
5967
labels: ${{ steps.meta.outputs.labels }}
60-
target: phpdraft
68+
target: phpdraft
69+
no-cache-filters: composer,phpdraft-build,phpdraft
70+
build-args: |
71+
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true
72+
PHPDRAFT_RELEASE_ID=${{ steps.tag-info.outputs.latest }}

‎Dockerfile

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
1414
RUN cmake --build build
1515
RUN cmake --install build
1616

17+
FROM debian:bullseye-slim AS drafter
18+
COPY --from=drafter-build /usr/local/bin/drafter /usr/local/bin/drafter
19+
1720
CMD drafter
1821

1922
FROM composer:latest AS composer
@@ -24,22 +27,23 @@ RUN composer install --ignore-platform-req=ext-uopz
2427

2528
FROM php:8.3-cli-bullseye AS phpdraft-build
2629

30+
ARG PHPDRAFT_RELEASE_ID=0.0.0
2731

32+
RUN echo $PHPDRAFT_RELEASE_ID
2833

2934
COPY --from=composer /usr/src/phpdraft /usr/src/phpdraft
3035
WORKDIR /usr/src/phpdraft
3136

32-
RUN ./vendor/bin/phing phar-nightly
33-
COPY /usr/src/phpdraft/build/out/phpdraft-nightly.phar /usr/local/bin/phpdraft
34-
RUN chmod +x /usr/local/bin/phpdraft
37+
RUN echo "phar.readonly=0" >> /usr/local/etc/php/conf.d/phar.ini
38+
39+
RUN php ./vendor/bin/phing phar-nightly
40+
RUN cp /usr/src/phpdraft/build/out/phpdraft-nightly.phar /usr/local/bin/phpdraft
3541

3642
FROM php:8.3-cli-bullseye AS phpdraft
3743

3844
LABEL maintainer="Sean Molenaar sean@seanmolenaar.eu"
3945

40-
COPY --from=phpdraft-build /usr/local/bin/phpdraft /usr/local/bin/phpdraft
4146
COPY --from=drafter-build /usr/local/bin/drafter /usr/local/bin/drafter
42-
43-
RUN ls -al /usr/local/bin/phpdraft
47+
COPY --from=phpdraft-build /usr/local/bin/phpdraft /usr/local/bin/phpdraft
4448

4549
CMD phpdraft

‎build.xml

+16
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@
130130
<echo message="Building version: ${version}, type: ${type}, output: ${_version}"/>
131131
<fail unless="_version" message="Could not construct version parameter!" />
132132

133+
<exec executable="php" outputProperty="_pharReadonly">
134+
<arg value="-r"/>
135+
<arg value="echo ini_get('phar.readonly');"/>
136+
</exec>
137+
138+
<echo message="Phar: ${_pharReadonly}"/>
139+
<fail message="No PHAR creation allowed">
140+
<condition>
141+
<or>
142+
<equals arg1="${_pharReadonly}" arg2="1"/>
143+
<equals arg1="${_pharReadonly}" arg2="true"/>
144+
<equals arg1="${_pharReadonly}" arg2="On"/>
145+
</or>
146+
</condition>
147+
</fail>
148+
133149
<exec executable="${project.basedir}/vendor/bin/phpab" taskname="phpab">
134150
<arg value="--all"/>
135151
<arg value="--static"/>

‎src/PHPDraft/Out/Version.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ public static function version(): void
3535
*/
3636
public static function release_id(): string
3737
{
38-
return (VERSION === '0') ? @exec('git describe --tags 2>&1') : VERSION;
38+
$env_id = getenv('PHPDRAFT_RELEASE_ID');
39+
if ($env_id !== FALSE) {
40+
return $env_id;
41+
}
42+
43+
return VERSION !== '0' ? VERSION : @exec('git describe --tags 2>&1');
3944
}
4045

4146
/**

0 commit comments

Comments
 (0)
Please sign in to comment.