From 25367f6a7ee206ceadffba35e3274fa4ad89ad24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chastanet?= Date: Sat, 18 May 2024 00:55:01 +0200 Subject: [PATCH] frankenphp binary file megalinter workflow only if not cancelled --- .cspell/config.txt | 1 + .github/workflows/lint-test.yml | 76 +++++++++++++++++++++- command-configurator/Dockerfile | 61 +++++++++++++---- command-configurator/convertConfigFile.php | 6 ++ 4 files changed, 131 insertions(+), 13 deletions(-) diff --git a/.cspell/config.txt b/.cspell/config.txt index cec760cd..f4636b08 100644 --- a/.cspell/config.txt +++ b/.cspell/config.txt @@ -142,6 +142,7 @@ PRUNEPATHS publickey rearranger refact +reqs Resolv riak RPAREN diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index bb1eef45..53918c2f 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -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 @@ -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 @@ -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: @@ -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 # ------------------------------------------------------- @@ -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 diff --git a/command-configurator/Dockerfile b/command-configurator/Dockerfile index 9271be2f..e1ece2ac 100644 --- a/command-configurator/Dockerfile +++ b/command-configurator/Dockerfile @@ -1,18 +1,19 @@ -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 | \ @@ -20,21 +21,15 @@ RUN \ ;\ 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}" ;\ @@ -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 diff --git a/command-configurator/convertConfigFile.php b/command-configurator/convertConfigFile.php index a6f4251b..436b20f2 100644 --- a/command-configurator/convertConfigFile.php +++ b/command-configurator/convertConfigFile.php @@ -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); }