diff --git a/docker/containers/composer/Dockerfile b/docker/containers/composer/Dockerfile index ce12d37..8abefaa 100644 --- a/docker/containers/composer/Dockerfile +++ b/docker/containers/composer/Dockerfile @@ -3,8 +3,8 @@ # - use the image tag php:php-8.1-fpm-alpine FROM php:php-8.1-fpm-alpine -# Install Composer 2.1.5 -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.1.5 +# Install Composer 2.6.1 +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.6.1 # Add composer bin files path to environment variable RUN export PATH=$PATH":/usr/bin" diff --git a/docker/containers/mysql/Dockerfile b/docker/containers/mysql/Dockerfile index eb91790..03ca982 100644 --- a/docker/containers/mysql/Dockerfile +++ b/docker/containers/mysql/Dockerfile @@ -1,2 +1,2 @@ # Install MySQL -FROM library/mysql:8.0.30 +FROM library/mysql:5.7.22 diff --git a/docker/containers/php/Dockerfile b/docker/containers/php/Dockerfile index f8ccf40..02748e6 100644 --- a/docker/containers/php/Dockerfile +++ b/docker/containers/php/Dockerfile @@ -4,4 +4,5 @@ FROM php:8.1-fpm-alpine # Install PHP Extension RUN apk --no-cache add zip libzip-dev \ && docker-php-ext-configure zip \ - && docker-php-ext-install zip pdo pdo_mysql \ + && docker-php-ext-install zip mysqli pdo pdo_mysql \ + && docker-php-ext-enable pdo_mysql \ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 13b0d9d..8bd44d6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.7' +version: '3.8' networks: web-app: @@ -7,7 +7,7 @@ services: # +----------------------+ # # | Container: NginX | # # +----------------------+ # - nginx: + webserver: networks: - web-app container_name: nginx @@ -16,57 +16,58 @@ services: dockerfile: containers/nginx/Dockerfile image: nginx:nginx-stable-alpine ports: - - "9100:80" + - "8080:80" volumes: + - "${PATH_CONFIGS_NGINX}:/etc/nginx/conf.d/default.conf" - "${PATH_PROJECT_SOURCE}:/var/www/html" - - "${PATH_NGINX_CONFIGS}:/etc/nginx/conf.d/default.conf" depends_on: - php - - mysql + - database + + # +----------------------+ # + # | Container: PHP | # + # +----------------------+ # + php: + networks: + - web-app + container_name: php + build: + context: . + dockerfile: containers/php/Dockerfile + image: php:php-8.1-fpm-alpine + ports: + - "9000:9000" + volumes: + - "${PATH_PROJECT_SOURCE}:/var/www/html" # +----------------------+ # # | Container: MySQL | # # +----------------------+ # - mysql: + database: networks: - web-app container_name: mysql - command: mysqld --default-authentication-plugin=mysql_native_password build: context: . dockerfile: containers/mysql/Dockerfile - image: mysql:mysql-8.0.30 + image: mysql:mysql-${DB_VERSION} +# command: mysqld --default-authentication-plugin=mysql_native_password restart: unless-stopped tty: true ports: - "3306:3306" env_file: - - ${PATH_ENV_CONFIGS}/${SYS_ENV}.env + - ${PATH_ENVIRONMENTS}/${SYS_ENV}.env volumes: - "${DB_VOLUME}:/var/lib/mysql" environment: + SERVICE_TAGS: dev + SERVICE_NAME: mysql +# ---- Database Credentials ---- # MYSQL_DATABASE: "${DB_NAME}" # MYSQL_USER: "${DB_USERNAME}" # MYSQL_PASSWORD: "${DB_PASSWORD}" # MYSQL_ROOT_PASSWORD: "${DB_PASSWORD_ROOT}" - SERVICE_TAGS: dev - SERVICE_NAME: mysql - - # +----------------------+ # - # | Container: PHP | # - # +----------------------+ # - php: - networks: - - web-app - container_name: php - build: - context: . - dockerfile: containers/php/Dockerfile - image: php:php-8.1-fpm-alpine - ports: - - "9000:9000" - volumes: - - "${PATH_PROJECT_SOURCE}:/var/www/html" # +----------------------+ # # | Container: Composer | # @@ -78,10 +79,12 @@ services: build: context: . dockerfile: containers/composer/Dockerfile - image: composer:composer-2.1.5 + image: composer:composer-2.6.1 working_dir: /var/www/html volumes: - "${PATH_PROJECT_SOURCE}:/var/www/html" + depends_on: + - php entrypoint: ['composer'] # +----------------------+ # @@ -108,12 +111,15 @@ services: context: . dockerfile: containers/php/Dockerfile image: artisan:laravel-8 + links: + - php + - database env_file: - - ${PATH_ENV_CONFIGS}/config.env - - ${PATH_ENV_CONFIGS}/${SYS_ENV}.env + - ${PATH_ENVIRONMENTS}/${SYS_ENV}.env working_dir: /var/www/html volumes: - "${PATH_PROJECT_SOURCE}:/var/www/html" depends_on: - - mysql - entrypoint: ['/var/www/html/artisan'] + - php + - database + entrypoint: ['php', '/var/www/html/artisan'] diff --git a/docker/environments/config.env b/docker/environments/config.env index 201d2f4..8dcf7d6 100644 --- a/docker/environments/config.env +++ b/docker/environments/config.env @@ -2,18 +2,19 @@ # Docker Environment Config #============================ -# ENVIROMENT +# SYSTEM VARIABLES SYS_ENV=local -# DIRECTORIES / VOLUMES / PATHS +# PATHS / DIRECTORIES / VOLUMES +PATH_CONTAINERS=./containers +PATH_ENVIRONMENTS=./environments +PATH_VOLUMES=./volumes + PATH_PROJECT_SOURCE=../src -PATH_NGINX=./containers/nginx -PATH_NGINX_CONFIGS=${PATH_NGINX}/conf.d/default.conf -PATH_ENV_CONFIGS=./environments -PATH_DATABASE=./volumes/mysql +PATH_CONFIGS_NGINX=${PATH_CONTAINERS}/nginx/conf.d/default.conf # DATABASE DB_DRIVER=mysql -DB_VERSION=8.0.30 DB_PORT=3306 -DB_VOLUME=${PATH_DATABASE}/${DB_DRIVER}_${DB_VERSION} \ No newline at end of file +DB_VERSION=5.7.22 +DB_VOLUME=${PATH_VOLUMES}/${DB_DRIVER}/${DB_DRIVER}_${DB_VERSION} \ No newline at end of file diff --git a/docker/environments/local.env b/docker/environments/local.env index 9fc0326..34b2774 100644 --- a/docker/environments/local.env +++ b/docker/environments/local.env @@ -6,4 +6,4 @@ MYSQL_DATABASE=db_docker_laravel MYSQL_USER=dbUserDev MYSQL_PASSWORD=dbUserDev123 -MYSQL_ROOT_PASSWORD=dbUserRoot123 \ No newline at end of file +MYSQL_ROOT_PASSWORD=dbUserRoot123 diff --git a/docker/environments/prod.env b/docker/environments/prod.env new file mode 100644 index 0000000..1826261 --- /dev/null +++ b/docker/environments/prod.env @@ -0,0 +1,9 @@ +# +# Docker Environment - Production +#============================ + +# DATABASE +MYSQL_DATABASE= +MYSQL_USER= +MYSQL_PASSWORD= +MYSQL_ROOT_PASSWORD= diff --git a/docker/environments/staging.env b/docker/environments/staging.env new file mode 100644 index 0000000..9dd001b --- /dev/null +++ b/docker/environments/staging.env @@ -0,0 +1,9 @@ +# +# Docker Environment - Staging +#============================ + +# DATABASE +MYSQL_DATABASE=db_docker_laravel +MYSQL_USER=dbUserDev +MYSQL_PASSWORD=dbUserDev123 +MYSQL_ROOT_PASSWORD=dbUserRoot123 diff --git a/scripts/artisan.sh b/scripts/artisan.sh new file mode 100644 index 0000000..a738a2f --- /dev/null +++ b/scripts/artisan.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# run --rm artisan \ +# ${@} + +./scripts/run.sh \ + artisan \ + ${@} \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 0000000..2da9a9a --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# build +./scripts/main-docker-compose.sh \ + build \ No newline at end of file diff --git a/scripts/composer.sh b/scripts/composer.sh new file mode 100644 index 0000000..37509aa --- /dev/null +++ b/scripts/composer.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# run --rm composer \ +# ${@} +./scripts/run.sh \ + composer \ + ${@} \ No newline at end of file diff --git a/scripts/down.sh b/scripts/down.sh new file mode 100644 index 0000000..a6c077c --- /dev/null +++ b/scripts/down.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# down \ +# ${@} +./scripts/main-docker-compose.sh \ + down \ + ${@} \ No newline at end of file diff --git a/scripts/exec.sh b/scripts/exec.sh new file mode 100644 index 0000000..cbb4a1d --- /dev/null +++ b/scripts/exec.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# run --rm \ +# ${@} +./scripts/main-docker-compose.sh \ + exec \ + ${@} \ No newline at end of file diff --git a/scripts/main-docker-compose.sh b/scripts/main-docker-compose.sh new file mode 100644 index 0000000..ea816ab --- /dev/null +++ b/scripts/main-docker-compose.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -eo pipefail + +docker compose \ + --env-file "docker/environments/config.env" \ + -f "docker/docker-compose.yml" \ + ${@} diff --git a/scripts/prune.sh b/scripts/prune.sh new file mode 100644 index 0000000..295f05d --- /dev/null +++ b/scripts/prune.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# Delete All Images +docker system prune -a --force +docker ps +docker images \ No newline at end of file diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 0000000..614a2f8 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# run --rm \ +# ${@} +./scripts/main-docker-compose.sh \ + run --rm \ + ${@} \ No newline at end of file diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 0000000..71d8a22 --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# stop \ +# ${@} +./scripts/main-docker-compose.sh \ + stop \ + ${@} \ No newline at end of file diff --git a/scripts/up.sh b/scripts/up.sh new file mode 100644 index 0000000..74b04b6 --- /dev/null +++ b/scripts/up.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -eo pipefail + +#docker compose \ +# --env-file "docker/environments/config.env" \ +# -f "docker/docker-compose.yml" \ +# up \ +# ${@} +./scripts/main-docker-compose.sh \ + up \ + ${@} \ No newline at end of file