diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index bb1eef45..d4f4596a 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -88,6 +88,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,14 +99,17 @@ 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 }} + - 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: @@ -124,6 +128,49 @@ jobs: name: build-frankenphp-docker-image status: ${{ job.status }} + # overall process + - uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6 + with: + name: build-frankenphp-binary-file + status: pending + + - uses: docker/build-push-action@v5 + continue-on-error: false + with: + load: true + context: command-configurator + file: command-configurator/Dockerfile + pull: true + github-token: ${{ github.token }} + build-args: | + UPDATE_DATE: "${{ env.updateDate }}" + target: build-bin-file + tags: static-app + cache-from: | + type=local + type=registry,ref=${{ env.image_name }}:${{ env.image_tag }} + + - name: Check and copy binary + continue-on-error: false + 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: Upload binary artifact + if: success() + uses: actions/upload-artifact@v4 + with: + name: command-configurator + path: command-configurator + + - uses: akatov/commit-status-updater@a9e988ec5454692ff7745a509452422a35172ad6 + with: + name: build-frankenphp-binary-file + status: ${{ job.status }} + # ------------------------------------------------------- # Build bash docker images # ------------------------------------------------------- diff --git a/command-configurator/Dockerfile b/command-configurator/Dockerfile index 9271be2f..8f884cf5 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,48 @@ 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 ;\ + composer install ;\ + \ + # 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 --platform=linux/amd64 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