From 02d356e93aee66ff348b94beb8aa440773d240b9 Mon Sep 17 00:00:00 2001 From: Marty Sloan Date: Sat, 16 Sep 2023 15:24:32 -0400 Subject: [PATCH 1/9] Add support for vite builds --- Dockerfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Dockerfile b/Dockerfile index ded87a0..88a7f90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,20 @@ ARG COMPOSER_VERSION=latest # Accepted values: swoole - roadrunner ARG OCTANE_SERVER="swoole" +########################################### +# Vite Build +########################################### + +FROM node:18-bullseye-slim as vite + +RUN mkdir -p /var/www/html + +WORKDIR /var/www/html + +COPY . . + +RUN npm install && npm run build + ########################################### # PHP dependencies ########################################### @@ -302,6 +316,7 @@ RUN apt-get clean \ && rm /var/log/lastlog /var/log/faillog COPY . . +COPY --from=vite ${ROOT}/public public COPY --from=vendor ${ROOT}/vendor vendor COPY --from=vendor ${ROOT}/rr* ${ROOT}/composer.json ./ From 70bf06eda015e18e86f59ecbf898d0816d2534ab Mon Sep 17 00:00:00 2001 From: smortexa Date: Sun, 17 Sep 2023 23:29:38 +0330 Subject: [PATCH 2/9] wip --- Dockerfile | 206 +++++++++++++++++++++++++++++------------------------ README.md | 2 +- 2 files changed, 112 insertions(+), 96 deletions(-) diff --git a/Dockerfile b/Dockerfile index 88a7f90..8ca93f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,18 +7,34 @@ ARG COMPOSER_VERSION=latest ARG OCTANE_SERVER="swoole" ########################################### -# Vite Build +# Build frontend assets with NPM ########################################### -FROM node:18-bullseye-slim as vite +ARG NODE_VERSION=18-bullseye-slim -RUN mkdir -p /var/www/html +FROM node:${NODE_VERSION} as build -WORKDIR /var/www/html +ENV ROOT=/var/www/html + +WORKDIR $ROOT + +RUN npm config set update-notifier false && npm set progress=false + +COPY package*.json ./ + +RUN if [ -f $ROOT/package-lock.json ]; \ + then \ + NODE_ENV=production npm ci --no-optional --loglevel=error --no-audit; \ + else \ + NODE_ENV=production npm install --no-optional --loglevel=error --no-audit; \ + fi COPY . . -RUN npm install && npm run build +RUN if [ -f $ROOT/package.json ] || [ -f $ROOT/package-lock.json ]; \ + then \ + npm install && npm run build; \ + fi ########################################### # PHP dependencies @@ -44,11 +60,11 @@ RUN composer install \ ########################################### RUN if [ ${OCTANE_SERVER} = "roadrunner" ]; then \ - if composer show | grep spiral/roadrunner-cli >/dev/null; then \ - ./vendor/bin/rr get-binary; else \ - echo "spiral/roadrunner-cli package is not installed. exiting..."; exit 1; \ - fi \ - fi + if composer show | grep spiral/roadrunner-cli >/dev/null; then \ + ./vendor/bin/rr get-binary; else \ + echo "spiral/roadrunner-cli package is not installed. exiting..."; exit 1; \ + fi \ + fi ########################################### @@ -69,11 +85,11 @@ ARG APP_WITH_HORIZON=false ARG APP_WITH_SCHEDULER=false ENV DEBIAN_FRONTEND=noninteractive \ - TERM=xterm-color \ - CONTAINER_MODE=${CONTAINER_MODE} \ - APP_WITH_HORIZON=${APP_WITH_HORIZON} \ - APP_WITH_SCHEDULER=${APP_WITH_SCHEDULER} \ - OCTANE_SERVER=${OCTANE_SERVER} + TERM=xterm-color \ + CONTAINER_MODE=${CONTAINER_MODE} \ + APP_WITH_HORIZON=${APP_WITH_HORIZON} \ + APP_WITH_SCHEDULER=${APP_WITH_SCHEDULER} \ + OCTANE_SERVER=${OCTANE_SERVER} ENV ROOT=/var/www/html WORKDIR $ROOT @@ -81,41 +97,41 @@ WORKDIR $ROOT SHELL ["/bin/bash", "-eou", "pipefail", "-c"] RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ - && echo $TZ > /etc/timezone + && echo $TZ > /etc/timezone RUN apt-get update; \ - apt-get upgrade -yqq; \ - pecl -q channel-update pecl.php.net; \ - apt-get install -yqq --no-install-recommends --show-progress \ - apt-utils \ - gnupg \ - gosu \ - git \ - curl \ - wget \ - libcurl4-openssl-dev \ - ca-certificates \ - supervisor \ - libmemcached-dev \ - libz-dev \ - libbrotli-dev \ - libpq-dev \ - libjpeg-dev \ - libpng-dev \ - libfreetype6-dev \ - libssl-dev \ - libwebp-dev \ - libmcrypt-dev \ - libonig-dev \ - libzip-dev zip unzip \ - libargon2-1 \ - libidn2-0 \ - libpcre2-8-0 \ - libpcre3 \ - libxml2 \ - libzstd1 \ - procps \ - libbz2-dev + apt-get upgrade -yqq; \ + pecl -q channel-update pecl.php.net; \ + apt-get install -yqq --no-install-recommends --show-progress \ + apt-utils \ + gnupg \ + gosu \ + git \ + curl \ + wget \ + libcurl4-openssl-dev \ + ca-certificates \ + supervisor \ + libmemcached-dev \ + libz-dev \ + libbrotli-dev \ + libpq-dev \ + libjpeg-dev \ + libpng-dev \ + libfreetype6-dev \ + libssl-dev \ + libwebp-dev \ + libmcrypt-dev \ + libonig-dev \ + libzip-dev zip unzip \ + libargon2-1 \ + libidn2-0 \ + libpcre2-8-0 \ + libpcre3 \ + libxml2 \ + libzstd1 \ + procps \ + libbz2-dev ########################################### @@ -147,11 +163,11 @@ RUN docker-php-ext-install mbstring; ########################################### RUN docker-php-ext-configure gd \ - --prefix=/usr \ - --with-jpeg \ - --with-webp \ - --with-freetype \ - && docker-php-ext-install gd; + --prefix=/usr \ + --with-jpeg \ + --with-webp \ + --with-freetype \ + && docker-php-ext-install gd; ########################################### # OPcache @@ -160,7 +176,7 @@ RUN docker-php-ext-configure gd \ ARG INSTALL_OPCACHE=true RUN if [ ${INSTALL_OPCACHE} = true ]; then \ - docker-php-ext-install opcache; \ + docker-php-ext-install opcache; \ fi ########################################### @@ -170,9 +186,9 @@ RUN if [ ${INSTALL_OPCACHE} = true ]; then \ ARG INSTALL_PHPREDIS=true RUN if [ ${INSTALL_PHPREDIS} = true ]; then \ - pecl -q install -o -f redis \ - && rm -rf /tmp/pear \ - && docker-php-ext-enable redis; \ + pecl -q install -o -f redis \ + && rm -rf /tmp/pear \ + && docker-php-ext-enable redis; \ fi ########################################### @@ -182,7 +198,7 @@ RUN if [ ${INSTALL_PHPREDIS} = true ]; then \ ARG INSTALL_PCNTL=true RUN if [ ${INSTALL_PCNTL} = true ]; then \ - docker-php-ext-install pcntl; \ + docker-php-ext-install pcntl; \ fi ########################################### @@ -192,7 +208,7 @@ RUN if [ ${INSTALL_PCNTL} = true ]; then \ ARG INSTALL_BCMATH=true RUN if [ ${INSTALL_BCMATH} = true ]; then \ - docker-php-ext-install bcmath; \ + docker-php-ext-install bcmath; \ fi ########################################### @@ -202,9 +218,9 @@ RUN if [ ${INSTALL_BCMATH} = true ]; then \ ARG INSTALL_RDKAFKA=true RUN if [ ${INSTALL_RDKAFKA} = true ]; then \ - apt-get install -yqq --no-install-recommends --show-progress librdkafka-dev \ - && pecl -q install -o -f rdkafka \ - && docker-php-ext-enable rdkafka; \ + apt-get install -yqq --no-install-recommends --show-progress librdkafka-dev \ + && pecl -q install -o -f rdkafka \ + && docker-php-ext-enable rdkafka; \ fi ########################################### @@ -214,9 +230,9 @@ RUN if [ ${INSTALL_RDKAFKA} = true ]; then \ ARG SERVER=swoole RUN if [ ${OCTANE_SERVER} = "swoole" ]; then \ - apt-get install -yqq --no-install-recommends --show-progress libc-ares-dev \ - && pecl -q install -o -f -D 'enable-openssl="yes" enable-http2="yes" enable-swoole-curl="yes" enable-mysqlnd="yes" enable-cares="yes"' ${SERVER} \ - && docker-php-ext-enable ${SERVER}; \ + apt-get install -yqq --no-install-recommends --show-progress libc-ares-dev \ + && pecl -q install -o -f -D 'enable-openssl="yes" enable-http2="yes" enable-swoole-curl="yes" enable-mysqlnd="yes" enable-cares="yes"' ${SERVER} \ + && docker-php-ext-enable ${SERVER}; \ fi ########################################################################### @@ -226,9 +242,9 @@ RUN if [ ${OCTANE_SERVER} = "swoole" ]; then \ ARG INSTALL_INTL=true RUN if [ ${INSTALL_INTL} = true ]; then \ - apt-get install -yqq --no-install-recommends --show-progress zlib1g-dev libicu-dev g++ \ - && docker-php-ext-configure intl \ - && docker-php-ext-install intl; \ + apt-get install -yqq --no-install-recommends --show-progress zlib1g-dev libicu-dev g++ \ + && docker-php-ext-configure intl \ + && docker-php-ext-install intl; \ fi ########################################### @@ -238,7 +254,7 @@ RUN if [ ${INSTALL_INTL} = true ]; then \ ARG INSTALL_MEMCACHED=false RUN if [ ${INSTALL_MEMCACHED} = true ]; then \ - pecl -q install -o -f memcached && docker-php-ext-enable memcached; \ + pecl -q install -o -f memcached && docker-php-ext-enable memcached; \ fi ########################################### @@ -248,7 +264,7 @@ RUN if [ ${INSTALL_MEMCACHED} = true ]; then \ ARG INSTALL_MYSQL_CLIENT=true RUN if [ ${INSTALL_MYSQL_CLIENT} = true ]; then \ - apt-get install -yqq --no-install-recommends --show-progress default-mysql-client; \ + apt-get install -yqq --no-install-recommends --show-progress default-mysql-client; \ fi ########################################### @@ -258,7 +274,7 @@ RUN if [ ${INSTALL_MYSQL_CLIENT} = true ]; then \ ARG INSTALL_PDO_PGSQL=false RUN if [ ${INSTALL_PDO_PGSQL} = true ]; then \ - docker-php-ext-install pdo_pgsql; \ + docker-php-ext-install pdo_pgsql; \ fi ########################################### @@ -268,7 +284,7 @@ RUN if [ ${INSTALL_PDO_PGSQL} = true ]; then \ ARG INSTALL_PGSQL=false RUN if [ ${INSTALL_PGSQL} = true ]; then \ - docker-php-ext-install pgsql; \ + docker-php-ext-install pgsql; \ fi ########################################### @@ -279,16 +295,16 @@ ARG INSTALL_PG_CLIENT=false ARG INSTALL_POSTGIS=false RUN if [ ${INSTALL_PG_CLIENT} = true ]; then \ - apt-get install -yqq gnupg \ - && . /etc/os-release \ - && echo "deb http://apt.postgresql.org/pub/repos/apt $VERSION_CODENAME-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ - && curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ - && apt-get update -yqq \ - && apt-get install -yqq --no-install-recommends --show-progress postgresql-client-12 postgis; \ - if [ ${INSTALL_POSTGIS} = true ]; then \ - apt-get install -yqq --no-install-recommends --show-progress postgis; \ - fi \ - && apt-get purge -yqq gnupg; \ + apt-get install -yqq gnupg \ + && . /etc/os-release \ + && echo "deb http://apt.postgresql.org/pub/repos/apt $VERSION_CODENAME-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ + && curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ + && apt-get update -yqq \ + && apt-get install -yqq --no-install-recommends --show-progress postgresql-client-12 postgis; \ + if [ ${INSTALL_POSTGIS} = true ]; then \ + apt-get install -yqq --no-install-recommends --show-progress postgis; \ + fi \ + && apt-get purge -yqq gnupg; \ fi ########################################### @@ -296,27 +312,27 @@ RUN if [ ${INSTALL_PG_CLIENT} = true ]; then \ ########################################### RUN if [ ${CONTAINER_MODE} = 'scheduler' ] || [ ${APP_WITH_SCHEDULER} = true ]; then \ - wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.26/supercronic-linux-amd64" \ - -O /usr/bin/supercronic \ - && chmod +x /usr/bin/supercronic \ - && mkdir -p /etc/supercronic \ - && echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel; \ + wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.26/supercronic-linux-amd64" \ + -O /usr/bin/supercronic \ + && chmod +x /usr/bin/supercronic \ + && mkdir -p /etc/supercronic \ + && echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel; \ fi ########################################### RUN groupadd --force -g $WWWGROUP octane \ - && useradd -ms /bin/bash --no-log-init --no-user-group -g $WWWGROUP -u $WWWUSER octane + && useradd -ms /bin/bash --no-log-init --no-user-group -g $WWWGROUP -u $WWWUSER octane RUN apt-get clean \ - && docker-php-source delete \ - && pecl clear-cache \ - && rm -R /tmp/pear \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ - && rm /var/log/lastlog /var/log/faillog + && docker-php-source delete \ + && pecl clear-cache \ + && rm -R /tmp/pear \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ + && rm /var/log/lastlog /var/log/faillog COPY . . -COPY --from=vite ${ROOT}/public public +COPY --from=build ${ROOT}/public public COPY --from=vendor ${ROOT}/vendor vendor COPY --from=vendor ${ROOT}/rr* ${ROOT}/composer.json ./ @@ -335,7 +351,7 @@ COPY deployment/octane/.rr.prod.yaml ./.rr.yaml RUN chmod +x deployment/octane/entrypoint.sh RUN if [ -f "rr" ]; then \ - chmod +x rr; \ + chmod +x rr; \ fi RUN cat deployment/octane/utilities.sh >> ~/.bashrc diff --git a/README.md b/README.md index 8b79a75..8943a61 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Also, some useful Bash functions and aliases are added in `utilities.sh` that ma ## ToDo - [x] Add support for Horizon - [x] Add support for RoadRunner -- [ ] Add support for the full-stack apps (Front-end assets) +- [x] Add support for the full-stack apps (Front-end assets) - [ ] Add support `testing` environment and CI - [x] Add support for the Laravel scheduler - [ ] Add support for Laravel Dusk From 8dc00a9690b6cd09a588acdebe544c72076d0d07 Mon Sep 17 00:00:00 2001 From: smortexa Date: Sun, 17 Sep 2023 23:46:27 +0330 Subject: [PATCH 3/9] wip --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ca93f7..eb0a828 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,8 @@ COPY package*.json ./ RUN if [ -f $ROOT/package-lock.json ]; \ then \ NODE_ENV=production npm ci --no-optional --loglevel=error --no-audit; \ - else \ + elif [ -f $ROOT/package.json ]; \ + then \ NODE_ENV=production npm install --no-optional --loglevel=error --no-audit; \ fi @@ -33,7 +34,7 @@ COPY . . RUN if [ -f $ROOT/package.json ] || [ -f $ROOT/package-lock.json ]; \ then \ - npm install && npm run build; \ + npm run build; \ fi ########################################### From 31d901e9a174fd26cc90418b1bd990ee013ddd96 Mon Sep 17 00:00:00 2001 From: Marty Sloan Date: Tue, 19 Sep 2023 19:29:29 -0400 Subject: [PATCH 4/9] Remove NODE_ENV=production for front end builds --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index eb0a828..f7739d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,10 @@ COPY package*.json ./ RUN if [ -f $ROOT/package-lock.json ]; \ then \ - NODE_ENV=production npm ci --no-optional --loglevel=error --no-audit; \ + npm ci --no-optional --loglevel=error --no-audit; \ elif [ -f $ROOT/package.json ]; \ then \ - NODE_ENV=production npm install --no-optional --loglevel=error --no-audit; \ + npm install --no-optional --loglevel=error --no-audit; \ fi COPY . . From 76dc2f91073ed8ac9a03644a7f2d6894cd666954 Mon Sep 17 00:00:00 2001 From: smortexa Date: Wed, 20 Sep 2023 21:08:20 +0330 Subject: [PATCH 5/9] wip --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f7739d7..68b0255 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,10 +32,7 @@ RUN if [ -f $ROOT/package-lock.json ]; \ COPY . . -RUN if [ -f $ROOT/package.json ] || [ -f $ROOT/package-lock.json ]; \ - then \ - npm run build; \ - fi +RUN npm run build ########################################### # PHP dependencies From 8d2b8af0fcc0a6c99319992bd857c563b1f7d8f3 Mon Sep 17 00:00:00 2001 From: smortexa Date: Wed, 20 Sep 2023 21:38:53 +0330 Subject: [PATCH 6/9] wip --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 68b0255..359a5f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ WORKDIR $ROOT RUN npm config set update-notifier false && npm set progress=false -COPY package*.json ./ +COPY ./package*.json ./ RUN if [ -f $ROOT/package-lock.json ]; \ then \ From 3d004857f9ee1a1029f90e36ffddc77374175d7b Mon Sep 17 00:00:00 2001 From: smortexa Date: Wed, 20 Sep 2023 22:04:43 +0330 Subject: [PATCH 7/9] wip --- .dockerignore | 2 -- Dockerfile | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 3650e15..2a10633 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,4 @@ **/node_modules -package-lock.json -package.json public/hot public/storage storage/*.key diff --git a/Dockerfile b/Dockerfile index 359a5f3..8b6df74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,14 +20,14 @@ WORKDIR $ROOT RUN npm config set update-notifier false && npm set progress=false -COPY ./package*.json ./ +COPY package*.json ./ RUN if [ -f $ROOT/package-lock.json ]; \ then \ - npm ci --no-optional --loglevel=error --no-audit; \ + NODE_ENV=production npm ci --no-optional --loglevel=error --no-audit; \ elif [ -f $ROOT/package.json ]; \ then \ - npm install --no-optional --loglevel=error --no-audit; \ + NODE_ENV=production npm install --no-optional --loglevel=error --no-audit; \ fi COPY . . From 5a2af75527e4c924f08f6e45318ffb7098ab69b1 Mon Sep 17 00:00:00 2001 From: smortexa Date: Wed, 20 Sep 2023 22:06:41 +0330 Subject: [PATCH 8/9] wip --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b6df74..68b0255 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,10 @@ COPY package*.json ./ RUN if [ -f $ROOT/package-lock.json ]; \ then \ - NODE_ENV=production npm ci --no-optional --loglevel=error --no-audit; \ + npm ci --no-optional --loglevel=error --no-audit; \ elif [ -f $ROOT/package.json ]; \ then \ - NODE_ENV=production npm install --no-optional --loglevel=error --no-audit; \ + npm install --no-optional --loglevel=error --no-audit; \ fi COPY . . From 4a610f48d0596aa03b970ad80d7079bb536a1eac Mon Sep 17 00:00:00 2001 From: smortexa Date: Wed, 20 Sep 2023 22:09:53 +0330 Subject: [PATCH 9/9] wip --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 68b0255..f7739d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,10 @@ RUN if [ -f $ROOT/package-lock.json ]; \ COPY . . -RUN npm run build +RUN if [ -f $ROOT/package.json ] || [ -f $ROOT/package-lock.json ]; \ + then \ + npm run build; \ + fi ########################################### # PHP dependencies