Skip to content

Commit

Permalink
frankenphp binary file
Browse files Browse the repository at this point in the history
megalinter workflow only if not cancelled
  • Loading branch information
fchastanet committed May 18, 2024
1 parent cc10e48 commit 25367f6
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 13 deletions.
1 change: 1 addition & 0 deletions .cspell/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ PRUNEPATHS
publickey
rearranger
refact
reqs
Resolv
riak
RPAREN
Expand Down
76 changes: 74 additions & 2 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on: # yamllint disable-line rule:truthy
- "**"
# avoid infinite loop for auto created PRs
- "!update/pre-commit-*"
tags:
- "**"
workflow_dispatch:

# cancel previous build if several pushes
Expand Down Expand Up @@ -41,6 +43,8 @@ jobs:
permissions:
# needed by akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
statuses: write
# needed by ncipollo/release-action
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -88,6 +92,7 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- uses: docker/build-push-action@v5
continue-on-error: false
with:
Expand All @@ -98,32 +103,99 @@ jobs:
github-token: ${{ github.token }}
build-args: |
UPDATE_DATE: "${{ env.updateDate }}"
target: base
tags: |
${{ env.image_name }}:${{ env.image_tag }}
cache-from: |
type=registry,ref=${{ env.image_name }}:${{ env.image_tag }}
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }}
cache-to: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }},mode=max
- name: Check image
continue-on-error: false
run: |
docker run --rm "${{ env.image_name }}:${{ env.image_tag }}" php --version
- uses: docker/build-push-action@v5
continue-on-error: false
with:
load: true
context: command-configurator
file: command-configurator/Dockerfile
target: base
push: true
github-token: ${{ github.token }}
tags: |
${{ env.image_name }}:${{ env.image_tag }}
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }}
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
with:
name: build-frankenphp-docker-image
status: ${{ job.status }}

# overall process
- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
with:
name: build-frankenphp-binary-file
status: pending

- name: Ensure vendor dir can be written in the binary
continue-on-error: false
if: ${{ !cancelled() && startsWith(github.ref, 'refs/tags/') }}
run: |
echo ".git/" > .dockerignore
- uses: docker/build-push-action@v5
continue-on-error: false
if: ${{ !cancelled() && startsWith(github.ref, 'refs/tags/') }}
with:
load: true
context: command-configurator
file: command-configurator/Dockerfile
target: build-bin-file
pull: true
push: false
github-token: ${{ github.token }}
build-args: |
UPDATE_DATE: "${{ env.updateDate }}"
cache-from: |
type=registry,ref=${{ env.image_name }}:cache-base-${{ env.image_tag }}
tags: static-app

- name: Check and copy binary
continue-on-error: false
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
run: |
set -exo pipefail
storeContainer="$(docker create --name static-app-tmp static-app)"
docker cp "${storeContainer}:/go/src/app/dist/frankenphp-linux-x86_64" my-app
docker rm static-app-tmp
mv my-app command-configurator
- name: Special Release
uses: ncipollo/release-action@v1
with:
name: latest-command-configurator
omitBody: true
allowUpdates: true
artifacts: "command-configurator"
artifactErrorsFailBuild: true
replacesArtifacts: true
prerelease: true
generateReleaseNotes: true
skipIfReleaseExists: false

- uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
with:
name: build-frankenphp-binary-file
status: ${{ job.status }}

# -------------------------------------------------------
# Build bash docker images
# -------------------------------------------------------
Expand Down Expand Up @@ -308,7 +380,7 @@ jobs:
- name: MegaLinter
id: ml
if: ${{ always() }}
if: ${{ !cancelled() }}
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/flavors/
uses: oxsecurity/megalinter/flavors/terraform@v7
Expand Down
61 changes: 50 additions & 11 deletions command-configurator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
FROM dunglas/frankenphp
FROM dunglas/frankenphp:1.1.5-php8 as base

ARG UPDATE_DATE
ARG DEBIAN_FRONTEND=noninteractive

SHELL ["/bin/bash", "-exo", "pipefail", "-c"]
# hadolint ignore=DL3008
RUN \
set -exo pipefail ;\
apt-get update ;\
apt-get upgrade -y ;\
apt-get install -y -q --no-install-recommends \
git \
unzip \
;\
install-php-extensions \
zip \
opcache \
;\
curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer \
;\
apt-get clean autoclean ;\
apt-get autoremove -y --allow-remove-essential ;\
apt-get autoremove apt --autoremove -y --allow-remove-essential ;\
rm -rf \
apt-get autoremove apt --autoremove -y --allow-remove-essential ;\rm -rf \
/var/lib/{apt,dpkg,cache,log}/ /tmp/* /var/tmp/* \
/var/cache/apt/archives /usr/share/{doc,man,locale}/

/var/cache/apt/archives /usr/share/{doc,man,locale}
RUN chown www-data:www-data /app
USER www-data

COPY --chown=www-data:www-data composer.* /app
RUN composer install

COPY --chown=www-data:www-data . /app

ONBUILD ARG USER=www-data
ONBUILD USER root
# hadolint ignore=SC3010
ONBUILD RUN \
if [[ "${USER}" != "www-data" ]]; then \
useradd -M "${USER}" ;\
Expand All @@ -45,3 +40,47 @@ ONBUILD RUN \
chown -R "${USER}:${USER}" /config/caddy ;\
fi
ONBUILD USER ${USER}

###################################################################################
# STAGE prepare-binary-env
###################################################################################
FROM base as prepare-binary-env

SHELL ["/bin/bash", "-exo", "pipefail", "-c"]

COPY --chown=www-data:www-data composer.* /app
RUN composer install

COPY --chown=www-data:www-data . /app
RUN \
# Set proper environment variables
echo APP_ENV=prod > .env.local ;\
echo APP_DEBUG=0 >> .env.local ;\
\
# Remove the tests and other unneeded files to save space
# Alternatively, add these files with the export-ignore attribute
# in your .gitattributes file
rm -Rf tests/ config-generated/ ;\
\
# Install the dependencies
composer install --ignore-platform-reqs --no-dev -a ;\
\
# Optimize .env
composer config --no-plugins allow-plugins.symfony/flex true ;\
composer require symfony/flex ;\
composer require symfony/dotenv ;\
composer dump-env prod

###################################################################################
# STAGE build-bin-file
###################################################################################
FROM dunglas/frankenphp:static-builder-1.1 as build-bin-file

SHELL ["/bin/bash", "-exo", "pipefail", "-c"]

WORKDIR /go/src/app/dist/app
COPY --from=prepare-binary-env /app .

# Build the static binary
WORKDIR /go/src/app/
RUN EMBED=dist/app/ ./build-static.sh
6 changes: 6 additions & 0 deletions command-configurator/convertConfigFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function transformConfig(Logger $logger, array &$config): void {
if (!isset($option['callbacks'])) {
$option['callbacks'] = [];
}
if (!isset($option['min'])) {
$option['min'] = 0;
}
if (!isset($option['max'])) {
$option['max'] = ($option['type'] === 'StringArray') ? -1 : 1;
}
}
unset($option);
}
Expand Down

0 comments on commit 25367f6

Please sign in to comment.