diff --git a/.dockerignore b/.dockerignore index 2aaa4394b..5fca33cea 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,5 @@ vagrant/ nix/ flake.nix flake.lock - +var/ +srv/ diff --git a/.github/docker/entrypoint.sh b/.github/docker/entrypoint.sh index 1089c3347..e975550a0 100644 --- a/.github/docker/entrypoint.sh +++ b/.github/docker/entrypoint.sh @@ -95,16 +95,16 @@ echo -e "Migrating Database" php artisan migrate --force if [ "$SKIP_SEED" != "True" ]; then - echo -e "Seeding database" - php artisan migrate --seed --force + echo -e "Seeding database" + php artisan migrate --seed --force else - echo -e "Skipping database seeding (SKIP_SEED=True)" + echo -e "Skipping database seeding (SKIP_SEED=True)" fi # Setup development environment if specified ( source /app/.env - if [ "$PYRODACTYL_DEV" = "true" ] && [ "$DEV_SETUP" != "true" ]; then + if [ "$PYRODACTYL_DOCKER_DEV" = "true" ] && [ "$DEV_SETUP" != "true" ]; then echo -e "\e[42mDevelopment environment detected, setting up development resources...\e[0m" # Create a developer user @@ -113,11 +113,54 @@ fi # Make a location and node for the panel php artisan p:location:make -n --short local --long Local - php artisan p:node:make -n --name local --description "Development Node" --locationId 1 --fqdn localhost --public 1 --scheme http --proxy 0 --maxMemory 1024 --maxDisk 10240 --overallocateMemory 0 --overallocateDisk 0 + php artisan p:node:make -n --name local --description "Development Node" --locationId 1 --fqdn $WINGS_IP --public 1 --scheme http --proxy 0 --maxMemory 1024 --maxDisk 10240 --overallocateMemory 0 --overallocateDisk 0 - # Add some dummy allocations to the node - mariadb -u root -h database -p"$DB_ROOT_PASSWORD" --ssl=0 -e "USE panel; INSERT INTO allocations (node_id, ip, port) VALUES (1, 'localhost', 25565), (1, 'localhost', 25566), (1, 'localhost', 25567);" + echo "Adding dummy allocations..." + mariadb -u root -h database -p"$DB_ROOT_PASSWORD" --ssl=0 -e "USE panel; INSERT INTO allocations (node_id, ip, port) VALUES (1, '0.0.0.0', 25565), (1, '0.0.0.0', 25566), (1, '0.0.0.0', 25567);" + echo "Creating database user..." + mariadb -u root -h database -p"$DB_ROOT_PASSWORD" --ssl=0 -e "CREATE USER 'pterodactyluser'@'%' IDENTIFIED BY 'somepassword'; GRANT ALL PRIVILEGES ON *.* TO 'pterodactyluser'@'%' WITH GRANT OPTION;" + + # Configure node + export WINGS_CONFIG=/etc/pterodactyl/config.yml + mkdir -p $(dirname $WINGS_CONFIG) + echo "Creating Wings configuration file at '$WINGS_CONFIG'" + php artisan p:node:configuration 1 > $WINGS_CONFIG + + # Allow all origins for CORS + echo "allowed_origins: ['*']" >> $WINGS_CONFIG + + # Update Wings configuration paths if WINGS_DIR is set + if [ -z "$WINGS_DIR" ]; then + echo "WINGS_DIR is not set, using default paths." + else + echo "Updating Wings configuration paths to '$WINGS_DIR'" + + update_config() { + key="$1" + value="$2" + + # update existing key or add new one + if grep -q "$key:" $WINGS_CONFIG; then + sed -i "s|$key:.*|$key: $value|" $WINGS_CONFIG + else + sed -i "/^system:/a\\ $key: $value" $WINGS_CONFIG + fi + } + + # if system section doesn't exists, add it + if ! grep -q "^system:" $WINGS_CONFIG; then + echo "system:" >> $WINGS_CONFIG + fi + + update_config "root_directory" "$WINGS_DIR/srv/wings/" + update_config "log_directory" "$WINGS_DIR/srv/wings/logs/" + update_config "data" "$WINGS_DIR/srv/wings/volumes" + update_config "archive_directory" "$WINGS_DIR/srv/wings/archives" + update_config "backup_directory" "$WINGS_DIR/srv/wings/backups" + update_config "tmp_directory" "$WINGS_DIR/srv/wings/tmp/" + fi + # Mark setup as complete echo "DEV_SETUP=true" >> /app/.env echo "Development setup complete." diff --git a/Dockerfile b/Dockerfile index be42a9055..8286268d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,6 +78,19 @@ COPY --chown=nginx:nginx .github/docker/default.conf /etc/nginx/http.d/default.c COPY --chown=nginx:nginx .github/docker/www.conf /usr/local/etc/php-fpm.conf COPY --chown=nginx:nginx .github/docker/supervisord.conf /etc/supervisord.conf +# Clean up image for dev environment +# This is because we share local files with the container +RUN if [ "$DEV" = "true" ]; then \ + echo "Cleaning up"; \ + find . \ + -mindepth 1 \ + \( -path './vendor' -o -path './vendor/*' \) -prune \ + -o \ + -exec rm -rf -- {} \; \ + >/dev/null 2>&1; \ + fi; \ + exit 0 + EXPOSE 80 443 ENTRYPOINT [ "/bin/ash", ".github/docker/entrypoint.sh" ] CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ] diff --git a/docker-compose.develop.yml b/docker-compose.develop.yml index 6b144b7a7..20a1b803c 100644 --- a/docker-compose.develop.yml +++ b/docker-compose.develop.yml @@ -1,17 +1,23 @@ x-common: + wings: &wings-environment + # The panel needs the to use the same FQDN/IP in both the container and the host, so a static IP is required. + # If you change it, you will need to update it in "http://localhost:3000/admin/nodes/view/1/settings" too, or down + # the compose, delete the "srv" folder, then up it again. + # + # macOS Docker Desktop users will need to install https://github.com/chipmk/docker-mac-net-connect for Wings to work. + # macOS OrbStack & Linux users shouldn't need to install the above. + ipv4: &wings-ipv4 172.20.0.99 database: &db-environment # Do not remove the "&db-password" from the end of the line below, it is important # for Panel functionality. MYSQL_PASSWORD: &db-password 'password' MYSQL_ROOT_PASSWORD: &db-root-password 'rootpassword' panel: &panel-environment - APP_URL: 'http://localhost:3000' + APP_URL: 'http://panel' # A list of valid timezones can be found here: http://php.net/manual/en/timezones.php APP_TIMEZONE: 'UTC' APP_SERVICE_AUTHOR: 'noreply@example.com' DB_USERNAME: 'pterodactyl' - # Specifies to setup default user, location, etc on first run - PYRODACTYL_DEV: 'true' # DB_PASSWORD: "Uncomment this to user your own password" # Uncomment the line below and set to a non-empty value if you want to use Let's Encrypt @@ -64,6 +70,7 @@ services: - './srv/nginx/:/etc/nginx/http.d/' - './srv/certs:/etc/letsencrypt' - './srv/logs/:/app/storage/logs' + - './srv/pterodactyl/config/:/etc/pterodactyl' environment: <<: [*panel-environment, *mail-environment] DB_PASSWORD: *db-password @@ -78,6 +85,46 @@ services: DB_HOST: 'database' DB_PORT: '3306' HASHIDS_LENGTH: 8 + WINGS_IP: *wings-ipv4 + WINGS_DIR: '${PWD}' + PYRODACTYL_DOCKER_DEV: 'true' + wings: + # The default Wings image doesn't work on macOS Docker + # This fork simply removes the incompatible `io.priority` cgroup v2 flag + # For Linux users, you can use the default image by uncommenting the line below + # image: ghcr.io/pterodactyl/wings:latest + image: ghcr.io/he3als/wings-mac:latest + restart: always + networks: + default: + ipv4_address: *wings-ipv4 + ports: + - '8080:8080' + - '2022:2022' + tty: true + environment: + TZ: 'UTC' + WINGS_UID: 988 + WINGS_GID: 988 + WINGS_USERNAME: pterodactyl + volumes: + - '/var/run/docker.sock:/var/run/docker.sock' + - '/etc/ssl/certs:/etc/ssl/certs:ro' + - './srv/pterodactyl/config/:/etc/pterodactyl/' + + # The volumes below need to be the exact same path in the container as on the host. + # + # The paths are currently hardcoded in the container on first run, meaning if you move + # this repo on your host, you'll need to delete "srv" folder so the paths can be recreated. + # + # If you change these from $PWD, make sure to update `WINGS_DIR` in the panel service too. + # Do not change anything but the $PWD part as this is also hardcoded in the container. + + - '${PWD}/srv/wings/tmp/:${PWD}/srv/wings/tmp/' + - '${PWD}/srv/wings/docker/containers/:${PWD}/srv/wings/docker/containers/' + - '${PWD}/srv/wings/:${PWD}/srv/wings/' + - '${PWD}/srv/wings/logs/:${PWD}/srv/wings/logs/' + networks: default: ipam: