diff --git a/.gitignore b/.gitignore index 9d5dff3..3269239 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ Homestead.json /.vagrant .phpunit.result.cache +# src Ordner mit Laravel Intallations Files +src/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..185193a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,137 @@ +version: '3' + +networks: + rauru_net: + +volumes: + local_pgdata_rauru: + pgadmin-data: + +services: + app: + container_name: rauru_app + build: + context: ./dockerfiles + dockerfile: nginx.dockerfile + args: + - UID=${UID:-1000} + - GID=${GID:-1000} + ports: + - "80:80" + volumes: + - ./src:/var/www/html:delegated + depends_on: + - php + - redis + - db + - mailhog + - pgadmin + networks: + - rauru_net + db: + image: postgres + container_name: rauru_db + ports: + - "5432:5432" + environment: + POSTGRES_DB: rauru_db + POSTGRES_USER: rauru_user + POSTGRES_PASSWORD: secret + volumes: + - local_pgdata_rauru:/var/lib/postgresql/data + #- ./rauru_pgdata:/var/lib/postgresql/data + networks: + - rauru_net + pgadmin: + image: dpage/pgadmin4 + container_name: rauru_pgAdmin + ports: + - "5050:80" + depends_on: + - db + environment: + PGADMIN_DEFAULT_EMAIL: admin@example.de + PGADMIN_DEFAULT_PASSWORD: secret + volumes: + - pgadmin-data:/var/lib/pgadmin + #- ./pgadmindata:/var/lib/pgadmin + networks: + - rauru_net + php: + build: + context: ./dockerfiles + dockerfile: php.root.dockerfile + args: + - UID=${UID:-1000} + - GID=${GID:-1000} + container_name: rauru_php + ports: + - "9000:9000" + volumes: + - ./src:/var/www/html:delegated + networks: + - rauru_net + + redis: + image: redis:alpine + container_name: rauru_redis + restart: unless-stopped + ports: + - "6379:6379" + networks: + - rauru_net + + composer: + build: + context: ./dockerfiles + dockerfile: php.root.dockerfile + args: + - UID=${UID:-1000} + - GID=${GID:-1000} + container_name: rauru_composer + volumes: + - ./src:/var/www/html + depends_on: + - php + entrypoint: [ 'composer', '--ignore-platform-reqs' ] + networks: + - rauru_net + + npm: + image: node:current-alpine + container_name: rauru_npm + volumes: + - ./src:/var/www/html + ports: + - "3000:3000" + - "3001:3001" + - "5173:5173" + working_dir: /var/www/html + entrypoint: [ 'npm' ] + networks: + - rauru_net + + artisan: + build: + context: ./dockerfiles + dockerfile: php.root.dockerfile + args: + - UID=${UID:-1000} + - GID=${GID:-1000} + container_name: rauru_artisan + volumes: + - ./src:/var/www/html:delegated + depends_on: + - db + entrypoint: [ 'php', '/var/www/html/artisan' ] + networks: + - rauru_net + + mailhog: + container_name: rauru_mailhog + image: mailhog/mailhog:latest + ports: + - "1025:1025" + - "8025:8025" + networks: + - rauru_net diff --git a/dockerfiles/nginx.dockerfile b/dockerfiles/nginx.dockerfile new file mode 100644 index 0000000..977e2f0 --- /dev/null +++ b/dockerfiles/nginx.dockerfile @@ -0,0 +1,18 @@ +FROM nginx:stable-alpine + +ARG UID +ARG GID + +ENV UID=${UID} +ENV GID=${GID} + +# MacOS staff group's gid is 20, so is the dialout group in alpine linux. We're not using it, let's just remove it. +RUN delgroup dialout + +RUN addgroup -g ${GID} --system laravel +RUN adduser -G laravel --system -D -s /bin/sh -u ${UID} laravel +RUN sed -i "s/user nginx/user laravel/g" /etc/nginx/nginx.conf + +ADD ./nginx/default.conf /etc/nginx/conf.d/ + +RUN mkdir -p /var/www/html \ No newline at end of file diff --git a/dockerfiles/nginx/default.conf b/dockerfiles/nginx/default.conf new file mode 100644 index 0000000..282633d --- /dev/null +++ b/dockerfiles/nginx/default.conf @@ -0,0 +1,20 @@ +server { + listen 80; + index index.php index.html; + server_name _; + root /var/www/html/public; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass php:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} diff --git a/dockerfiles/php.dockerfile b/dockerfiles/php.dockerfile new file mode 100644 index 0000000..c834ac6 --- /dev/null +++ b/dockerfiles/php.dockerfile @@ -0,0 +1,38 @@ +FROM php:8-fpm-alpine + +ARG UID +ARG GID + +ENV UID=${UID} +ENV GID=${GID} + +RUN mkdir -p /var/www/html + +WORKDIR /var/www/html + +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer + +# MacOS staff group's gid is 20, so is the dialout group in alpine linux. We're not using it, let's just remove it. +RUN delgroup dialout + +RUN addgroup -g ${GID} --system laravel +RUN adduser -G laravel --system -D -s /bin/sh -u ${UID} laravel + +RUN sed -i "s/user = www-data/user = laravel/g" /usr/local/etc/php-fpm.d/www.conf +RUN sed -i "s/group = www-data/group = laravel/g" /usr/local/etc/php-fpm.d/www.conf +RUN echo "php_admin_flag[log_errors] = on" >> /usr/local/etc/php-fpm.d/www.conf + +RUN set -ex \ + && apk --no-cache add \ + postgresql-dev + +RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql + +RUN mkdir -p /usr/src/php/ext/redis \ + && curl -L https://github.com/phpredis/phpredis/archive/5.3.4.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \ + && echo 'redis' >> /usr/src/php-available-exts \ + && docker-php-ext-install redis + +USER laravel + +CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"] diff --git a/dockerfiles/php.root.dockerfile b/dockerfiles/php.root.dockerfile new file mode 100644 index 0000000..ab5e324 --- /dev/null +++ b/dockerfiles/php.root.dockerfile @@ -0,0 +1,26 @@ +FROM php:8-fpm-alpine + +RUN mkdir -p /var/www/html + +WORKDIR /var/www/html + +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer + +RUN sed -i "s/user = www-data/user = root/g" /usr/local/etc/php-fpm.d/www.conf +RUN sed -i "s/group = www-data/group = root/g" /usr/local/etc/php-fpm.d/www.conf +RUN echo "php_admin_flag[log_errors] = on" >> /usr/local/etc/php-fpm.d/www.conf + +RUN set -ex \ + && apk --no-cache add \ + postgresql-dev + +RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql + +RUN mkdir -p /usr/src/php/ext/redis \ + && curl -L https://github.com/phpredis/phpredis/archive/5.3.4.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \ + && echo 'redis' >> /usr/src/php-available-exts \ + && docker-php-ext-install redis + +USER root + +CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]