Skip to content

Commit 763f641

Browse files
author
Evgenii Mykhalichenko
committed
Rebuild and big update
1 parent cc2617a commit 763f641

File tree

9 files changed

+139
-37
lines changed

9 files changed

+139
-37
lines changed

.env_example

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
# Docker
22
DOCKER_PREFIX=skeleton
3+
DOCKER_WORK_DIR=/var/www/backend
4+
5+
# Nginx
6+
NGINX_VERSION=latest
7+
NGINX_PORT=80
8+
NGINX_HOST=localhost
9+
10+
# Redis
11+
REDIS_VERSION=latest
12+
REDIS_PORT=6379
13+
14+
# Redis commander
15+
REDIS_COMMANDER_VERSION=latest
16+
REDIS_COMMANDER_PORT=8081
17+
18+
# xDebug
19+
XDEBUG_MODE=debug,trace
20+
XDEBUG_CLIENT_HOST=host.docker.internal
21+
XDEBUG_IDKEY=docker
22+
XDEBUG_CLIENT_PORT=9003
323

424
# MySQL
5-
MYSQL_HOST=
6-
MYSQL_PORT=
7-
MYSQL_DATABASE=testwork
25+
MYSQL_VERSION=latest
26+
MYSQL_PORT=3306
27+
MYSQL_DATABASE=skeleton_db
828
MYSQL_ROOT_USER=
929
MYSQL_ROOT_PASSWORD=
1030
MYSQL_USER=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.env
22

3+
# Ignore mysql data
4+
/docker/mysql/data/**
5+
36
# Editor directories and files
47
.idea
58
*.suo

Makefile

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
include .env
1+
#!make
2+
-include .env
3+
4+
# set default command name
5+
default: help
6+
7+
# set variables
8+
DOCKER := docker
9+
DOCKER_COMPOSE := docker-compose
210

311
# make help
412
help:
@@ -14,7 +22,38 @@ help:
1422

1523
# make init
1624
init:
17-
cp .env_example .env;
25+
@if [ ! -f ./.env ]; then \
26+
cp .env_example .env; \
27+
fi
28+
29+
# add nginx host to /etc/hosts file
30+
add-host:
31+
SERVICES=$$(command -v getent > /dev/null && echo "getent ahostsv4" || echo "dscacheutil -q host -a name"); \
32+
if [ ! "$$($$SERVICES $(NGINX_HOST) | grep 127.0.0.1 > /dev/null; echo $$?)" -eq 0 ]; then sudo bash -c 'echo "127.0.0.1 $(NGINX_HOST)" >> /etc/hosts; echo "Entry was added"'; else echo 'Entry already exists'; fi;
33+
34+
# exec docker backend container
35+
bash:
36+
@${DOCKER} exec -it "${DOCKER_PREFIX}-backend" bash;
37+
38+
# build docker-compose
39+
build:
40+
@${DOCKER_COMPOSE} build;
41+
42+
# build docker-compose without cache
43+
build-no-cache:
44+
@${DOCKER_COMPOSE} build --no-cache;
45+
46+
# up with demon docker containers
47+
up:
48+
@${DOCKER_COMPOSE} up -d;
49+
50+
# down docker containers
51+
down:
52+
@${DOCKER_COMPOSE} up --volumes --rmi local --remove-orphans;
53+
54+
# stop docker containers
55+
stop:
56+
@${DOCKER_COMPOSE} stop;
1857

1958
# make clear-all-logs
2059
clear-all-logs:

docker-compose.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,44 @@ version: "3.7"
33
services:
44

55
nginx:
6-
image: nginx:latest
6+
image: "nginx:${NGINX_VERSION}"
77
container_name: "${DOCKER_PREFIX}-nginx"
8+
restart: always
89
ports:
9-
- "80:80"
10+
- "${NGINX_PORT}:80"
1011
volumes:
11-
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf
12-
- ./src:/var/www/backend
12+
- ./docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
13+
- ./docker/nginx/default.template.conf:/etc/nginx/default.template
14+
- "./src:${DOCKER_WORK_DIR}"
1315
- ./logs/nginx/:/var/log/nginx/
16+
environment:
17+
- NGINX_HOST=${NGINX_HOST}
18+
command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
1419
networks:
1520
- backend-network
1621

1722
redis:
18-
image: redis:latest
23+
image: "redis:${REDIS_VERSION}"
24+
restart: always
1925
container_name: "${DOCKER_PREFIX}-redis"
20-
expose:
21-
- "6379"
26+
ports:
27+
- "${REDIS_PORT}:6379"
2228
networks:
2329
- backend-network
2430

2531
redis-commander:
26-
image: rediscommander/redis-commander:latest
32+
image: "rediscommander/redis-commander:${REDIS_COMMANDER_VERSION}"
2733
container_name: "${DOCKER_PREFIX}-redis-commander"
2834
restart: always
2935
environment:
3036
- REDIS_HOSTS=local:redis
3137
ports:
32-
- "8081:8081"
38+
- "${REDIS_COMMANDER_PORT}:8081"
3339
networks:
3440
- backend-network
3541

3642
mysql:
37-
image: mysql:latest
43+
image: "mysql:${MYSQL_VERSION}"
3844
container_name: "${DOCKER_PREFIX}-mysql"
3945
restart: always
4046
env_file:
@@ -45,22 +51,31 @@ services:
4551
- MYSQL_USER=${MYSQL_USER}
4652
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
4753
volumes:
54+
- ./docker/mysql/data:/var/lib/mysql
4855
- ./logs/mysql/:/var/log/mysql
4956
- ./docker/mysql/conf.d:/etc/mysql/conf.d
5057
ports:
51-
- "3306:3306"
58+
- "${MYSQL_PORT}:3306"
5259
networks:
5360
- backend-network
5461

5562
backend:
5663
container_name: "${DOCKER_PREFIX}-backend"
57-
build: docker/backend
64+
build:
65+
context: ./docker/backend
66+
dockerfile: Dockerfile
67+
args:
68+
- WORK_DIR=${DOCKER_WORK_DIR}
69+
- XDEBUG_MODE=${XDEBUG_MODE}
70+
- XDEBUG_CLIENT_HOST=${XDEBUG_CLIENT_HOST}
71+
- XDEBUG_IDKEY=${XDEBUG_IDKEY}
72+
- XDEBUG_CLIENT_PORT=${XDEBUG_CLIENT_PORT}
73+
restart: always
5874
env_file:
5975
- .env
6076
volumes:
61-
- ./src:/var/www/backend
77+
- "./src:${DOCKER_WORK_DIR}"
6278
- ./logs/supervisor/:/var/log/supervisor/
63-
- ./logs/cron/:/var/log/cron/
6479
ports:
6580
- "9001:9001" # Access GUI with http://localhost:9001/
6681
networks:

docker/backend/Dockerfile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
FROM php:8.1-fpm
22

3+
ARG WORK_DIR
4+
ARG XDEBUG_MODE
5+
ARG XDEBUG_CLIENT_HOST
6+
ARG XDEBUG_IDKEY
7+
ARG XDEBUG_CLIENT_PORT
8+
9+
ENV WORK_DIR=$WORK_DIR
10+
ENV XDEBUG_MODE=$XDEBUG_MODE
11+
ENV XDEBUG_CLIENT_HOST=$XDEBUG_CLIENT_HOST
12+
ENV XDEBUG_IDKEY=$XDEBUG_IDKEY
13+
ENV XDEBUG_CLIENT_PORT=$XDEBUG_CLIENT_PORT
14+
315
# Set timezone
416
RUN echo "UTC" > /etc/timezone
517

@@ -10,7 +22,6 @@ RUN apt-get update && apt-get install -y \
1022
unzip \
1123
curl \
1224
supervisor \
13-
cron \
1425
procps \
1526
htop
1627

@@ -23,11 +34,10 @@ COPY php/conf.d/xdebug.ini $PHP_INI_DIR/conf.d/
2334
COPY supervisor/supervisord.conf /etc/supervisor
2435
COPY supervisor/conf.d/* /etc/supervisor/conf.d
2536

26-
COPY cron/crontab /etc/cron.d/crontab
27-
RUN chmod 0644 /etc/cron.d/crontab
28-
RUN crontab /etc/cron.d/crontab
29-
30-
RUN mkdir -p /var/log/cron
37+
# Set configuration for xdebug
38+
RUN sed -i -e 's/xdebug.client_host=host.docker.internal/xdebug.client_host='"${XDEBUG_CLIENT_HOST}"'/g' $PHP_INI_DIR/conf.d/xdebug.ini
39+
RUN sed -i -e 's/xdebug.client_port=9003/xdebug.client_port='"${XDEBUG_CLIENT_PORT}"'/g' $PHP_INI_DIR/conf.d/xdebug.ini
40+
RUN sed -i -e 's/xdebug.idekey=docker/xdebug.idekey='"${XDEBUG_IDKEY}"'/g' $PHP_INI_DIR/conf.d/xdebug.ini
3141

3242
# Install and enable pecl php extentions
3343
RUN pecl install xdebug redis
@@ -39,6 +49,6 @@ RUN docker-php-ext-install pdo_mysql
3949
# Get latest Composer
4050
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
4151

42-
WORKDIR "/var/www/backend"
52+
WORKDIR "${WORK_DIR}"
4353

4454
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

docker/backend/cron/crontab

Lines changed: 0 additions & 11 deletions
This file was deleted.

docker/nginx/nginx.conf renamed to docker/nginx/conf.d/default.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
server {
22
listen 80 default_server;
3+
listen [::]:80 default_server;
34
root /var/www/backend/public;
45

6+
server_name api.loc;
7+
58
index index.php;
69

710
error_log /var/log/nginx/backend-error.log;

docker/nginx/default.template.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
listen 80 default_server;
3+
listen [::]:80 default_server;
4+
root /var/www/backend/public;
5+
6+
server_name ${NGINX_HOST};
7+
8+
index index.php;
9+
10+
error_log /var/log/nginx/backend-error.log;
11+
access_log /var/log/nginx/backend-access.log;
12+
13+
location / {
14+
try_files $uri $uri/ /index.php?$query_string;
15+
}
16+
17+
location ~ \.php$ {
18+
fastcgi_pass backend:9000;
19+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
20+
include fastcgi_params;
21+
}
22+
}

logs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
2+
*/
23
!.gitignore

0 commit comments

Comments
 (0)