Skip to content

Commit

Permalink
frankenphp binary file
Browse files Browse the repository at this point in the history
  • Loading branch information
fchastanet committed May 17, 2024
1 parent cc10e48 commit e7c8eab
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 11 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
# -------------------------------------------------------
Expand Down
62 changes: 51 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,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

0 comments on commit e7c8eab

Please sign in to comment.