Migrating to fedora

This commit is contained in:
Shadchamp
2025-08-28 18:31:04 -04:00
parent 89aff94ec4
commit 512c1ffc38
7 changed files with 122 additions and 51 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
mysql
UNIT3D/
.env
.env
home/

View File

@@ -1,18 +1,22 @@
FROM archlinux:latest
FROM fedora:latest
LABEL description="UNIT3D Docker image"
LABEL version="latest"
LABEL name="unit3d docker"
# Install Remi repository and enable PHP 8.4 module
RUN dnf install -y dnf-plugins-core \
&& dnf install -y https://rpms.remirepo.net/fedora/remi-release-$(rpm -E %fedora).rpm \
&& dnf module reset php -y \
&& dnf module enable php:remi-8.4 -y \
&& dnf install -y php
# Install base dependencies
RUN pacman -Sy --noconfirm archlinux-keyring \
&& pacman-key --init \
&& pacman-key --populate archlinux \
&& pacman -Syu --noconfirm --needed \
RUN dnf -y update \
&& dnf -y install \
git \
base-devel \
mariadb \
valkey \
mariadb-server \
redis \
nginx \
python3 \
php \
@@ -20,32 +24,69 @@ RUN pacman -Sy --noconfirm archlinux-keyring \
php-gd \
php-intl \
php-pgsql \
php-sqlite \
php-redis \
php-imagick \
composer \
php-sqlite3 \
php-bcmath \
php-mysqlnd \
php-zip \
nodejs \
npm \
yarn \
unzip \
&& yes | pacman -Scc
&& dnf clean all
# Install composer manually
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
# Install yarnpkg using npm
RUN npm install -g yarn
# Install php-pecl-redis and php-imagick using pecl
RUN dnf -y install php-pear php-devel gcc make ImageMagick-devel \
&& pecl channel-update pecl.php.net \
&& pecl install redis imagick \
&& echo "extension=redis.so" > /etc/php.d/40-redis.ini \
&& echo "extension=imagick.so" > /etc/php.d/40-imagick.ini
# Install and enable dnf-automatic for automatic updates
RUN dnf -y install dnf-automatic \
&& systemctl enable dnf-automatic.timer
# Configure dnf-automatic to run updates at midnight UTC
RUN sed -i 's/^OnCalendar=.*/OnCalendar=*-*-* 00:00:00 UTC/' /usr/lib/systemd/system/dnf-automatic.timer
# Set up MariaDB
RUN mkdir -p /run/mysqld && chown mysql:mysql /run/mysqld
# Install bun globally using npm
RUN npm install -g bun || npm update -g bun
RUN sed -i '/^;extension=iconv/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=bcmath/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=intl/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=mysqli/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=intl/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=zip/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=pdo_mysql/s/^;//' /etc/php.ini \
&& sed -i '/^;extension=intl/s/^;//' /etc/php.ini
# Enable required PHP extensions
RUN sed -i '/^;zend_extension=opcache/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=iconv/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=bcmath/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=intl/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=mysqli/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=pdo_mysql/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=intl/s/^;//' /etc/php/php.ini \
&& sed -i '/^;extension=redis/s/^;//' /etc/php/conf.d/redis.ini \
&& sed -i '/^;extension=igbinary/s/^;//' /etc/php/conf.d/igbinary.ini
# Install bun globally using npm
RUN npm install -g bun || npm update -g bun
# Disable remote login for MariaDB (MySQL)
RUN echo "[mysqld]\nskip-networking\nskip-bind-address" >> /etc/my.cnf.d/disable-remote.cnf
# Disable user logon for mysql user
RUN usermod -s /sbin/nologin mysql
# Create restricted user for running PHP application
RUN useradd -r -s /sbin/nologin unit3d \
&& mkdir -p /var/www/html \
&& chown unit3d:unit3d /var/www/html
# Expose necessary ports

View File

@@ -35,11 +35,12 @@ A Dockerized setup for UNIT3D, an open-source private torrent tracker.
```
Replace `your_secure_username` and `your_strong_password` with your own secure values.
4. Create a directory for MySQL data persistence:
4. Create a directory for MySQL and cache data persistence:
```bash
mkdir mysql
mkdir home
```
This ensures your database data is stored outside the container and persists across restarts.
This ensures your database and cache data is stored outside the container and persists across restarts.
5. Start the `unit3d-setup` service using Docker Compose:
```bash

View File

@@ -10,6 +10,8 @@ services:
- ./unit3d.conf:/etc/nginx/conf.d/unit3d.conf
- ./mysql:/var/lib/mysql
- ./entrypoint.sh:/entrypoint.sh
- ./home:/home/unit3d/
- ./run.sh:/run.sh
env_file:
- .env
entrypoint: /entrypoint.sh
@@ -22,6 +24,8 @@ services:
- ./mysql:/var/lib/mysql
- ./entrypoint.sh:/entrypoint.sh
- ./database-setup.py:/database-setup.py
- ./setup.sh:/setup.sh
- ./home:/home/unit3d/
env_file:
- .env
entrypoint: /entrypoint.sh setup

View File

@@ -2,41 +2,29 @@
if [[ "$1" == "setup" ]]; then
echo "Setting up UNIT3D..."
# Run setup commands here
cd /var/www/html
composer install --no-interaction --prefer-dist
php artisan key:generate
echo "Please save this to APP_KEY in UNIT3D/.env"
echo "Setting correct permissions for MariaDB data directory..."
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 750 /var/lib/mysql
sudo chage -E -1 mysql
echo "Initializing MariaDB system tables if necessary..."
if [ ! -d "/var/lib/mysql/mysql" ]; then
su -s /bin/bash mysql -c "mysql_install_db --basedir=/usr --datadir=/var/lib/mysql"
fi
echo "Setting correct permissions for MariaDB data directory..."
su -s /bin/bash mysql -c "mysqld &"
redis-server --daemonize yes
mkdir -p /run/php-fpm
php-fpm &
# Wait for MariaDB to be ready
until mysqladmin ping -h "localhost" --silent; do
echo "Waiting for MariaDB to be available..."
sleep 2
done
python3 /database-setup.py
# Keep MariaDB running in the background
php artisan migrate:fresh --seed
npm install -g bun || npm update -g bun
bun install
bun pm untrusted
bun pm trust --all
bun install
bun run build
php artisan set:all_cache
redis-server --daemonize yes
php artisan queue:restart
sudo chown -R unit3d:unit3d /var/www/html /home/unit3d/
su -s /bin/bash unit3d -c "/setup.sh"
tail -f /dev/null
fi
if [[ "$1" == "debug" ]]; then
echo "Debug mode: keeping container running..."
@@ -64,11 +52,16 @@ if [[ -z "$1" ]]; then
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 750 /var/lib/mysql
sudo chage -E -1 mysql
su -s /bin/bash mysql -c "mysqld &"
# Ensure correct ownership for /var/www/html
sudo chown -R unit3d:unit3d /var/www/html
su -s /bin/bash mysql -c "cd '/usr' ; /usr/bin/mariadbd-safe --datadir='/var/lib/mysql'"
# Wait for MariaDB to be ready
until mysqladmin ping -h "localhost" --silent; do
echo "Waiting for MariaDB to be available..."
sleep 2
done
/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
redis-server --daemonize yes
php-fpm &
su -s /bin/bash unit3d -c "/run.sh"
fi

7
run.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
cd /var/www/html
PATH="$NPM_PACKAGES/bin:$PATH"
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80

24
setup.sh Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Run setup commands here
cd /var/www/html
composer install --no-interaction --prefer-dist
php artisan key:generate
echo "Please save this to APP_KEY in UNIT3D/.env"
# Keep MariaDB running in the background
php artisan migrate:fresh --seed
mkdir -p $HOME/.npm-packages
export NPM_PACKAGES="$HOME/.npm-packages"
PATH="$NPM_PACKAGES/bin:$PATH"
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
bun install
bun pm untrusted
bun pm trust --all
bun install
bun run build
php artisan set:all_cache
php artisan queue:restart