Skip to content

Commit 2ed2574

Browse files
committed
Update Docker setup
1 parent f71e3a8 commit 2ed2574

14 files changed

Lines changed: 279 additions & 89 deletions

File tree

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
"request": "launch",
1111
"port": 9000,
1212
"log": false,
13+
},
14+
{
15+
"name": "Listen for Xdebug on Docker",
16+
"type": "php",
17+
"request": "launch",
18+
"port": 9001,
19+
"pathMappings": {
20+
"/app": "${workspaceFolder}"
21+
},
22+
"xdebugSettings": {
23+
"max_children": 128,
24+
"max_data": 512,
25+
"max_depth": 3
26+
}
1327
}
1428
]
1529
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
> This file contains the changelog of the Skeleton itself. You should replace it with your own Changelog!
1010
1111
## [6.0.0-beta.4](https://github.com/userfrosting/UserFrosting/compare/6.0.0-beta.3...6.0.0-beta.4)
12+
- Update Docker setup (@ssnukala)
1213
- Add exclude list for optimizeDeps in Vite config
1314
- Add Admin Sprinkle to main.ts
1415
- Go back to Vite default port (`5173`) + allows Vite port to be in env variable

app/.env.docker

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Sample UserFrosting environment variables definition file for Docker environment.
2+
# Note that in production, it is strongly recommended that you set these variables directly in your environment instead.
3+
4+
UF_MODE=
5+
6+
DB_CONNECTION=mysql
7+
DB_HOST=mysql
8+
DB_PORT=3306
9+
DB_NAME=userfrosting
10+
DB_USER=docker
11+
DB_PASSWORD=secret
12+
DB_ROOT_PASSWORD=secret
13+
ROOT_PASSWORD=secret
14+
15+
MAIL_MAILER=smtp # Set to one of 'smtp', 'mail', 'qmail', 'sendmail'
16+
SMTP_HOST=mailpit
17+
18+
SMTP_PASSWORD=password
19+
SMTP_PORT=2025
20+
SMTP_SECURE=false
21+
SMTP_AUTH=false
22+
23+
24+
MAIL_FROM_NAME="Site Administrator"
25+
URI_PUBLIC="" # Set to the base URI of your site, e.g. http://www.example.com in production. If left blank, it will be automatically determined.
26+
27+
# MySQL Container Settings - only used by docker-compose, not by UserFrosting itself
28+
# Set as same as DB_ settings above
29+
MYSQL_DATABASE=userfrosting
30+
MYSQL_ROOT_PASSWORD=secret
31+
MYSQL_USER=docker
32+
MYSQL_PASSWORD=secret

app/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
# Note that in production, it is strongly recommended that you set these variables directly in your environment instead.
33

44
UF_MODE=""
5+
56
DB_CONNECTION="mysql"
67
DB_HOST="localhost" # Some developer environments, like some MAMP installations, require you to instead set DB_HOST="127.0.0.1"
78
DB_PORT="3306"
89
DB_NAME="userfrosting"
910
DB_USER="userfrosting"
1011
DB_PASSWORD="password"
12+
1113
MAIL_MAILER="smtp" # Set to one of 'smtp', 'mail', 'qmail', 'sendmail'
1214
SMTP_HOST="host.example.com"
1315
SMTP_USER="[email protected]"
1416
SMTP_PASSWORD="password"
1517
SMTP_PORT="587"
1618
SMTP_AUTH="true"
1719
SMTP_SECURE="tls"
20+
1821
MAIL_FROM_ADDRESS="[email protected]"
1922
MAIL_FROM_NAME="Site Administrator"
2023
URI_PUBLIC="" # Set to the base URI of your site, e.g. http://www.example.com in production. If left blank, it will be automatically determined.
Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
version: "3.2"
21
services:
32
app:
43
restart: unless-stopped
54
tty: true
65
build:
7-
context: docker/app
8-
environment:
9-
- DB_CONNECTION=mysql
10-
- DB_HOST=mysql
11-
- DB_PORT=3306
12-
- DB_NAME=userfrosting
13-
- DB_USER=docker
14-
- DB_PASSWORD=secret
15-
- SMTP_HOST=mailpit
16-
- SMTP_PORT=1025
17-
- SMTP_SECURE=false
18-
- SMTP_AUTH=false
6+
context: ./docker/app
7+
env_file:
8+
- ./app/.env
199
volumes:
2010
- .:/app
2111
- ./docker/app/php/custom.ini:/usr/local/etc/php/conf.d/custom.ini
2212
networks:
2313
- backend
24-
2514
nginx:
2615
restart: unless-stopped
2716
tty: true
@@ -33,38 +22,47 @@ services:
3322
- .:/app
3423
depends_on:
3524
- app
36-
- mysql
3725
- mailpit
3826
networks:
3927
- frontend
4028
- backend
41-
29+
vue-frontend:
30+
restart: unless-stopped
31+
tty: true
32+
build:
33+
context: .
34+
dockerfile: ./docker/vue/Dockerfile
35+
env_file:
36+
- ./app/.env
37+
ports:
38+
- "5173:5173"
39+
volumes:
40+
- .:/app
41+
networks:
42+
- frontend
43+
mysql:
44+
restart: unless-stopped
45+
tty: true
46+
build:
47+
context: ./docker/mysql
48+
env_file:
49+
- ./app/.env
50+
ports:
51+
- "8503:3306"
52+
volumes:
53+
- userfrosting-db:/var/lib/mysql
54+
networks:
55+
- backend
4256
mailpit:
4357
image: 'axllent/mailpit:latest'
4458
ports:
4559
- '1025:1025'
4660
- '8025:8025'
4761
networks:
4862
- backend
49-
50-
mysql:
51-
image: mysql:8.0
52-
networks:
53-
- backend
54-
environment:
55-
- MYSQL_DATABASE=userfrosting
56-
- MYSQL_ROOT_PASSWORD=secret
57-
- MYSQL_USER=docker
58-
- MYSQL_PASSWORD=secret
59-
ports:
60-
- 8593:3306
61-
volumes:
62-
- userfrosting-db:/var/lib/mysql
63-
6463
volumes:
6564
userfrosting-db:
6665
driver: local
67-
6866
networks:
6967
frontend:
7068
backend:

docker/README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,39 @@ First, install [Docker Compose or Docker Desktop](https://docs.docker.com/compos
66

77
Second, initialize a new UserFrosting project:
88

9-
1. Get UserFrosting repository : `docker run --rm -it -v "$(pwd):/app" composer create-project userfrosting/userfrosting UserFrosting "^5.0" --no-scripts --no-install --ignore-platform-reqs`
10-
2. Change to the new directory `cd UserFrosting`
11-
3. Run `docker-compose build --no-cache` to build all the docker containers.
12-
4. Run `docker-compose up -d` to to start all the containers.
13-
5. Run `sudo chown -R $USER: .` and `sudo chmod 777 app/{logs,cache,sessions}` to set some directory permissions (your may have to enter your root password):
14-
6. Run `docker-compose exec app composer update` to install all composer modules used in UserFrosting.
15-
7. Run `docker-compose exec app php bakery bake` to install UserFrosting (database configuration and migrations, creation of admin user, ...). You'll need to provide info to create the admin user.
9+
1. Get UserFrosting repository :
10+
```
11+
docker run --rm -it -v "$(pwd):/app" composer create-project userfrosting/userfrosting UserFrosting "^6.0" --no-scripts --no-install --ignore-platform-reqs
12+
```
13+
2. Change to the new directory :
14+
```
15+
cd UserFrosting
16+
```
17+
3. Copy the default env file :
18+
```
19+
cp app/.env.docker app/.env
20+
```
21+
4. Build all the docker containers:
22+
```
23+
docker-compose build --no-cache
24+
```
25+
5. Start all the containers:
26+
```
27+
docker-compose up -d
28+
```
29+
6. Set some directory permissions (your may have to enter your root password):
30+
```
31+
sudo chown -R $USER: .
32+
sudo chmod 777 app/{logs,cache,sessions}
33+
```
34+
7. Install all composer modules used in UserFrosting:
35+
```
36+
docker-compose exec app composer update
37+
```
38+
8. Install UserFrosting (database configuration and migrations, creation of admin user, ...). You'll need to provide info to create the admin user.
39+
```
40+
docker-compose exec app php bakery bake
41+
```
1642

1743
Now visit [http://localhost:8080](http://localhost:8080) to see your UserFrosting homepage!
1844

@@ -21,8 +47,9 @@ Now visit [http://localhost:8080](http://localhost:8080) to see your UserFrostin
2147
**You can paste these into a bash file and execute it!**
2248

2349
```bash
24-
docker run --rm -it -v "$(pwd):/app" composer create-project userfrosting/userfrosting UserFrosting "^5.0" --no-scripts --no-install --ignore-platform-reqs
50+
docker run --rm -it -v "$(pwd):/app" composer create-project userfrosting/userfrosting UserFrosting "^6.0" --no-scripts --no-install --ignore-platform-reqs
2551
cd UserFrosting
52+
cp app/.env.docker app/.env
2653
docker-compose build --no-cache
2754
docker-compose up -d
2855
sudo chown -R $USER: .
@@ -35,11 +62,15 @@ docker-compose exec app php bakery bake
3562

3663
If you need to stop the UserFrosting docker containers, just change to your userfrosting directory and run:
3764

38-
`docker-compose stop`
65+
```
66+
docker-compose stop
67+
```
3968

4069
To start containers again, change to your userfrosting directory and run:
4170

42-
`docker-compose up -d`
71+
```
72+
docker-compose up -d
73+
```
4374

4475
**Purge docker containers to start over**
4576

@@ -55,8 +86,7 @@ And then start the installation process again.
5586

5687
You may be tempted to run with this in production but this setup has not been security-hardened. For example:
5788

58-
- Database is exposed on port 8593 so you can access MySQL using your favorite client at localhost:8593. However,
59-
the way Docker exposes this actually bypasses common firewalls like `ufw` so this should not be exposed in production.
89+
- Database is exposed on port 8593 so you can access MySQL using your favorite client at localhost:8593. However, the way Docker exposes this actually bypasses common firewalls like `ufw` so this should not be exposed in production.
6090
- Database credentials are hard-coded so obviously not secure.
6191
- File permissions may be more open than necessary.
6292
- HTTPS not implemented fully

docker/app/Dockerfile

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,45 @@
1+
# Use the official PHP 8.2 FPM image
12
FROM php:8.2-fpm
23

3-
RUN apt-get update
4+
# Set environment variables for non-interactive installations
5+
ENV DEBIAN_FRONTEND=noninteractive
46

5-
RUN apt-get install -y apt-utils
6-
7-
# Add NodeJS 18 Repository
8-
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
9-
apt-get install -y nodejs
10-
11-
RUN apt-get install -y \
12-
libc-client-dev \
7+
# Update and install all necessary system dependencies in a single RUN command
8+
RUN apt-get update && apt-get install -y apt-utils curl git unzip gnupg2 \
9+
libpq-dev \
1310
libicu-dev \
1411
libkrb5-dev \
1512
libssl-dev \
1613
libxslt1-dev \
1714
libxml2-dev \
1815
locales \
1916
zlib1g-dev \
20-
libzip-dev\
17+
libzip-dev \
2118
libpng-dev \
2219
libfreetype6-dev \
2320
libjpeg62-turbo-dev \
2421
libjpeg-dev \
2522
zip \
26-
nodejs
23+
default-mysql-client \
24+
# Clean up the package cache to reduce image size
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# Add NodeJS 20 Repository and install nodejs
28+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
29+
&& apt-get install -y nodejs \
30+
&& rm -rf /var/lib/apt/lists/*
2731

28-
# Optional XDebug Install
29-
#RUN curl -fsSL 'https://xdebug.org/files/xdebug-2.9.4.tgz' -o xdebug.tar.gz \
30-
# && mkdir -p xdebug \
31-
# && tar -xf xdebug.tar.gz -C xdebug --strip-components=1 \
32-
# && rm xdebug.tar.gz \
33-
# && ( \
34-
# cd xdebug \
35-
# && phpize \
36-
# && ./configure --enable-xdebug \
37-
# && make -j$(nproc) \
38-
# && make install \
39-
# ) \
40-
# && rm -r xdebug \
41-
# && docker-php-ext-enable xdebug
32+
# Install XDebug via PECL
33+
RUN pecl install xdebug \
34+
&& docker-php-ext-enable xdebug
4235

43-
# COMPOSER INSTALL
44-
RUN curl -sSfo /tmp/composer.phar https://getcomposer.org/installer
45-
RUN php /tmp/composer.phar --install-dir=/usr/local/bin --filename=composer
36+
# Install Composer
37+
RUN curl -sSfo /tmp/composer.phar https://getcomposer.org/installer \
38+
&& php /tmp/composer.phar --install-dir=/usr/local/bin --filename=composer
4639

47-
# Install and configure PHP extensions
40+
# Configure and install PHP extensions
4841
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
4942
&& docker-php-ext-install -j$(nproc) gd \
50-
&& docker-php-ext-install -j$(nproc) pdo pdo_mysql \
51-
&& docker-php-ext-install -j$(nproc) zip
43+
&& docker-php-ext-install -j$(nproc) pdo pdo_mysql zip
5244

53-
WORKDIR /app
45+
WORKDIR /app

docker/app/php/custom.ini

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@ memory_limit = 64M
33
upload_max_filesize = 64M
44
post_max_size = 64M
55
max_execution_time = 600
6-
memory_limit=512M
6+
memory_limit=512M
7+
8+
[xdebug]
9+
xdebug.mode=debug,coverage
10+
xdebug.start_with_request=yes
11+
xdebug.client_host=host.docker.internal
12+
xdebug.client_port=9001
13+
xdebug.log=/var/log/xdebug.log
14+
xdebug.log_level=7
15+
xdebug.discover_client_host=1
16+
xdebug.idekey=VSCODE

docker/mysql/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
# Use MySQL 9.4.0 as the base
4+
FROM mysql:9.4.0
5+
6+
# Expose MySQL default port
7+
EXPOSE 3306
8+
9+
# Default authentication plugin
10+
CMD ["mysqld"]

docker/mysql/mysql.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mysqld]
2+
bind-address = 0.0.0.0
3+
innodb_use_native_aio = 0

0 commit comments

Comments
 (0)