Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luke- committed Dec 16, 2024
0 parents commit 240db71
Show file tree
Hide file tree
Showing 18 changed files with 573 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HUMHUB_DOCKER_VERSION="develop"
HUMHUB_DOCKER_DOMAIN="localhost"
HUMHUB_DOCKER_DB_DSN="mysql:host=db;dbname=humhub"
HUMHUB_DOCKER_DB_USER="root"
HUMHUB_DOCKER_DB_PASSWORD="ChangeMeToSuperSecretMySqlRootPassword:-)"
29 changes: 29 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Docker Image CI
on:
push:
tags:
- '*'
workflow_dispatch:
schedule:
- cron: "33 3 * * *"

jobs:
build:
strategy:
matrix:
branch: [develop, next]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: docker login
env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Build the Docker image
run: cd image; docker build . --file Dockerfile --build-arg BRANCH=${{ matrix.branch }} --tag humhub/humhub-dev:${{ matrix.branch }}

- name: Docker Push
run: docker push humhub/humhub-dev:${{ matrix.branch }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
humhub.env
humhub-data
caddy-data
mysql-data
3 changes: 3 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{$caddydomain} {
reverse_proxy humhub:8404
}
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# HumHub - Docker Image (Development Version)

The Docker package provides all the essential components for setting up your HumHub installation.

## Features

- HumHub Core Software (Apache2 + FPM)
- MariaDB (Database Server)
- Caddy (Reverse Proxy w/ automatic LetsEncrypt SSL certificates)
- Redis (Cache / Queue)

## Quick Start

### Installation

```
git clone [email protected]:humhub/docker-dev.git /opt/humhub
cd /opt/humhub
cp humhub.env.dist humhub.env
cp .env.dist .env
```

Then edit the `.env` file and set at least the `HUMHUB_DOCKER_DOMAIN`.

```
docker compose up -d
```

> On older Docker versions you may need to run `docker-compose up -d` instead.
Open your HumHub installation at: https://YOUR-HUMHUB_DOCKER_DOMAIN

> After installation, an e-mail server must be configured at: `Administration` -> `Settings` -> `Advanced` -> `E-Mail`.
### Upgrading

Running following commands in the main directory.

```
cd /opt/humhub
git pull
docker compose pull
docker compose down
docker compose up -d
```

> Also check for new configuration options in `.env.dist` and `humhub.env.dist` files.
## Other Setup Options

### HumHub CLI

You can use the wrapper script in the main directoy.

```
./yii.sh help
```

### Version Control

You can define the HumHub version using the variable `HUMHUB_DOCKER_VERSION`.

The following tags are currently available:
- ~~`master` - For the current stable version~~ (not available yet)
- `develop` - For the current development version
- `next` - For the next development version

For older versions:
- ~~`v1.17`~~ (not available yet)
- ~~`v1.17.0-beta.1`~~ (not available yet)

### Custom Themes & Modules

You can store your own themes/modules in the folders `/opt/humhub/humhub-data/themes` and `/opt/humhub/humhub-data/custom-modules`.

### Existing Reverse Proxy

**NGINX Example:**

If an NGINX web server is already running on the host on which the Docker container is started on the HTTPS port, a reverse proxy to the HumHub Docker container can be created in a virtual host via the following block.

```
location / {
proxy_pass http://127.0.0.1:8404;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
```

**Apache2 Example:**

TBD
60 changes: 60 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
services:
humhub:
image: humhub/humhub-dev:${HUMHUB_DOCKER_VERSION}
ports:
- 8404:8404
depends_on:
db:
condition: service_healthy
volumes:
- ./humhub-data:/var/lib/humhub
env_file:
- ./humhub.env
environment:
- HUMHUB_CONFIG__COMPONENTS__DB__DSN=${HUMHUB_DOCKER_DB_DSN}
- HUMHUB_CONFIG__COMPONENTS__DB__USERNAME=${HUMHUB_DOCKER_DB_USER}
- HUMHUB_CONFIG__COMPONENTS__DB__PASSWORD=${HUMHUB_DOCKER_DB_PASSWORD}
- HUMHUB_FIXED_SETTINGS__BASE__BASE_URL=https://${HUMHUB_DOCKER_DOMAIN}
- HUMHUB_FIXED_SETTINGS__BASE__CACHE_CLASS=yii\redis\Cache
- HUMHUB_CONFIG__COMPONENTS__REDIS__CLASS=yii\redis\Connection
- HUMHUB_CONFIG__COMPONENTS__REDIS__HOSTNAME=redis
- HUMHUB_CONFIG__COMPONENTS__REDIS__PORT=6379
- HUMHUB_CONFIG__COMPONENTS__REDIS__DATABASE=0
- HUMHUB_CONFIG__COMPONENTS__SESSION__CLASS=yii\redis\Session
db:
image: mariadb
restart: always
user: root
volumes:
- ./mysql-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${HUMHUB_DOCKER_DB_PASSWORD}
expose:
- 3306
healthcheck:
test: ["CMD", "/usr/local/bin/healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 5
caddy:
image: caddy:latest
ports:
- 80:80
- 443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./caddy-data:/data
environment:
- caddydomain=${HUMHUB_DOCKER_DOMAIN}
restart: always
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
restart: always
command: redis-server --save 20 1 --loglevel warning
volumes:
- cache:/data
volumes:
cache:
driver: local
3 changes: 3 additions & 0 deletions humhub.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use this file to pass HumHub Configuration

HUMHUB_DEBUG=false
111 changes: 111 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
FROM debian:bookworm

ARG HUMHUB_GIT_BRANCH="develop"

RUN apt-get update && apt-get install -y \
apache2 \
php-fpm php php-cli \
php-imagick php-curl php-bz2 php-gd php-intl php-mbstring php-mysql php-zip php-apcu php-xml php-ldap \
unzip curl zip joe git npm \
supervisor

#------------------------------------------------------------------------------------------------
# PHP, Apache2, FPM Config
#------------------------------------------------------------------------------------------------

RUN sed -i 's/variables_order = "GPCS"/variables_order = "EGPCS"/g' /etc/php/8.2/cli/php.ini && \
sed -i 's/variables_order = "GPCS"/variables_order = "EGPCS"/g' /etc/php/8.2/fpm/php.ini && \
sed -i 's/post_max_size = 8M/post_max_size = 512M/g' /etc/php/8.2/fpm/php.ini && \
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 512M/g' /etc/php/8.2/fpm/php.ini && \
sed -i 's/max_execution_time = 30/max_execution_time = 90/g' /etc/php/8.2/fpm/php.ini && \
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /etc/php/8.2/fpm/php.ini && \
a2enmod ssl rewrite headers proxy_fcgi setenvif proxy_fcgi && \
a2enconf php8.2-fpm && \
echo "Listen 8404" > /etc/apache2/ports.conf

COPY files/apache-config.conf /etc/apache2/sites-available/000-default.conf
COPY files/php-fpm-www.conf /etc/php/8.2/fpm/pool.d/www.conf

EXPOSE 80

#------------------------------------------------------------------------------------------------
# Install Requirements: Composer, NPM, Less, Grunt
#------------------------------------------------------------------------------------------------

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
npm install -g grunt-cli less less-plugin-clean-css

#------------------------------------------------------------------------------------------------
# HumHub Base GIT Install
#------------------------------------------------------------------------------------------------

RUN mkdir -p /opt/humhub
WORKDIR /opt/humhub

RUN git clone https://github.com/humhub/humhub.git /opt/humhub && \
git config --global --add safe.directory /opt/humhub && \
git checkout ${HUMHUB_GIT_BRANCH} && \
composer install --no-interaction --optimize-autoloader --prefer-dist && \
npm install && \
grunt build-assets && \
rm -rf /var/www/html/* && \
mkdir -p /var/www/html/protected/runtime && \
cp /opt/humhub/.htaccess.dist /var/www/html/.htaccess && \
ln -s /var/lib/humhub/uploads/ /var/www/html/ && \
ln -s /var/lib/humhub/assets/ /var/www/html/ && \
ln -s /var/lib/humhub/themes/ /var/www/html/ && \
ln -s /var/lib/humhub/config/ /var/www/html/protected/ && \
ln -s /var/lib/humhub/modules/ /var/www/html/protected/ && \
ln -s /var/lib/humhub/logs/ /var/www/html/protected/runtime/ && \
ln -s /opt/humhub/protected/humhub /var/www/html/protected/ && \
ln -s /opt/humhub/protected/vendor /var/www/html/protected/ && \
ln -s /opt/humhub/static /var/www/html/ && \
mkdir -p /var/lib/humhub-modules-custom && \
rm -rf /opt/humhub/.git* && \
rm -rf /opt/humhub/.idea && \
rm -rf /opt/humhub/.editorconfig && \
rm -rf /opt/humhub/.php-cs* && \
rm -rf /opt/humhub/index-test.php && \
rm -rf /opt/humhub/node_modules && \
rm -rf /opt/humhub/LICENSE* && \
rm -rf /opt/humhub/*.js && \
rm -rf /opt/humhub/*.lock && \
rm -rf /opt/humhub/*.json && \
rm -rf /opt/humhub/*.md && \
rm -rf /opt/humhub/*.dist && \
rm -rf /opt/humhub/robots.txt && \
rm -rf /root/.cache && \
rm -rf /root/.npm && \
rm -rf /var/lib/apt/lists/*

# We cannot symlink these entry scripts atm, since the DynamicConfig is otherwise loaded from /opt/humhub
RUN cp /opt/humhub/protected/yii /var/www/html/protected/ && \
cp /opt/humhub/index.php /var/www/html/index.php

#------------------------------------------------------------------------------------------------

COPY ["files/humhub-queue-listen.sh", "files/humhub-cron.sh", "files/humhub-startup.sh", "files/docker-entrypoint.sh", "/"]
RUN chmod +x /humhub-queue-listen.sh && \
chmod +x /humhub-startup.sh && \
chmod +x /docker-entrypoint.sh && \
mkdir -p /var/log/supervisord && \
mkdir -p /var/run/supervisord

COPY files/supervisord.conf /etc


#------------------------------------------------------------------------------------------------

ENV HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__SHOW_SCRIPT_NAME=false
ENV HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true
ENV HUMHUB_CONFIG__MODULES__INSTALLER__ENABLE_AUTO_SETUP=true
ENV HUMHUB_CONFIG__MODULES__MARKETPLACE__MODULE_BLACKLIST='["updater"]'
ENV HUMHUB_CONFIG__PARAMS__MODULE_AUTOLOAD_PATHS='["/var/lib/humhub/modules-custom"]'
ENV HUMHUB_CONFIG__COMPONENTS__REQUEST__TRUSTED_HOSTS='["0.0.0.0/0"]'
ENV HUMHUB_CONFIG__RUNTIME_PATH=/var/www/html/protected/runtime
ENV HUMHUB_ALIASES__WEBROOT=/var/www/html
ENV HUMHUB_ALIASES__APP=/var/www/html/protected
ENV HUMHUB_ALIASES__CONFIG=/var/www/html/protected/config
ENV HUMHUB_ALIASES__HUMHUB=/var/www/html/protected/humhub

CMD ["/docker-entrypoint.sh"]
1 change: 1 addition & 0 deletions image/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build --build-arg HUMHUB_GIT_BRANCH=develop --tag humhub/humhub-dev:latest .
26 changes: 26 additions & 0 deletions image/debug-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

CONTAINER_IMAGE_NAME="humhub/humhub-dev"

# Find containers running with the specified image base name (ignoring the tag)
CONTAINER_IDS=$(docker ps --format "{{.ID}} {{.Image}}" | grep -E "^.+ ${CONTAINER_IMAGE_NAME}(:.+)?$" | awk '{print $1}')

# Check if any containers are running with the specified image name
if [ -z "$CONTAINER_IDS" ]; then
echo "Error: No container running with image '${CONTAINER_IMAGE_NAME}'."
exit 1
fi

# Count the number of containers
CONTAINER_COUNT=$(echo "$CONTAINER_IDS" | wc -l)

if [ "$CONTAINER_COUNT" -gt 1 ]; then
echo "Error: Multiple containers are running with image '${CONTAINER_IMAGE_NAME}'."
exit 1
fi

# Exactly one container is running, execute the PHP script inside it
CONTAINER_ID=$(echo "$CONTAINER_IDS" | head -n 1)

echo "Executing PHP script in container '${CONTAINER_ID}'..."
docker exec -it "$CONTAINER_ID" /bin/bash
34 changes: 34 additions & 0 deletions image/files/apache-config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<VirtualHost *:8404>
DocumentRoot /var/www/html

<Directory /var/www/html>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>

<DirectoryMatch "/var/www/html/(\.|protected|themes/\w+/views|uploads/file)">
Order Deny,Allow
Deny from all
</DirectoryMatch>

<FilesMatch "^\.">
Order Deny,Allow
Deny from all
</FilesMatch>

<DirectoryMatch "/var/www/html/(static|uploads|themes|assets)">
Header set Cache-Control "max-age=172800, public"
</DirectoryMatch>

PassEnv HUMHUB_DEBUG
PassEnv HUMHUB_CONFIG__COMPONENTS__DB__DSN HUMHUB_CONFIG__COMPONENTS__DB__USERNAME HUMHUB_CONFIG__COMPONENTS__DB__PASSWORD
PassEnv HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__SHOW_SCRIPT_NAME HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL
PassEnv HUMHUB_CONFIG__COMPONENTS__REQUEST__TRUSTED_HOSTS
PassEnv HUMHUB_CONFIG__MODULES__INSTALLER__ENABLE_AUTO_SETUP
PassEnv HUMHUB_ALIASES__WEBROOT HUMHUB_ALIASES__APP HUMHUB_ALIASES__HUMHUB
PassEnv HUMHUB_FIXED_SETTINGS__BASE__BASE_URL

ErrorLog /dev/stderr
CustomLog /dev/stdout combined
</VirtualHost>
Loading

0 comments on commit 240db71

Please sign in to comment.