Skip to content

Instantly share code, notes, and snippets.

@felegy
Last active August 23, 2024 08:20
Show Gist options
  • Save felegy/c4ae30ffaf3b930ac6d832363a9e3a7f to your computer and use it in GitHub Desktop.
Save felegy/c4ae30ffaf3b930ac6d832363a9e3a7f to your computer and use it in GitHub Desktop.

Heroku buildpack Php Dockerfile

# Heroku stack version
# https://devcenter.heroku.com/articles/heroku-22-stack#using-heroku-22
ARG STACK_VERSION=22
ARG STACK=heroku-${STACK_VERSION}
FROM heroku/heroku:${STACK_VERSION} AS base
# local profile.d
RUN tee -a /etc/profile <<'EOF'
if [ -d $HOME/.profile.d ]; then
for i in $HOME/.profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
FROM heroku/heroku:${STACK_VERSION}-build AS build
ARG STACK
COPY --chown=heroku:heroku . /app
# Procfile parser script
RUN tee -a /usr/bin/parse-procfile <<'EOF'
#!/usr/bin/env bash
parse_procfile() {
local path=${1:-${PWD}}
local procfile=${2:-'Procfile'}
mkdir -p "$path/bin"
while read line || [[ -n "$line" ]]; do
if [[ -z "$line" ]] || [[ "$line" == \#* ]]; then continue; fi
local name="${line%%:*}"
local command="${line#*:[[:space:]]}"
local command_file="$path/bin/$name"
echo '#!/usr/bin/env bash' | tee "${command_file}"
echo "${command}" | tee -a "${command_file}"
chmod +x "${command_file}"
done < "$procfile"
mkdir -p "${path}/.profile.d" && echo 'PATH="/app/bin:$PATH"' | tee "${path}/.profile.d/999-procfile.sh"
}
parse_procfile $1 $2
EOF
RUN chmod a+x /usr/bin/parse-procfile
# Build steps
USER heroku
WORKDIR /app
RUN mkdir -p /tmp/buildpack/php /tmp/build_cache /tmp/env
RUN curl https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/php.tgz | tar --warning=none -xz -C /tmp/buildpack/php
RUN /tmp/buildpack/php/bin/compile /app /tmp/build_cache /tmp/env
RUN parse-procfile
# Release
FROM base
COPY --from=build --chown=heroku:heroku /app /app
ENV HOME=/app
WORKDIR /app
USER heroku
ENTRYPOINT ["/bin/bash", "-l", "-c"]
CMD ["web"]
FROM heroku/heroku:22-build AS build
COPY --chown=heroku:heroku . /app
USER heroku
WORKDIR /app
RUN mkdir -p /tmp/buildpack/php /tmp/build_cache /tmp/env
RUN curl https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/php.tgz | tar --warning=none -xz -C /tmp/buildpack/php
RUN STACK=heroku-22 /tmp/buildpack/php/bin/compile /app /tmp/build_cache /tmp/env
FROM heroku/heroku:22
COPY --from=build --chown=heroku:heroku /app /app
ENV HOME=/app
WORKDIR /app
USER heroku
ENTRYPOINT ["/bin/bash", "-l", "-c"]
CMD ["echo 'Auto-generated Dockerfile'"]
build:
docker:
# web: Dockerfile
web: Dockerfile.minimal
run:
web: heroku-php-nginx web
web: heroku-php-nginx web
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment