Skip to content

Commit

Permalink
refactor: Docker (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
IceToast authored Oct 2, 2024
2 parents 58dc351 + 5db2b3d commit 0b99933
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 71 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Push Docker Image

on:
push:
tags:
- '*'

jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
file: docker/standalone/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 0 additions & 2 deletions bin/rebuild.sh

This file was deleted.

2 changes: 0 additions & 2 deletions bin/startdocker.sh

This file was deleted.

1 change: 0 additions & 1 deletion bin/stopdocker.sh

This file was deleted.

3 changes: 3 additions & 0 deletions config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'permission' => 0664,
],

'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
'permission' => 0664,
],

'slack' => [
Expand Down Expand Up @@ -116,6 +118,7 @@

'emergency' => [
'path' => storage_path('logs/laravel.log'),
'permission' => 0664,
],
],

Expand Down
3 changes: 3 additions & 0 deletions docker/development/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!.gitignore
mysql
nginx_config
23 changes: 23 additions & 0 deletions docker/development/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 🐳 Docker Development Environment

This development environment utilizes standalone Docker with necessary tools pre-configured.

## Included Services
- Redis
- MySQL
- Tools like phpMyAdmin

## Not Included Services (for the moment)
- Pterodactyl
- Wings

Feel free to modify the Docker Compose file to remove any services you already have.

## Setting Up the Testing Environment

1. **Manual Setup:** As mentioned in the standalone Docker guide, you will need to manually set up some components.
2. **Custom Configuration:** Modify the CtrlPanel Docker Compose configuration to use your current project as a base. If you point it to an empty folder, it will clone the repository, and you won't see your changes immediately.

For detailed setup instructions, refer to the standalone Docker documentation.

⚠ Caution: These instructions have not been finished. Therefore, there may be inaccuracies, instability, or non-functional aspects. Proceed with care.
57 changes: 26 additions & 31 deletions docker/docker-compose.yml → docker/development/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
version: '3'

networks:
laravel:

services:
nginx:
# TODO: add wings and pterodactyl
ctrlpanel_development:
build:
context: ../
dockerfile: docker/nginx/Dockerfile
container_name: ctrlpanel_nginx
context: ../../
dockerfile: ./docker/standalone/Dockerfile
container_name: ctrlpanel_development
restart: unless-stopped
ports:
- 80:80
- "80:80"
- "443:443"
volumes:
- "../:/var/www/html"
depends_on:
- php
- mysql
- '../..:/var/www/html:rw'
- './nginx_config:/etc/nginx/conf.d/:rw'
networks:
- laravel
- ctrlpanel

mysql:
image: mysql
Expand All @@ -28,23 +24,13 @@ services:
- "3306:3306"
environment:
MYSQL_DATABASE: ctrlpanel
MYSQL_USER: ctrlpanel
MYSQL_USER: ctrlpaneluser
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- "mysql:/var/lib/mysql:delegated"
networks:
- laravel

php:
build:
context: ../
dockerfile: docker/php/Dockerfile
container_name: ctrlpanel_php
volumes:
- "../:/var/www/html"
- "./mysql:/var/lib/mysql:delegated"
networks:
- laravel
- ctrlpanel

phpmyadmin:
image: phpmyadmin/phpmyadmin
Expand All @@ -59,7 +45,16 @@ services:
- PMA_PASSWORD=root
- PMA_ARBITRARY=1
networks:
- laravel
- ctrlpanel

volumes:
mysql:
redis:
image: redis
container_name: ctrlpanel_redis
restart: unless-stopped
ports:
- "6379:6379"
networks:
- ctrlpanel

networks:
ctrlpanel:
10 changes: 0 additions & 10 deletions docker/nginx/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions docker/php/Dockerfile

This file was deleted.

62 changes: 62 additions & 0 deletions docker/standalone/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM php:8.1-fpm

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
nginx \
nano \
curl \
git \
libcurl4-openssl-dev \
libicu-dev \
libzip-dev \
libpng-dev \
&& rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN pecl install redis \
&& docker-php-ext-enable redis \
&& docker-php-ext-install -j$(nproc) \
mysqli \
pdo \
pdo_mysql \
intl \
zip \
gd \
bcmath \
&& rm -rf /tmp/* /var/cache/*

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create directory for application
RUN mkdir -p /var/default /var/www/html

# Create user and group for Laravel
RUN groupadd -g 1000 laravel \
&& useradd -u 1000 -g laravel -ms /bin/bash laravel \
&& chown -R laravel:laravel /var/default /var/www/html

# Copy application files
COPY --chown=laravel:laravel . /var/default

# Copy PHP-FPM configuration
COPY --chown=laravel:laravel ./docker/standalone/php/www.conf /usr/local/etc/php-fpm.d/

# Copy Nginx configuration
COPY --chown=laravel:laravel ./docker/standalone/nginx/nginx.conf /etc/nginx/nginx.conf
# Create directory for Nginx logs
RUN mkdir -p /var/log/nginx && chown -R laravel:laravel /var/log/nginx

# Expose ports
EXPOSE 80 443

# Copy startup script
COPY --chown=laravel:laravel ./docker/standalone/scripts/startup.sh /usr/local/bin/startup-script.sh
# Make startup script executable
RUN chmod +x /usr/local/bin/startup-script.sh

# Set the working directory
WORKDIR /var/www/html

# Start the startup script
CMD ["/usr/local/bin/startup-script.sh"]
34 changes: 34 additions & 0 deletions docker/standalone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 🐳 Standalone Docker

The CtrlPanel standalone Docker enables users to run CtrlPanel easily with just a few clicks.

To run CtrlPanel standalone Docker, you need to have Docker installed on your machine. Some server operating systems like Unraid, TrueNAS, etc.. already have Docker installed, making it even easier to run CtrlPanel.
If you're using a different operating system, you can follow the official Docker installation guide [here](https://docs.docker.com/get-docker/).

Once you have Docker installed, you can run CtrlPanel standalone Docker by executing the following command:

Running as commandline command:

```bash
docker run -p 80:80 -p 443:443 -v /path/to/website_files:/var/www/html ghcr.io/ctrlpanel-gg/panel:latest
```

This command will run the latest CtrlPanel Docker image from GitHub Container Registry and run it.

Recommended way via Docker Compose:

1. Copy and configure your docker compose file to your needs `curl -L -o compose.yaml https://raw.githubusercontent.com/Ctrlpanel-gg/panel/blob/main/docker/standalone/compose.yaml`.
2. Create the env file in the same directory as the compose file `touch env_file`.
3. When installing you need to update the `env_file` file. Change those two variables to: `MEMCACHED_HOST=redis` and `REDIS_HOST=redis`, to use the Redis server which comes with the docker compose installation.

The control panel will be available at http://localhost/install and will be a completely fresh installation.

Note that while the container contains the full CtrlPanel installation, you will still need to perform the basic setup. You can find instructions for this [here](https://ctrlpanel.gg/docs/Installation/getting-started#basic-setup).

## 🏗️ Migrating from a previous bare metal installation

If you are migrating, from a previous bare metal installation, you can follow the instructions [here]() (Soon on documentation).

## 🧰 Creating your own Docker image

If you want to create your own Docker image, you can follow the instructions [here]() (Soon on documentation).
62 changes: 62 additions & 0 deletions docker/standalone/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
services:
ctrlpanel_standalone:
image: ghcr.io/ctrlpanel-gg/panel:latest
container_name: ctrlpanel_standalone
restart: unless-stopped
depends_on:
- redis
ports:
- "80:80"
- "443:443"
volumes:
- './logs:/var/www/html/storage/logs:w'
- './env_file:/var/www/html/.env'
- './website_files:/var/www/html:rw' # optionally remove this bind mount, it's not needed unless you want access to all project files, to modify the project with addons/plugins.
- './nginx_config:/etc/nginx/conf.d/:rw' # optionally remove this bind mount, it's not needed unless you want to modify the project with addons/plugins. (dangerous to edit)
networks:
- ctrlpanel

mysql:
image: mysql
container_name: ctrlpanel_mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ctrlpanel
MYSQL_USER: ctrlpaneluser
MYSQL_PASSWORD: root # change it
MYSQL_ROOT_PASSWORD: root # change it
volumes:
- "./mysql:/var/lib/mysql:delegated"
networks:
- ctrlpanel

phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: ctrlpanel_phpmyadmin
restart: unless-stopped
depends_on:
- mysql
ports:
- '8080:80'
environment:
- PMA_HOST=ctrlpanel_mysql
- PMA_USER=root # change it
- PMA_PASSWORD=root # change it
- PMA_ARBITRARY=1
networks:
- ctrlpanel

redis:
image: redis
container_name: ctrlpanel_redis
restart: unless-stopped
ports:
- "6379:6379"
networks:
- ctrlpanel

networks:
ctrlpanel:
Loading

0 comments on commit 0b99933

Please sign in to comment.