Update to v2 and use php-fpm for better performance

This commit is contained in:
Derkades 2020-06-10 14:12:51 +02:00
parent ed84436224
commit 2b8e21f95f
11 changed files with 162 additions and 104 deletions

View File

@ -1,26 +0,0 @@
FROM php:7.0-apache
ARG NAMELESSMC_VERSION=1.0.21
WORKDIR /var/www
RUN docker-php-source extract \
&& apt-get update \
&& apt-get install -y libmcrypt-dev libldap2-dev libpng-dev libjpeg62-turbo-dev libfreetype6-dev curl tar \
&& docker-php-ext-install pdo pdo_mysql mysqli \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& a2enmod rewrite \
&& docker-php-source delete \
&& apt-get clean \
&& apt-get autoclean \
&& apt-get autoremove --purge -y \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ /tmp/* /var/tmp/*
RUN curl -Lo nameless.tar.gz https://github.com/NamelessMC/Nameless/archive/v$NAMELESSMC_VERSION.tar.gz \
&& tar -xvf nameless.tar.gz \
&& mv Nameless-$NAMELESSMC_VERSION/* /var/www/html/ \
&& bash -c "mv Nameless-$NAMELESSMC_VERSION/.[^.]* /var/www/html/" \
&& rm -rf nameless.tar.gz Nameless-$NAMELESSMC_VERSION \
&& chown -R www-data:www-data /var/www/html \
&& chmod 755 -R /var/www/html

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017 Birkhoff Lee
Copyright (c) 2020 Derkades
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,76 +1,27 @@
# NamelessMC Docker [![](https://images.microbadger.com/badges/image/birkhofflee/namelessmc-docker.svg)](https://microbadger.com/images/birkhofflee/namelessmc-docker)
# NamelessMC Docker
This is the official Docker image for NamelessMC. Deploy with ease!
# Usage
## Usage
## # Install Docker
Obviously, if you wanna use Docker for deployment, you need to install Docker.
### Install Docker
You have to manually install Docker first if you don't have it installed on your server. Check out the official install guide here: https://docs.docker.com/engine/installation.
You have to manually install Docker first if you don't have it installed on your server. Check out the [official install guide](https://docs.docker.com/engine/installation).
If you want to specify the version of NamelessMC you want, head to https://github.com/NamelessMC/Nameless-Docker#manually-run-commands.
### Automated Deployment
## # Automated Deployment
You will need to install [Docker Compose](https://docs.docker.com/compose/) for automated deploying. If you don't have it installed, run the following:
You will need to install [Docker Compose](https://docs.docker.com/compose/) for automated deploying.
```bash
$ curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
sudo apt install docker-compose
```
> If you got a “Permission denied” error while running the commands above, add `sudo` at the beginning of each of them and run again. This will require sudo access.
When you're done, clone this repository and run! (`-d` means detach mode, e.g. run in background)
Download the example file, optionally change the directories, passwords, etc. then run it with
```bash
$ git clone https://github.com/NamelessMC/Nameless-Docker
$ cd NamelessMC-docker
$ docker-compose up -d
docker-compose up -d
```
When the container is up, follow the guide at https://github.com/NamelessMC/Nameless-Docker#namelessmc-installation.
When the containers are up, visit the website in a browser to start the installer. By default it listens on any interface, port 80.
## # Manual Deployment
If you more like to run the containers by yourself or using them with other containers like [jwilder/nginx-proxy](https://github.com/jwilder/nginx-proxy), you may want to do it yourself.
First, clone the repository:
```bash
$ git clone https://github.com/NamelessMC/Nameless-Docker
$ cd Nameless-Docker
```
Next, build the image.
```bash
$ docker build -t namelessmc .
```
If you want to specify the version:
```bash
$ docker build --build-arg NAMELESSMC_VERSION=1.0.21 -t namelessmc .
```
The version number **MUST BE** listed [here](https://github.com/NamelessMC/Nameless/releases) and it's **not guranteed** to work.
Next, run the image we just built and a MySQL container as well.
```bash
$ docker run -d -e "MYSQL_ROOT_PASSWORD=nameless" -e "MYSQL_USER=nameless" -e "MYSQL_PASSWORD=nameless" -e "MYSQL_DATABASE=nameless" --name nameless_db mysql
$ docker run -d -p 80:80 --link nameless_db --name nameless namelessmc
```
That's it!
# Installation
After deploying the containers, open up the corresponding URL in your web browser to get started with NamelessMC.
By default, the web server will be available at `0.0.0.0:80`, means if you deployed it on you own computer, the URL is gonna be `http://localhost`. Instead, if you did it on a remote server, the URL would be `http://<your-server-ip-addr>`.
Follow the install instructions. When the database configuration page shows up, fill in `db` for the *database address*. For database username, password and database name, fill `nameless` for all of them, if you used default database credentials.
When you're done, submit and follow the rest of installation.
# About
This repository was moved from [Birkhoff Lee](https://github.com/BirkhoffLee), and the original repository is here: https://github.com/BirkhoffLee/namelessmc-docker, carefully made in Taiwan. :heart:
When the database configuration page shows up, fill in `namelessmc_db` for the *database address*. For database username, password and database name, fill `nameless` for all of them, if you used default database credentials.

3
build.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
docker build -t derkades/namelessmc-nginx nginx_web
docker build -t derkades/namelessmc-php php_fpm

11
deploy.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
export DOCKER_CLI_EXPERIMENTAL=enabled
set +e
docker buildx rm namelessmc_builder
set -e
docker buildx create --use --name namelessmc_builder
docker buildx build -t derkades/namelessmc-nginx --platform=linux/arm,linux/arm64,linux/amd64 nginx_web --push
docker buildx build -t derkades/namelessmc-php --platform=linux/arm,linux/arm64,linux/amd64 php_fpm --push
docker buildx rm namelessmc_builder

View File

@ -1,23 +1,26 @@
version: '3.1'
version: '2'
services:
nameless:
build:
context: src
namelessmc:
image: derkades/namelessmc-nginx
ports: ['80:80']
volumes: ['/srv/namelessmc/web:/data']
# environment:
# PHP_FPM: namelessmc_php:9000
restart: unless-stopped
links:
- db
ports:
- "80:80"
db:
image: mysql:5.7
namelessmc_php:
image: derkades/namelessmc-php
volumes_from: [namelessmc]
restart: unless-stopped
expose:
- 3306
namelessmc_db:
image: mariadb
volumes: ['/srv/namelessmc/db:/var/lib/mysql']
environment:
- "MYSQL_ROOT_PASSWORD=nameless"
- "MYSQL_USER=nameless"
- "MYSQL_PASSWORD=nameless"
- "MYSQL_DATABASE=nameless"
MYSQL_ROOT_PASSWORD: nameless
MYSQL_USER: nameless
MYSQL_PASSWORD: nameless
MYSQL_DATABASE: nameless
restart: unless-stopped

15
nginx_web/Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM nginx:alpine
ENV PHP_FPM="namelessmc_php:9000"
RUN deluser xfs && \
delgroup www-data && \
adduser -DH -h /home/www-data -s /sbin/nologin -u 33 www-data
RUN find /etc/nginx -type f -not -name 'mime.types' -not -name 'fastcgi_params' -delete && \
rm -rf conf.d modules
COPY nginx.conf /etc/nginx
COPY entrypoint.sh /
ENTRYPOINT [ "sh", "/entrypoint.sh" ]

9
nginx_web/entrypoint.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
cat > /etc/nginx/php.conf << EOL
upstream php-handler {
server ${PHP_FPM};
}
EOL
exec nginx -g "daemon off;"

47
nginx_web/nginx.conf Normal file
View File

@ -0,0 +1,47 @@
user "www-data";
events {
worker_connections 1024;
}
http {
access_log /dev/stdout;
error_log /dev/stdout;
include mime.types;
default_type application/octet-stream;
include php.conf;
server {
listen 80 default_server;
server_name _;
index index.php index.html;
proxy_read_timeout 3600;
fastcgi_read_timeout 3600;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
root /data;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-handler;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
client_max_body_size 0;
}
}

23
php_fpm/Dockerfile Normal file
View File

@ -0,0 +1,23 @@
FROM php:7.4-fpm
ARG NAMELESSMC_VERSION=2.0.0-pr7
RUN docker-php-source extract && \
BUILD_DEPS="libmcrypt-dev libldap2-dev libjpeg62-turbo-dev libfreetype6-dev" && \
apt-get update && \
apt-get install -y $BUILD_DEPS libpng-dev curl tar && \
docker-php-ext-configure gd && \
docker-php-ext-install -j "$(nproc)" exif gd pdo_mysql mysqli && \
docker-php-source delete && \
apt-get purge -y $BUILD_DEPS && \
apt-get clean && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/{apt,dpkg,cache,log}/ /tmp/* /var/tmp/*
ADD entrypoint.sh /
ENV NAMELESSMC_VERSION=2.0.0-pr7
VOLUME [ "/data" ]
ENTRYPOINT [ "bash", "/entrypoint.sh" ]

22
php_fpm/entrypoint.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -e
if [ -n "$(ls -A /data 2>/dev/null)" ]
then
echo "Data directory contains files, not downloading NamelessMC"
else
echo "Data directory is empty, downloading NamelessMC.."
set -x
mkdir -p /data
cd /tmp
curl -Lo nameless.tar.gz https://github.com/NamelessMC/Nameless/archive/v$NAMELESSMC_VERSION.tar.gz
tar -xf nameless.tar.gz
mv Nameless-$NAMELESSMC_VERSION/{,.[^.]}* /data
chown -R www-data:www-data /data
chmod 755 -R /data
rm -rf /tmp
set +x
echo "Done!"
fi
exec php-fpm