diff --git a/.devcontainer/.docker/php/Dockerfile b/.devcontainer/.docker/php/Dockerfile deleted file mode 100644 index 69265a0..0000000 --- a/.devcontainer/.docker/php/Dockerfile +++ /dev/null @@ -1,71 +0,0 @@ -# defined in docker-compose.yml, from docker-env.env -ARG RUNTIME_PHP_IMAGE - -# Use the specified image as the base -FROM ${RUNTIME_PHP_IMAGE} - -# create the log file and provide permission to the www-data user -RUN touch /tmp/xdebug.log && chown www-data:www-data /tmp/xdebug.log - -# same thing for the PHP error log -RUN touch /var/log/php-errors.log && chown www-data:www-data /var/log/php-errors.log - -# Update the packages -# Install system packages required for MongoDB extension -# 'mysql-client' so we can log into mysql from the PHP container with the command 'mysql -h mysql -u root -p' where mysql is the service name -# 'iputils-ping' to get the ping command -RUN apt-get update \ - && apt-get install -y libssl-dev wget git unzip default-mysql-client iputils-ping - -RUN pecl apt update \ - && apt install libzip-dev -y \ - && docker-php-ext-install zip \ - && rm -rf /var/lib/apt/lists/* - -# Required for MySQL to work in PHP -RUN docker-php-ext-install mysqli && \ - docker-php-ext-install pdo_mysql - -# Test if already installed and -# install the mongodb PHP extension -# RUN pecl install mongodb && docker-php-ext-enable mongodb -RUN bash -c '[[ -n "$(pecl list | grep mongodb)" ]]\ - || (pecl install mongodb && docker-php-ext-enable mongodb)' - -# Test if already installed and -# install and enable XDEBUG -# RUN pecl install xdebug && docker-php-ext-enable xdebug -RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\ - || (pecl install xdebug && docker-php-ext-enable xdebug)' - -# install Redis PHP driver -RUN pecl install -o -f redis \ -&& rm -rf /tmp/pear \ -&& docker-php-ext-enable redis \ -&& docker-php-ext-enable pdo_mysql - -# Task: copy rep's PHP .ini files to be automatically parsed -# -# directory is related to the PHP service context -# dot NOT use ./filename.ext for root files -# use filename.ext -COPY docker-php.ini /usr/local/etc/php/conf.d/ -COPY xdebug.ini /usr/local/etc/php/conf.d/ - -# Install Composer -# ---------------------------------------------------------- -# download composer -RUN curl -sS https://getcomposer.org/installer | php -# copy composer to a place where it can be globally executed -RUN mv composer.phar /usr/local/bin/composer - -# our repo is in var/www/htdoc -# COPY init_repo.sh /var/www/htdoc/ - -# Set the working directory in the container -WORKDIR /var/www/htdoc - -# start out script that runs composer install, but ONLY if /vendor/ does not exist -# WARNING: the commands below crash CodeSpaces. Not using for now. -#RUN chmod +x /var/www/htdoc/init_repo.sh -#ENTRYPOINT ["/var/www/htdoc/init_repo.sh"] \ No newline at end of file diff --git a/.devcontainer/.env b/.devcontainer/.env deleted file mode 100644 index 4248e91..0000000 --- a/.devcontainer/.env +++ /dev/null @@ -1,28 +0,0 @@ -# PATHs are relative to docker-compose.yml - -NGINX_IMAGE=nginx:alpine -NGINX_HOST_PORT=80 -NGINX_CONTAINER_PORT=80 -NGINX_HOST_CONFD_DIR=./.docker/nginx/conf.d -NGINX_CONTAINER_CONFD_DIR=/etc/nginx/conf.d - -PHP_WEBROOT_HOST_PATH=../.framework/php/src/ -PHP_WEBROOT_CONTAINER_PATH=/var/www/htdoc - -NGINX_WEBROOT_HOST_PATH=../src/ -NGINX_WEBROOT_CONTAINER_PATH=/var/www/htdoc - -MYSQL_IMAGE=mysql:5.7 -MYSQL_DATA_HOST_PATH=./data/mysql -MYSQL_DATA_CONTAINER_PATH=/var/lib/mysql -MYSQL_HOST_PORT=3306 -MYSQL_CONTAINER_PORT=3306 - -MYSQL_ROOT_PASSWORD=rootpassword -MYSQL_DATABASE=mydatabase - -PHP_IMAGE=php:8.2-fpm - - -REDIS_DATA_HOST_PATH=./data/redis -REDIS_DATA_CONTAINER_PATH=/etc/data \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f60d594..bf214b3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,37 +1,6 @@ { "name": "laravel-fresh-install", - // Mandatory definition for .devcontainer - // - // which service AS DEFINED IN .devcontainer/docker-compose.yml - // do we want VS Code to attach to? - // here, we choose the "php" service since that's where our code is executed - "service": "php", - - // we have multiple containers (nginx, PHP, MySQL, redis) - // so we'll use a compose .yml file instead of defining the services in devcontainer.json - "dockerComposeFile": "./docker-compose.yml", - - "shutdownAction": "stopCompose", - - // Mandatory definition for .devcontainer - // - // workspaceFolder describes the CONTAINER folder - // in which the "service" (php here) is configured to mount the project - // in our case, "/var/www/htdoc" refers to - // ${WEBROOT_HOST_PATH}:${WEBROOT_CONTAINER_PATH} in our "php" service "volumeS" - // these are defined in .devcontainer/.env as follows: - // WEBROOT_HOST_PATH=../src - // WEBROOT_CONTAINER_PATH=/var/www/htdoc - "workspaceFolder": "/var/www/htdoc", - - // NOT REQUIRED, because our mounts are defined in the .yml file - // - // mount defined in docker-compose.yml - //"mounts": [ - // "source=${localWorkspaceFolder},target=/src,type=bind" - //], - // "xdebug.php-debug" = official XDEBUG extension "customizations": { "vscode": { @@ -45,4 +14,4 @@ // execute our one-time repo init if /vendor/ does not exist "postCreateCommand": "sh init_repo.sh" -} \ No newline at end of file +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml deleted file mode 100644 index 6f4bdf4..0000000 --- a/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,84 +0,0 @@ -# build command: docker compose build -# docker uses the .env file BY DEFAULT. Any other name and you'll have to specify it in the command line -# docker compose --env-file FILENAME.env build - -# docker compose version -version: '3.4' - -# Services -services: - - # Nginx Service - nginx: - - image: ${NGINX_IMAGE} - ports: - - ${NGINX_HOST_PORT}:${NGINX_CONTAINER_PORT} - - # path is relative to where the docker-compose.yml file is. - # local-path : container-path - # - volumes: - # public web files - - ${NGINX_WEBROOT_HOST_PATH}:${NGINX_WEBROOT_CONTAINER_PATH} - # .ini location - - ${NGINX_HOST_CONFD_DIR}:${NGINX_CONTAINER_CONFD_DIR} - depends_on: - - php - - mysql_service - - # PHP Service - php: - build: - context: ./.docker/php - dockerfile: Dockerfile - args: - RUNTIME_PHP_IMAGE: ${PHP_IMAGE} - image: ${PHP_IMAGE} - # container-path - working_dir: ${PHP_WEBROOT_CONTAINER_PATH} - # disk local-path - volumes: - - ${PHP_WEBROOT_HOST_PATH}:${PHP_WEBROOT_CONTAINER_PATH} - # we don't need to expose the port 9003 here for Xdebug because the - # connection comes from inside the PHP container to the IDE via port 9003 - environment: - # laravel's default mysql config looks for the DATABASE_URL environment variable - - DATABASE_URL=mysql://root:${MYSQL_ROOT_PASSWORD}@mysql_service:3306/${MYSQL_DATABASE} - depends_on: - - mysql_service - - # MySQL Service - mysql_service: - image: ${MYSQL_IMAGE} - - environment: - MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} - MYSQL_DATABASE: ${MYSQL_DATABASE} - - # the two variales below don't seem to be used at all. Commenting out for now - #MYSQL_USER: myuser - #MYSQL_PASSWORD: mypassword - - # do NOT try mounting a volume in CodeSpaces as it will fail and MySQL will not launch (try pinging mysql_service) - # this is only useful when working locally on a website with a non-ephemeral database - #volumes: - # map local /data/ folder to container /var/lib/mysql for MySQL data persistence - # - ${MYSQL_DATA_HOST_PATH}:${MYSQL_DATA_CONTAINER_PATH} - - ports: - - "3306:3306" - # syntax = host_port:container_port - - -# redis: -# image: redis:latest -# ports: -# - "6379:6379" -# volumes: -# - ${REDIS_DATA_HOST_PATH}:${REDIS_DATA_CONTAINER_PATH} - -# Notes: -# -# From Docker Compose version 3.4 the name of the volume can be dynamically generated from environment variables placed in an .env file (this file has to be in the same folder as docker-compose.yml is). -# diff --git a/.devcontainer/.docker/nginx/conf.d/error_reporting.ini b/.docker/nginx/conf.d/error_reporting.ini similarity index 100% rename from .devcontainer/.docker/nginx/conf.d/error_reporting.ini rename to .docker/nginx/conf.d/error_reporting.ini diff --git a/.devcontainer/.docker/nginx/conf.d/nginx-webserver.conf b/.docker/nginx/conf.d/nginx-webserver.conf similarity index 100% rename from .devcontainer/.docker/nginx/conf.d/nginx-webserver.conf rename to .docker/nginx/conf.d/nginx-webserver.conf diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile new file mode 100644 index 0000000..1e86d9c --- /dev/null +++ b/.docker/php/Dockerfile @@ -0,0 +1,26 @@ +# defined in docker-compose.yml, from docker-env.env +ARG RUNTIME_PHP_IMAGE + +# Use the specified image as the base +FROM ${RUNTIME_PHP_IMAGE} + +# Install system dependencies and PHP extensions +RUN apt-get update && apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev zip git unzip && \ + docker-php-ext-configure gd --with-freetype --with-jpeg && \ + docker-php-ext-install gd pdo pdo_mysql + +# Test if already installed and +# install the mongodb PHP extension +# RUN pecl install mongodb && docker-php-ext-enable mongodb +RUN bash -c '[[ -n "$(pecl list | grep mongodb)" ]]\ + || (pecl install mongodb && docker-php-ext-enable mongodb)' + +# Test if already installed and +# install and enable XDEBUG +# RUN pecl install xdebug && docker-php-ext-enable xdebug +RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\ + || (pecl install xdebug && docker-php-ext-enable xdebug)' +# Get Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www/htdoc \ No newline at end of file diff --git a/.devcontainer/.docker/php/docker-php.ini b/.docker/php/docker-php.ini similarity index 100% rename from .devcontainer/.docker/php/docker-php.ini rename to .docker/php/docker-php.ini diff --git a/.devcontainer/.docker/php/xdebug.ini b/.docker/php/xdebug.ini similarity index 100% rename from .devcontainer/.docker/php/xdebug.ini rename to .docker/php/xdebug.ini diff --git a/.framework/php/docker-compose.yml b/.framework/php/docker-compose.yml new file mode 100644 index 0000000..86c41fe --- /dev/null +++ b/.framework/php/docker-compose.yml @@ -0,0 +1,62 @@ +# build command: docker compose build +# docker uses the .env file BY DEFAULT. Any other name and you'll have to specify it in the command line +# docker compose --env-file FILENAME.env build + +# docker compose version +version: '3.4' + +# Services +services: + + # Nginx Service + nginx: + + image: nginx:alpine + ports: + - 80:80 + volumes: + - ./src:/var/www/htdoc + - ./.docker/nginx/conf.d:/etc/nginx/conf.d + depends_on: + - php + - mysql_service + + # PHP Service + php: + build: + context: ./.docker/php + dockerfile: Dockerfile + args: + RUNTIME_PHP_IMAGE: php:8.2-fpm + image: php:8.2-fpm + # container-path + working_dir: /var/www/htdoc + volumes: + - ./src:/var/www/htdoc + environment: + - DATABASE_URL=mysql://root:rootpassword@mysql_service:3306/mydatabase + depends_on: + - mysql_service + + + + # MySQL Service + mysql_service: + image: mysql:5.7 + + environment: + MYSQL_ROOT_PASSWORD: rootpassword + MYSQL_DATABASE: mydatabase + + +# redis: +# image: redis:latest +# ports: +# - "6379:6379" +# volumes: +# - ${REDIS_DATA_HOST_PATH}:${REDIS_DATA_CONTAINER_PATH} + +# Notes: +# +# From Docker Compose version 3.4 the name of the volume can be dynamically generated from environment variables placed in an .env file (this file has to be in the same folder as docker-compose.yml is). +#