dev: minio for local s3 testing and mailpit!

This commit is contained in:
Elizabeth
2025-08-15 03:31:00 -05:00
parent aa1d24ade1
commit 2d063fec1e
2 changed files with 306 additions and 43 deletions

3
Vagrantfile vendored
View File

@@ -10,6 +10,9 @@ Vagrant.configure("2") do |config|
3000, # app
3306, # database
8080, # alt-http
8025, # mailpit web ui
9000, # minio api
9001, # minio console
25565, # test ports...
25566,
25567

View File

@@ -7,9 +7,15 @@ err() { echo -e "\n\033[1;31m!! $*\033[0m" >&2; }
export DEBIAN_FRONTEND=noninteractive
log Updating OS packages
apt-get update -y
apt-get upgrade -y
log Checking and updating OS packages
if [ ! -f /var/lib/pterodactyl-provision/packages-updated ]; then
apt-get update -y
apt-get upgrade -y
mkdir -p /var/lib/pterodactyl-provision
touch /var/lib/pterodactyl-provision/packages-updated
else
log "OS packages already updated, skipping"
fi
log Installing base utilities
apt-get install -y \
@@ -23,6 +29,10 @@ ufw allow ssh
ufw allow 3306/tcp
ufw allow 3000/tcp
ufw allow 8080/tcp
ufw allow 9000/tcp # MinIO API
ufw allow 9001/tcp # MinIO Console
ufw allow 8025/tcp # Mailpit Web UI
ufw allow 1025/tcp # Mailpit SMTP
ufw allow 25500:25600/tcp
ufw allow 25500:25600/udp
@@ -31,8 +41,13 @@ apt-get install -y redis-server
systemctl enable --now redis-server
log Adding PHP 8.3 repository
add-apt-repository -y ppa:ondrej/php
apt-get update -y
if [ ! -f /var/lib/pterodactyl-provision/php-repo-added ]; then
add-apt-repository -y ppa:ondrej/php
apt-get update -y
touch /var/lib/pterodactyl-provision/php-repo-added
else
log "PHP repository already added, skipping"
fi
log Installing PHP 8.3 + extensions
apt-get install -y \
@@ -234,7 +249,6 @@ Group=vagrant
WorkingDirectory=/var/www/pterodactyl
Restart=always
ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
StartLimitIntervalSec=180
StartLimitBurst=30
RestartSec=5s
[Install]
@@ -242,20 +256,32 @@ WantedBy=multi-user.target
EOF
log Installing Docker Engine
install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
>/etc/apt/sources.list.d/docker.list
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker
if ! command -v docker >/dev/null 2>&1; then
install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
>/etc/apt/sources.list.d/docker.list
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker
else
log "Docker already installed, skipping"
fi
log Installing Wings
install -d -m 0755 /etc/pterodactyl
ARCH=$(uname -m); [[ $ARCH == x86_64 ]] && ARCH=amd64 || ARCH=arm64
curl -fsSL -o /usr/local/bin/wings "https://github.com/pterodactyl/wings/releases/latest/download/wings_linux_${ARCH}"
chmod u+x /usr/local/bin/wings
sudo -u vagrant -H bash -lc 'cd /var/www/pterodactyl && php artisan p:node:configuration 1' >/etc/pterodactyl/config.yml || true
if [ ! -f /usr/local/bin/wings ]; then
ARCH=$(uname -m); [[ $ARCH == x86_64 ]] && ARCH=amd64 || ARCH=arm64
curl -fsSL -o /usr/local/bin/wings "https://github.com/pterodactyl/wings/releases/latest/download/wings_linux_${ARCH}"
chmod u+x /usr/local/bin/wings
else
log "Wings already installed, skipping download"
fi
if [ ! -f /etc/pterodactyl/config.yml ]; then
sudo -u vagrant -H bash -lc 'cd /var/www/pterodactyl && php artisan p:node:configuration 1' >/etc/pterodactyl/config.yml || true
else
log "Wings config already exists, skipping"
fi
cat >/etc/systemd/system/wings.service <<EOF
[Unit]
@@ -268,7 +294,6 @@ WorkingDirectory=/etc/pterodactyl
LimitNOFILE=4096
ExecStart=/usr/local/bin/wings
Restart=on-failure
StartLimitIntervalSec=180
StartLimitBurst=30
RestartSec=5s
[Install]
@@ -280,6 +305,217 @@ systemctl daemon-reload
systemctl enable --now pteroq
systemctl enable --now wings
log Installing MinIO
if ! command -v minio >/dev/null 2>&1; then
ARCH=$(uname -m); [[ $ARCH == x86_64 ]] && ARCH=amd64 || ARCH=arm64
curl -fsSL -o /usr/local/bin/minio "https://dl.min.io/server/minio/release/linux-${ARCH}/minio"
chmod +x /usr/local/bin/minio
# Create minio user and directories
useradd -r minio-user || true
mkdir -p /opt/minio/data
mkdir -p /etc/minio
chown minio-user:minio-user /opt/minio/data
# Create MinIO environment file
cat >/etc/minio/minio.conf <<EOF
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadmin
MINIO_VOLUMES=/opt/minio/data
MINIO_OPTS="--console-address :9001"
EOF
# Create systemd service
cat >/etc/systemd/system/minio.service <<EOF
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio
[Service]
WorkingDirectory=/usr/local
User=minio-user
Group=minio-user
ProtectProc=invisible
EnvironmentFile=/etc/minio/minio.conf
ExecStartPre=/bin/bash -c 'if [ -z "\${MINIO_VOLUMES}" ]; then echo "Variable MINIO_VOLUMES not set in /etc/minio/minio.conf"; exit 1; fi'
ExecStart=/usr/local/bin/minio server \$MINIO_OPTS \$MINIO_VOLUMES
# Let systemd restart this service always
Restart=always
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of threads this process can create
TasksMax=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now minio
# Wait for MinIO to start
sleep 5
# Create default buckets using mc (MinIO Client)
curl -fsSL -o /usr/local/bin/mc "https://dl.min.io/client/mc/release/linux-${ARCH}/mc"
chmod +x /usr/local/bin/mc
# Configure mc alias and create buckets
sudo -u vagrant -H bash -c '
/usr/local/bin/mc alias set local http://localhost:9000 minioadmin minioadmin
/usr/local/bin/mc mb local/pterodactyl-backups --ignore-existing
' || true
# Configure MinIO in .env for S3 backups
pushd /var/www/pterodactyl >/dev/null
if [ -f .env ]; then
# Set S3 backup configuration for MinIO
sed -i '/^APP_BACKUP_DRIVER=/c\APP_BACKUP_DRIVER=s3' .env
# Configure AWS/S3 settings for MinIO
if grep -q "^AWS_ACCESS_KEY_ID=" .env; then
sed -i '/^AWS_ACCESS_KEY_ID=/c\AWS_ACCESS_KEY_ID=minioadmin' .env
else
echo 'AWS_ACCESS_KEY_ID=minioadmin' >> .env
fi
if grep -q "^AWS_SECRET_ACCESS_KEY=" .env; then
sed -i '/^AWS_SECRET_ACCESS_KEY=/c\AWS_SECRET_ACCESS_KEY=minioadmin' .env
else
echo 'AWS_SECRET_ACCESS_KEY=minioadmin' >> .env
fi
if grep -q "^AWS_DEFAULT_REGION=" .env; then
sed -i '/^AWS_DEFAULT_REGION=/c\AWS_DEFAULT_REGION=us-east-1' .env
else
echo 'AWS_DEFAULT_REGION=us-east-1' >> .env
fi
if grep -q "^AWS_BACKUPS_BUCKET=" .env; then
sed -i '/^AWS_BACKUPS_BUCKET=/c\AWS_BACKUPS_BUCKET=pterodactyl-backups' .env
else
echo 'AWS_BACKUPS_BUCKET=pterodactyl-backups' >> .env
fi
if grep -q "^AWS_ENDPOINT=" .env; then
sed -i '/^AWS_ENDPOINT=/c\AWS_ENDPOINT=http://localhost:9000' .env
else
echo 'AWS_ENDPOINT=http://localhost:9000' >> .env
fi
if grep -q "^AWS_USE_PATH_STYLE_ENDPOINT=" .env; then
sed -i '/^AWS_USE_PATH_STYLE_ENDPOINT=/c\AWS_USE_PATH_STYLE_ENDPOINT=true' .env
else
echo 'AWS_USE_PATH_STYLE_ENDPOINT=true' >> .env
fi
fi
popd >/dev/null
log "MinIO installed and configured successfully"
log "MinIO Console: http://localhost:9001 (minioadmin/minioadmin)"
else
log "MinIO already installed, skipping"
fi
log Installing Mailpit
if ! command -v mailpit >/dev/null 2>&1; then
ARCH=$(uname -m); [[ $ARCH == x86_64 ]] && ARCH=linux-amd64 || ARCH=linux-arm64
MAILPIT_VERSION=$(curl -s https://api.github.com/repos/axllent/mailpit/releases/latest | jq -r .tag_name)
curl -fsSL -o /tmp/mailpit.tar.gz "https://github.com/axllent/mailpit/releases/download/${MAILPIT_VERSION}/mailpit-${ARCH}.tar.gz"
tar -xzf /tmp/mailpit.tar.gz -C /tmp
mv /tmp/mailpit /usr/local/bin/
chmod +x /usr/local/bin/mailpit
rm -f /tmp/mailpit.tar.gz
# Create mailpit user
useradd -r mailpit-user || true
# Create systemd service
cat >/etc/systemd/system/mailpit.service <<EOF
[Unit]
Description=Mailpit SMTP testing server
After=network.target
[Service]
ExecStart=/usr/local/bin/mailpit --smtp 0.0.0.0:1025 --listen 0.0.0.0:8025
User=mailpit-user
Group=mailpit-user
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now mailpit
# Configure Mailpit in .env for mail testing
pushd /var/www/pterodactyl >/dev/null
if [ -f .env ]; then
# Set mail configuration for Mailpit
if grep -q "^MAIL_MAILER=" .env; then
sed -i '/^MAIL_MAILER=/c\MAIL_MAILER=smtp' .env
else
echo 'MAIL_MAILER=smtp' >> .env
fi
if grep -q "^MAIL_HOST=" .env; then
sed -i '/^MAIL_HOST=/c\MAIL_HOST=localhost' .env
else
echo 'MAIL_HOST=localhost' >> .env
fi
if grep -q "^MAIL_PORT=" .env; then
sed -i '/^MAIL_PORT=/c\MAIL_PORT=1025' .env
else
echo 'MAIL_PORT=1025' >> .env
fi
if grep -q "^MAIL_USERNAME=" .env; then
sed -i '/^MAIL_USERNAME=/c\MAIL_USERNAME=' .env
else
echo 'MAIL_USERNAME=' >> .env
fi
if grep -q "^MAIL_PASSWORD=" .env; then
sed -i '/^MAIL_PASSWORD=/c\MAIL_PASSWORD=' .env
else
echo 'MAIL_PASSWORD=' >> .env
fi
if grep -q "^MAIL_ENCRYPTION=" .env; then
sed -i '/^MAIL_ENCRYPTION=/c\MAIL_ENCRYPTION=' .env
else
echo 'MAIL_ENCRYPTION=' >> .env
fi
if grep -q "^MAIL_FROM_ADDRESS=" .env; then
sed -i '/^MAIL_FROM_ADDRESS=/c\MAIL_FROM_ADDRESS=no-reply@localhost' .env
else
echo 'MAIL_FROM_ADDRESS=no-reply@localhost' >> .env
fi
fi
popd >/dev/null
log "Mailpit installed and configured successfully"
log "Mailpit Web UI: http://localhost:8025"
else
log "Mailpit already installed, skipping"
fi
log Generating Application API Key
pushd /var/www/pterodactyl >/dev/null
API_KEY_RESULT=$(sudo -u vagrant -H bash -lc 'php artisan tinker --execute="
@@ -335,7 +571,8 @@ if [ -n "${API_KEY:-}" ]; then
},
"feature_limits": {
"databases": 0,
"allocations": 1
"allocations": 1,
"backups": 0
},
"allocation": {
"default": $ALLOCATION_ID
@@ -353,30 +590,45 @@ if [ -n "${API_KEY:-}" ]; then
}
EOF
SERVER_RESPONSE=$(curl -s -X POST http://localhost:3000/api/application/servers \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: Application/vnd.pterodactyl.v1+json" \
-d @/tmp/server_create.json 2>/dev/null || echo '{"error":"curl_failed"}')
rm -f /tmp/server_create.json
# Check if a Minecraft server already exists
EXISTING_SERVER=$(mysql -u root -D panel -N -B -e "SELECT id FROM servers WHERE name='Minecraft Vanilla Dev Server' LIMIT 1;" 2>/dev/null || echo "")
if echo "$SERVER_RESPONSE" | grep -q '"object":"server"'; then
SERVER_ID=$(echo "$SERVER_RESPONSE" | jq -r '.attributes.id' 2>/dev/null || echo "")
SERVER_UUID=$(echo "$SERVER_RESPONSE" | jq -r '.attributes.uuid' 2>/dev/null || echo "")
if [ -n "$SERVER_ID" ] && [ "$SERVER_ID" != "null" ]; then
echo SERVER_ID=$SERVER_ID >> /home/vagrant/.bashrc
echo SERVER_UUID=$SERVER_UUID >> /home/vagrant/.bashrc
curl -s -X POST http://localhost:3000/api/application/servers/$SERVER_ID/reinstall \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: Application/vnd.pterodactyl.v1+json" >/dev/null 2>&1 || true
log "Server created successfully with ID: $SERVER_ID"
else
warn "Server creation succeeded but failed to extract server ID"
if [ -n "$EXISTING_SERVER" ]; then
log "Minecraft server already exists with ID: $EXISTING_SERVER, skipping creation"
if ! grep -q "SERVER_ID=" /home/vagrant/.bashrc 2>/dev/null; then
echo SERVER_ID=$EXISTING_SERVER >> /home/vagrant/.bashrc
SERVER_UUID=$(mysql -u root -D panel -N -B -e "SELECT uuid FROM servers WHERE id=$EXISTING_SERVER;" 2>/dev/null || echo "")
if [ -n "$SERVER_UUID" ]; then
echo SERVER_UUID=$SERVER_UUID >> /home/vagrant/.bashrc
fi
fi
else
warn "Server creation failed or returned unexpected response"
# Don't show the full response as it might contain sensitive info, just log the attempt
SERVER_RESPONSE=$(curl -s -X POST http://localhost:3000/api/application/servers \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: Application/vnd.pterodactyl.v1+json" \
-d @/tmp/server_create.json 2>/dev/null || echo '{"error":"curl_failed"}')
rm -f /tmp/server_create.json
if echo "$SERVER_RESPONSE" | grep -q '"object":"server"'; then
SERVER_ID=$(echo "$SERVER_RESPONSE" | jq -r '.attributes.id' 2>/dev/null || echo "")
SERVER_UUID=$(echo "$SERVER_RESPONSE" | jq -r '.attributes.uuid' 2>/dev/null || echo "")
if [ -n "$SERVER_ID" ] && [ "$SERVER_ID" != "null" ]; then
echo SERVER_ID=$SERVER_ID >> /home/vagrant/.bashrc
echo SERVER_UUID=$SERVER_UUID >> /home/vagrant/.bashrc
curl -s -X POST http://localhost:3000/api/application/servers/$SERVER_ID/reinstall \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: Application/vnd.pterodactyl.v1+json" >/dev/null 2>&1 || true
log "Server created successfully with ID: $SERVER_ID"
else
warn "Server creation succeeded but failed to extract server ID"
fi
else
warn "Server creation failed or returned unexpected response"
# Don't show the full response as it might contain sensitive info, just log the attempt
fi
fi
rm -f /tmp/server_create.json
fi
else
log API key already exists, skipping creation
@@ -385,8 +637,16 @@ fi
systemctl restart php8.3-fpm
systemctl reload nginx || systemctl restart nginx || true
echo "======================================="
echo " Provisioning Complete"
echo "======================================="
echo
echo "=== Development Services ==="
echo "Mailpit Web UI: http://localhost:8025"
echo "MinIO Console: http://localhost:9001"
echo "MinIO Credentials: minioadmin / minioadmin"
echo
echo "Panel: http://localhost:3000"
echo "Login: dev / dev"
echo "API Key: ${API_KEY:-<not created on this run>}"
echo
echo === Provisioning Complete ===
echo Panel: http://localhost:3000
echo Login: dev / dev
echo API Key: ${API_KEY:-<not created on this run>}