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

Feat/vite (front end) build #43

Merged
merged 9 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
**/node_modules
package-lock.json
package.json
public/hot
public/storage
storage/*.key
Expand Down
210 changes: 121 additions & 89 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ ARG COMPOSER_VERSION=latest
# Accepted values: swoole - roadrunner
ARG OCTANE_SERVER="swoole"

###########################################
# Build frontend assets with NPM
###########################################

ARG NODE_VERSION=18-bullseye-slim

FROM node:${NODE_VERSION} as build

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 \
npm ci --no-optional --loglevel=error --no-audit; \
elif [ -f $ROOT/package.json ]; \
then \
npm install --no-optional --loglevel=error --no-audit; \
fi

COPY . .

RUN if [ -f $ROOT/package.json ] || [ -f $ROOT/package-lock.json ]; \
then \
npm run build; \
fi

###########################################
# PHP dependencies
###########################################
Expand All @@ -30,11 +61,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

###########################################

Expand All @@ -55,53 +86,53 @@ 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

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


###########################################
Expand Down Expand Up @@ -133,11 +164,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
Expand All @@ -146,7 +177,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

###########################################
Expand All @@ -156,9 +187,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

###########################################
Expand All @@ -168,7 +199,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

###########################################
Expand All @@ -178,7 +209,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

###########################################
Expand All @@ -188,9 +219,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

###########################################
Expand All @@ -200,9 +231,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

###########################################################################
Expand All @@ -212,9 +243,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

###########################################
Expand All @@ -224,7 +255,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

###########################################
Expand All @@ -234,7 +265,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

###########################################
Expand All @@ -244,7 +275,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

###########################################
Expand All @@ -254,7 +285,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

###########################################
Expand All @@ -265,43 +296,44 @@ 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

###########################################
# Laravel scheduler
###########################################

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=build ${ROOT}/public public
COPY --from=vendor ${ROOT}/vendor vendor
COPY --from=vendor ${ROOT}/rr* ${ROOT}/composer.json ./

Expand All @@ -320,7 +352,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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading