Skip to content

Commit b9c2148

Browse files
authored
Merge pull request pterodactyl#1285 from parkervcp/feature/add-dockerfile
2 parents eaabe5b + fefcc31 commit b9c2148

File tree

10 files changed

+399
-2
lines changed

10 files changed

+399
-2
lines changed

.dev/docker/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Pterodactyl Panel - Docker Image
2+
This is a ready to use docker image for the panel.
3+
4+
## Requirements
5+
This docker image requires some additional software to function. The software can either be provided in other containers (see the [docker-compose.yml](docker-compose.yml) as an example) or as existing instances.
6+
7+
A mysql database is required. We recommend the stock [MariaDB Image](https://hub.docker.com/_/mariadb/) image if you prefer to run it in a docker container. As a non-containerized option we recommend mariadb.
8+
9+
A caching software is required as well. We recommend the stock [Redis Image](https://hub.docker.com/_/redis/) image. You can choose any of the [supported options](#cache-drivers).
10+
11+
You can provide additional settings using a custom `.env` file or by setting the appropriate environment variables in the docker-compose file.
12+
13+
## Setup
14+
15+
Start the docker container and the required dependencies (either provide existing ones or start containers as well, see the [docker-compose.yml](docker-compose.yml) file as an example).
16+
17+
After the startup is complete you'll need to create a user.
18+
If you are running the docker container without docker-compose, use:
19+
```
20+
docker exec -it <container id> php artisan p:user:make
21+
```
22+
If you are using docker compose use
23+
```
24+
docker-compose exec panel php artisan p:user:make
25+
```
26+
27+
## Environment Variables
28+
There are multiple environment variables to configure the panel when not providing your own `.env` file, see the following table for details on each available option.
29+
30+
Note: If your `APP_URL` starts with `https://` you need to provide an `LETSENCRYPT_EMAIL` as well so Certificates can be generated.
31+
32+
| Variable | Description | Required |
33+
| ------------------- | ------------------------------------------------------------------------------ | -------- |
34+
| `APP_URL` | The URL the panel will be reachable with (including protocol) | yes |
35+
| `APP_TIMEZONE` | The timezone to use for the panel | yes |
36+
| `LETSENCRYPT_EMAIL` | The email used for letsencrypt certificate generation | yes |
37+
| `DB_HOST` | The host of the mysql instance | yes |
38+
| `DB_PORT` | The port of the mysql instance | yes |
39+
| `DB_DATABASE` | The name of the mysql database | yes |
40+
| `DB_USERNAME` | The mysql user | yes |
41+
| `DB_PASSWORD` | The mysql password for the specified user | yes |
42+
| `CACHE_DRIVER` | The cache driver (see [Cache drivers](#cache-drivers) for detais) | yes |
43+
| `SESSION_DRIVER` | | yes |
44+
| `QUEUE_DRIVER` | | yes |
45+
| `REDIS_HOST` | The hostname or IP address of the redis database | yes |
46+
| `REDIS_PASSWORD` | The password used to secure the redis database | maybe |
47+
| `REDIS_PORT` | The port the redis database is using on the host | maybe |
48+
| `MAIL_DRIVER` | The email driver (see [Mail drivers](#mail-drivers) for details) | yes |
49+
| `MAIL_FROM` | The email that should be used as the sender email | yes |
50+
| `MAIL_HOST` | The host of your mail driver instance | maybe |
51+
| `MAIL_PORT` | The port of your mail driver instance | maybe |
52+
| `MAIL_USERNAME` | The username for your mail driver | maybe |
53+
| `MAIL_PASSWORD` | The password for your mail driver | maybe |
54+
55+
56+
### Cache drivers
57+
You can choose between different cache drivers depending on what you prefer.
58+
We recommend redis when using docker as it can be started in a container easily.
59+
60+
| Driver | Description | Required variables |
61+
| -------- | ------------------------------------ | ------------------------------------------------------ |
62+
| redis | host where redis is running | `REDIS_HOST` |
63+
| redis | port redis is running on | `REDIS_PORT` |
64+
| redis | redis database password | `REDIS_PASSWORD` |
65+
66+
### Mail drivers
67+
You can choose between different mail drivers according to your needs.
68+
Every driver requires `MAIL_FROM` to be set.
69+
70+
| Driver | Description | Required variables |
71+
| -------- | ------------------------------------ | ------------------------------------------------------------- |
72+
| mail | uses the installed php mail | |
73+
| mandrill | [Mandrill](http://www.mandrill.com/) | `MAIL_USERNAME` |
74+
| postmark | [Postmark](https://postmarkapp.com/) | `MAIL_USERNAME` |
75+
| mailgun | [Mailgun](https://www.mailgun.com/) | `MAIL_USERNAME`, `MAIL_HOST` |
76+
| smtp | Any SMTP server can be configured | `MAIL_USERNAME`, `MAIL_HOST`, `MAIL_PASSWORD`, `MAIL_PORT` |

.dev/docker/default.conf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# If using Ubuntu this file should be placed in:
2+
# /etc/nginx/sites-available/
3+
#
4+
# If using CentOS this file should be placed in:
5+
# /etc/nginx/conf.d/
6+
#
7+
server {
8+
listen 80;
9+
server_name _;
10+
11+
root /app/public;
12+
index index.html index.htm index.php;
13+
charset utf-8;
14+
15+
location / {
16+
try_files $uri $uri/ /index.php?$query_string;
17+
}
18+
19+
location = /favicon.ico { access_log off; log_not_found off; }
20+
location = /robots.txt { access_log off; log_not_found off; }
21+
22+
access_log off;
23+
error_log /var/log/nginx/pterodactyl.app-error.log error;
24+
25+
# allow larger file uploads and longer script runtimes
26+
client_max_body_size 100m;
27+
client_body_timeout 120s;
28+
29+
sendfile off;
30+
31+
location ~ \.php$ {
32+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
33+
# the fastcgi_pass path needs to be changed accordingly when using CentOS
34+
fastcgi_pass unix:/var/run/php/php-fpm7.2.sock;
35+
fastcgi_index index.php;
36+
include fastcgi_params;
37+
fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
fastcgi_param HTTP_PROXY "";
40+
fastcgi_intercept_errors off;
41+
fastcgi_buffer_size 16k;
42+
fastcgi_buffers 4 16k;
43+
fastcgi_connect_timeout 300;
44+
fastcgi_send_timeout 300;
45+
fastcgi_read_timeout 300;
46+
}
47+
48+
location ~ /\.ht {
49+
deny all;
50+
}
51+
}

.dev/docker/default_ssl.conf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# If using Ubuntu this file should be placed in:
2+
# /etc/nginx/sites-available/
3+
#
4+
server {
5+
listen 80;
6+
server_name <domain>;
7+
return 301 https://$server_name$request_uri;
8+
}
9+
10+
server {
11+
listen 443 ssl http2;
12+
server_name <domain>;
13+
14+
root /var/www/pterodactyl/public;
15+
index index.php;
16+
17+
access_log /var/log/nginx/pterodactyl.app-access.log;
18+
error_log /var/log/nginx/pterodactyl.app-error.log error;
19+
20+
# allow larger file uploads and longer script runtimes
21+
client_max_body_size 100m;
22+
client_body_timeout 120s;
23+
24+
sendfile off;
25+
26+
# strengthen ssl security
27+
ssl_certificate /etc/letsencrypt/live/<domain>/fullchain.pem;
28+
ssl_certificate_key /etc/letsencrypt/live/<domain>/privkey.pem;
29+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
30+
ssl_prefer_server_ciphers on;
31+
ssl_session_cache shared:SSL:10m;
32+
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
33+
34+
# See the link below for more SSL information:
35+
# https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
36+
#
37+
# ssl_dhparam /etc/ssl/certs/dhparam.pem;
38+
39+
# Add headers to serve security related headers
40+
add_header Strict-Transport-Security "max-age=15768000; preload;";
41+
add_header X-Content-Type-Options nosniff;
42+
add_header X-XSS-Protection "1; mode=block";
43+
add_header X-Robots-Tag none;
44+
add_header Content-Security-Policy "frame-ancestors 'self'";
45+
46+
location / {
47+
try_files $uri $uri/ /index.php?$query_string;
48+
}
49+
50+
location ~ \.php$ {
51+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
52+
fastcgi_pass unix:/run/php/pterodactyl.sock;
53+
fastcgi_index index.php;
54+
include fastcgi_params;
55+
fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
56+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
57+
fastcgi_param HTTP_PROXY "";
58+
fastcgi_intercept_errors off;
59+
fastcgi_buffer_size 16k;
60+
fastcgi_buffers 4 16k;
61+
fastcgi_connect_timeout 300;
62+
fastcgi_send_timeout 300;
63+
fastcgi_read_timeout 300;
64+
include /etc/nginx/fastcgi_params;
65+
}
66+
67+
location ~ /\.ht {
68+
deny all;
69+
}
70+
}

.dev/docker/entrypoint.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/ash
2+
## Ensure we are in /app
3+
4+
cd /app
5+
6+
## check for .env file and generate app keys if missing
7+
if [ -f /app/var/.env ]; then
8+
echo "external vars exist"
9+
rm /app/.env
10+
11+
ln -s /app/var/.env /app/
12+
else
13+
echo "external vars don't exist"
14+
rm /app/.env
15+
touch /app/var/.env
16+
17+
## manually generate a key because key generate --force fails
18+
echo -e "Generating key"
19+
APP_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
20+
echo -e "Generated app key: $APP_KEY"
21+
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
22+
23+
ln -s /app/var/.env /app/
24+
fi
25+
26+
## check for DB up before starting the panel
27+
echo "Checking database status."
28+
until nc -z -v -w30 $DB_HOST 3306
29+
30+
do
31+
echo "Waiting for database connection..."
32+
# wait for 5 seconds before check again
33+
sleep 5
34+
done
35+
36+
## make sure the db is set up
37+
echo -e "Migrating and Seeding DB"
38+
php artisan migrate --force
39+
php artisan db:seed --force
40+
41+
## start cronjobs for the queue
42+
echo -e "Starting cron jobs"
43+
crond
44+
45+
echo -e "Starting supervisord"
46+
exec "$@"

.dev/docker/supervisord.conf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[unix_http_server]
2+
file=/tmp/supervisor.sock ; path to your socket file
3+
4+
[supervisord]
5+
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
6+
logfile_maxbytes=50MB ; maximum size of logfile before rotation
7+
logfile_backups=2 ; number of backed up logfiles
8+
loglevel=error ; info, debug, warn, trace
9+
pidfile=/var/run/supervisord.pid ; pidfile location
10+
nodaemon=false ; run supervisord as a daemon
11+
minfds=1024 ; number of startup file descriptors
12+
minprocs=200 ; number of process descriptors
13+
user=root ; default user
14+
childlogdir=/var/log/supervisord/ ; where child log files will live
15+
16+
[rpcinterface:supervisor]
17+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
18+
19+
[supervisorctl]
20+
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
21+
22+
[program:php-fpm]
23+
command=/usr/sbin/php-fpm7 -F
24+
autostart=true
25+
autorestart=true
26+
27+
[program:queue-worker]
28+
command=/usr/bin/php /app/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
29+
user=nginx
30+
autostart=true
31+
autorestart=true
32+
33+
[program:nginx]
34+
command=/usr/sbin/nginx -g 'daemon off;'
35+
autostart=true
36+
autorestart=true
37+
priority=10
38+
stdout_events_enabled=true
39+
stderr_events_enabled=true

.dev/docker/www.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[pterodactyl]
2+
3+
user = nginx
4+
group = nginx
5+
6+
listen = /var/run/php/php-fpm7.2.sock
7+
listen.owner = nginx
8+
listen.group = nginx
9+
listen.mode = 0750
10+
11+
pm = ondemand
12+
pm.max_children = 9
13+
pm.process_idle_timeout = 10s
14+
pm.max_requests = 200
15+
16+
clear_env = no

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ sami.phar
2020
# For local development with docker
2121
# Remove if we ever put the Dockerfile in the repo
2222
.dockerignore
23-
Dockerfile
23+
#Dockerfile
2424
docker-compose.yml
25+
2526
# for image related files
2627
misc
2728
.phpstorm.meta.php

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM alpine:3.8
2+
3+
WORKDIR /app
4+
5+
RUN apk add --no-cache --update ca-certificates certbot nginx dcron curl tini php7 php7-bcmath php7-common php7-dom php7-fpm php7-gd php7-mbstring php7-openssl php7-zip php7-pdo php7-phar php7-json php7-pdo_mysql php7-session php7-ctype php7-tokenizer php7-zlib php7-simplexml supervisor \
6+
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
7+
8+
COPY . ./
9+
10+
RUN cp .env.example .env \
11+
&& composer install --no-dev --optimize-autoloader \
12+
&& rm .env \
13+
&& chown -R nginx:nginx . && chmod -R 777 storage/* bootstrap/cache
14+
15+
RUN cp .dev/docker/default.conf /etc/nginx/conf.d/default.conf \
16+
&& cp .dev/docker/www.conf /etc/php7/php-fpm.d/www.conf \
17+
&& cat .dev/docker/supervisord.conf > /etc/supervisord.conf \
18+
&& echo "* * * * * /usr/bin/php /app/pterodactyl/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \
19+
&& mkdir -p /var/run/php /var/run/nginx \
20+
&& mkdir -p /var/log/supervisord/
21+
22+
EXPOSE 80 443
23+
24+
ENTRYPOINT ["/bin/ash", ".dev/docker/entrypoint.sh"]
25+
26+
CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ]

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| change this value if you are not maintaining your own internal versions.
1010
*/
1111

12-
'version' => 'canary',
12+
'version' => '0.7.10',
1313

1414
/*
1515
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)