Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapting for PHP 8.1 / Laravel 9 #1

Open
alexc-hollywood opened this issue Nov 22, 2022 · 0 comments
Open

Adapting for PHP 8.1 / Laravel 9 #1

alexc-hollywood opened this issue Nov 22, 2022 · 0 comments

Comments

@alexc-hollywood
Copy link

alexc-hollywood commented Nov 22, 2022

For those who are curious, and want to use this excellent Docker image....

  1. Change the php-base version of Alpine
  2. Change the Roadrunner version (this dies with permission errors otherwise)
  3. Change the Laravel version variable
FROM php:8.1.12-cli-alpine3.16 as php-base
    WORKDIR /srv/laravel

    RUN apk add --no-cache $PHPIZE_DEPS autoconf libzip-dev zip unzip wget curl && \
        docker-php-ext-install bcmath ctype pcntl sockets zip && \
        rm -rf /var/www && \
        chown -R www-data:www-data /srv/laravel

# This stage is so that we can build up everything that doesn't require Laravel
# so as to not bust the caching for those items.
FROM php-base as octane-base
    COPY --from=spiralscout/roadrunner:latest /usr/bin/rr /usr/bin/rr

    # This really shouldn't be modified, so we aren't advertising the env variable.
    # It allows us to globally install chokidar without modifying the Laravel package.json.
    ENV NODE_PATH "/home/www-data/.npm-global/lib/node_modules"

    RUN apk add --no-cache nodejs npm && \
        mkdir "/home/www-data/.npm-global/" && \
        npm config set prefix "/home/www-data/.npm-global/" && \
        npm install -g chokidar

# Here we have a build container so that it is not necessary to pull composer into
# the final container. We are going to create a new Laravel project and install Octane.
FROM php-base as laravel
    ARG LARAVEL_VERSION="9.*"

    COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

    RUN cd /srv && \
        composer create-project laravel/laravel="${LARAVEL_VERSION}" laravel && \
        cd /srv/laravel && \
        composer require laravel/octane spiral/roadrunner && \
        php artisan octane:install --server="roadrunner" && \
        rm "/srv/laravel/.env"

# This is our final container. We will install the RoadRunner binary and copy over
# our built version of Laravel.
FROM octane-base
    USER www-data

    COPY --from=laravel --chown=www-data:www-data /srv/laravel/ /srv/laravel/

    # Allow the user to specify RoadRunner options via ENV variables.
    ENV ROADRUNNER_MAX_REQUESTS "500"
    ENV ROADRUNNER_WATCH $false
    ENV ROADRUNNER_WORKERS "auto"

    # Expose the ports that Octane is using.
    EXPOSE 8000

    # Run RoadRunner
    CMD if [[ -z $ROADRUNNER_WATCH ]] ; then \
        php artisan octane:start --server="roadrunner" --host="0.0.0.0" --workers=${ROADRUNNER_WORKERS} --max-requests=${ROADRUNNER_MAX_REQUESTS} ; \
    else \
        php artisan octane:start --server="roadrunner" --host="0.0.0.0" --workers=${ROADRUNNER_WORKERS} --max-requests=${ROADRUNNER_MAX_REQUESTS} --watch ; \
    fi

    # Check the health status using the Octane status command.
    HEALTHCHECK CMD php artisan octane:status --server="roadrunner"

For a list of PHP extensions you can install in Alpine: https://gist.github.com/chronon/95911d21928cff786e306c23e7d1d3f3 .

If you need to add others (e.g. curl, mbstring), you will need the development files. Find them here: https://pkgs.alpinelinux.org/packages

RUN apk add --no-cache libzip-dev curl-dev libxml2 libxml2-dev oniguruma-dev icu-dev freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \

For MongoDB and Redis you will need to install from PECL, which requires autoconf and $PHPIZE_DEPS:

    RUN pecl install mongodb && docker-php-ext-enable mongodb  
    RUN pecl install redis && docker-php-ext-enable redis   

Another issue here is the directory binding. The latest version of Docker wants volumes.

Example Compose setup:

myfolder/
   docker/
       laravel.Dockerfile
   laravel-src/
       app/
       config/
  laravel:
    build:
      context: ./docker/
      dockerfile: laravel.Dockerfile
    restart: unless-stopped
    ports:
      - '127.0.0.1:8000:8000' # run on port 8000 localhost only, port 8000 on the container
    environment:
      ROADRUNNER_MAX_REQUESTS: 250
      ROADRUNNER_WATCH: "yes"
      ROADRUNNER_WORKERS: 6
      APP_NAME: "Example"
      APP_ENV: "local"
    volumes:
      - ./laravel-src:/srv/laravel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant