Skip to content

Merge dev into master #2

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

Merged
merged 18 commits into from
Sep 11, 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
1 change: 1 addition & 0 deletions .devcontainer/.docker/nginx/conf.d/error_reporting.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error_reporting=E_ALL
38 changes: 38 additions & 0 deletions .devcontainer/.docker/nginx/conf.d/nginx-webserver.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# this server config works with Laravel too
server {
listen 80;
listen [::]:80 default_server;

# not needed for now
# server_name example.com;

root /var/www/htdoc/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

error_page 404 /index.php;

location ~* \.php$ {
fastcgi_pass php:9000;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
71 changes: 71 additions & 0 deletions .devcontainer/.docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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 <latest> 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 <latest>
# 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"]
1 change: 1 addition & 0 deletions .devcontainer/.docker/php/docker-php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# hubert stuff
41 changes: 41 additions & 0 deletions .devcontainer/.docker/php/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; already loaded in /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
;zend_extension=xdebug

; FIXME : should be elsewhere, like docker-php.ini
error_log = /var/log/php-errors.log
catch_workers_output = yes

[xdebug]
; 'debug' means we're enabling step-by-step debugging
xdebug.mode=debug

xdebug.client_port=9003

; xdebug.client_host is the IP address of the system where VS Code runs
; that IP address is DIFFERENT depending on WHERE VS Code is launched in Windows/Mac, WSL, Container/devcontainer/codespaces
;
; the PHP container sends debugging data OUT to xdebug.client_host:xdebug.client_port


; localhost is used when running btoh VS Code and PHP from within **the same PHP container**
; after opening the project in the Container
xdebug.client_host=localhost

; if using Docker Desktop 'host.docker.internal' is supposed to hold the IP Address of
; the Docker host, but that's not always true. DOUBLE-CHECK

;xdebug.client_host=host.docker.internal

; 'yes': This will always initiate a debugging, profiling, or tracing session as soon as a request is received, without needing any specific trigger
; 'no' : This will never initiate a session regardless of the presence of any trigger
; 'trigger' : This will initiate a session only if a specific trigger, like a GET/POST variable or a cookie, is present in the request.
xdebug.start_with_request=yes

; OPTIONAL: idekey
; in the browser add a URL param , if not using a browser utility
; url.to.debug?XDEBUG_SESSION_START=PHPSTORM
; sets up a coockie called "XDEBUG_SESSION_START" with the value "PHPSTORM", which is the "trigger"
; xdebug.idekey=PHPSTORM

; defines a log file. This is created, with touch, and initialized (permissions) in the PHP container Dockerfile
xdebug.log=/tmp/xdebug.log
28 changes: 28 additions & 0 deletions .devcontainer/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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=../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
2 changes: 2 additions & 0 deletions .devcontainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/data/
/www/
48 changes: 48 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "laravel9-mongodb-tutorial",

// 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": {
"extensions": [
"xdebug.php-debug"
]
}
},

"forwardPorts": [80],

// execute our one-time repo init if /vendor/ does not exist
"postCreateCommand": "sh init_repo.sh"
}
84 changes: 84 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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).
#
53 changes: 53 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
// ${workspaceFolder} == directory where /.vscode/ is
// the syntax is SERVER_PATH : LOCAL_PATH
"pathMappings": {
"/var/www/htdoc": "${workspaceFolder}/src"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
Loading