simple laravel container

This commit is contained in:
2023-03-11 13:00:48 +01:00
commit 2d32c9f2ec
5 changed files with 125 additions and 0 deletions

19
.env.example Normal file
View File

@@ -0,0 +1,19 @@
# the laravel version to install (empty for latest)
LARAVEL_VERSION=
# weather to run "npm dev run" at boot
AUTO_START_NPM_DEV=true
# external ports
FORWARD_LARAVEL_PORT=80
FORWARD_VITE_PORT=5173
FORWARD_DB_PORT=3306
FORWARD_REDIS_PORT=6379
FORWARD_MAILPIT_PORT=1025
FORWARD_MAILPIT_DASHBOARD_PORT=8025
# DB settings (this will overwrite the defaults in the laravel project)
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=password

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.env
.env.*
!*.env.example
.idea

25
build/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
FROM composer:latest
ARG USERNAME=laravel
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN apk add --no-cache nodejs npm zlib-dev libpng-dev \
&& npm install -g npm \
&& rm -rf /tmp/* /var/tmp/*
RUN docker-php-ext-install mysqli pdo pdo_mysql gd
RUN addgroup -g $USER_GID -S $USERNAME \
&& adduser -u $USER_UID -S $USERNAME -G $USERNAME
COPY start-container /usr/local/bin/start-container
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8080
WORKDIR /var/www/html
USER $USERNAME
ENTRYPOINT ["start-container"]

22
build/start-container Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# exit when any command fails
set -e
if [ ! -f /var/www/html/artisan ]; then
echo "No existing Laravel project found"
composer create-project laravel/laravel /var/www/html "$LARAVEL_VERSION"
npm install -D tailwindcss postcss autoprefixer --prefix /var/www/html
sed -i "/export default defineConfig({/a\ server: {host: '0.0.0.0'}," /var/www/html/vite.config.js
echo -e "@tailwind base;\n@tailwind components;\n@tailwind utilities;" >> /var/www/html/resources/css/app.css
echo -e '/** @type {import('tailwindcss').Config} */\nmodule.exports = {\n content: [\n "./resources/**/*.blade.php",\n "./resources/**/*.js",\n "./resources/**/*.vue",\n ],\n theme: {\n extend: {},\n },\n plugins: [],\n}' > /var/www/html/tailwind.config.js
npx tailwindcss init -p
fi
if [[ "$AUTO_START_NPM_DEV" = true ]]; then
echo "Staring npm dev"
npm run dev --prefix /var/www/html &
fi
echo "Staring Laravel"
php /var/www/html/artisan serve --host=0.0.0.0 --port=8080

54
docker-compose.yml Normal file
View File

@@ -0,0 +1,54 @@
version: '3'
services:
app:
build:
context: build
dockerfile: Dockerfile
image: laravel
ports:
- '${FORWARD_LARAVEL_PORT:-80}:8080'
- '${FORWARD_VITE_PORT:-5173}:5173'
environment:
LARAVEL_VERSION: '${LARAVEL_VERSION}'
AUTO_START_NPM_DEV: '${AUTO_START_NPM_DEV:-false}'
DB_HOST: mysql
DB_CONNECTION: mysql
env_file:
.env
depends_on:
- mysql
- redis
- mailpit
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'mysql:/var/lib/mysql'
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'redis:/data'
mailpit:
image: 'axllent/mailpit:latest'
ports:
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
volumes:
mysql:
driver: local
redis:
driver: local