فهرست منبع

Complete rewrite with entry-point

Alex Trofimov 6 سال پیش
والد
کامیت
23b9cdd543
4فایلهای تغییر یافته به همراه151 افزوده شده و 30 حذف شده
  1. 23 0
      .gitignore
  2. 17 30
      Dockerfile
  3. 33 0
      REAMDE.md
  4. 78 0
      docker-entrypoint.sh

+ 23 - 0
.gitignore

@@ -0,0 +1,23 @@
+.vagrant*
+bin
+docker/docker
+.*.swp
+a.out
+*.orig
+build_src
+.flymake*
+.idea
+.DS_Store
+docs/_build
+docs/_static
+docs/_templates
+.gopath/
+.dotcloud
+*.test
+bundles/
+.hg/
+.git/
+vendor/pkg/
+pyenv
+Vagrantfile
+tmp

+ 17 - 30
Dockerfile

@@ -3,7 +3,10 @@ FROM php:7.4-apache
 
 MAINTAINER at@una.io
 
+USER root
+
 # PHP extensions and necessary packages
+
 RUN apt-get update && apt-get install -y \
         cron \
         libfreetype6-dev \
@@ -36,42 +39,22 @@ RUN groupadd -r --gid 2483 www-una \
  && useradd -r --uid 2483 -g www-una www-una \
  && chown www-una:www-una /var/www/html /var/www
 
-# Unzip package
-
-USER www-una
-
-WORKDIR /var/www/html
-
-ENV UNA_VERSION 11.0.3
-
-# Alternative download URL - https://github.com/unaio/una/releases/download/${UNA_VERSION}/UNA-v.${UNA_VERSION}.zip
-RUN curl -fSL "http://ci.una.io/builds/UNA-v.${UNA_VERSION}.zip" -o una.zip \
- && unzip -o una.zip \
- && rm una.zip \
- && mv UNA-v.${UNA_VERSION}/* . \
- && mv UNA-v.${UNA_VERSION}/.htaccess . \
- && rm -rf "UNA-v.${UNA_VERSION}" 
-
-RUN chmod 777 inc cache cache_public logs tmp storage \
- && chmod +x plugins/ffmpeg/ffmpeg.exe
-
 # Apache configuration
 
-USER root
+ENV APACHE_RUN_USER www-una
+ENV APACHE_RUN_GROUP www-una
 
 RUN echo "memory_limit=192M \n\
 post_max_size=100M \n\
 upload_max_filesize=100M \n\
-error_log=/var/www/php_error.log \n\
+error_log=/var/log/php/error.log \n\
 error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT \n\
 display_errors=Off \n\
 log_errors=On \n\
 sendmail_path=/usr/sbin/sendmail -t -i \n\
 date.timezone=UTC" > /var/www/php.ini && chown www-una:www-una /var/www/php.ini
 
-RUN touch /var/www/php_error.log \
- && chown www-una:www-una /var/www/php_error.log \
- && chmod 666 /var/www/php_error.log
+RUN mkdir /var/log/php && chown www-una:www-una /var/log/php && chmod 777 /var/log/php && su www-una -c "ln -s /dev/stderr /var/log/php/error.log"
 
 RUN echo "<VirtualHost *:80> \n\
         DocumentRoot /var/www/html \n\
@@ -82,14 +65,18 @@ RUN echo "<VirtualHost *:80> \n\
 
 RUN a2enmod rewrite expires
 
-# Crontab
+# Expose port and set volume
 
-RUN echo "* * * * * php -c /var/www /var/www/html/periodic/cron.php" > /var/www/crontab \
- && chown www-una:www-una /var/www/crontab \
- && crontab -u www-una /var/www/crontab 
-
-# Expose port
+WORKDIR /var/www/html
 
 VOLUME /var/www
 
 EXPOSE 80
+
+# Entrypoint
+
+COPY docker-entrypoint.sh /usr/local/bin/
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+
+CMD ["apache2-foreground"]

+ 33 - 0
REAMDE.md

@@ -0,0 +1,33 @@
+# Official UNA Docker repository
+
+This is the official git repository for UNA. Refer to [Docker Hub page](https://hub.docker.com/r/unaio/una) for the actual UNA Docker image.
+
+
+## How to use this image
+
+```
+docker run -e "UNA_DB_HOST=host.docker.internal" -e "UNA_DB_NAME=test" -e "UNA_ADMIN_PWD=5ecret" -d -p 80:80 --name una unaio/una:latest
+```
+
+Above example assumes that UNA is run locally with mysql server installed on the host machine. After the run UNA should be accessible using `http://localhost` URL, you can login with `admin@example.com` email and   `5ecret` password.
+
+## Full list of supported environment variables
+
+`UNA_DB_HOST` - MySQL database hostname, default - `localhost`
+`UNA_DB_PORT` - MySQL database port, default - `3306`
+`UNA_DB_SOCK` - MySQL database sock file path, optional
+`UNA_DB_NAME` - MySQL database name, **required** 
+`UNA_DB_USER` - MySQL database user, default - `root`
+`UNA_DB_PWD` - MySQL database user, default - `root`
+`UNA_HTTP_HOST` - UNA hostname, if other that `80` port is used, then it need to be specified here, for example `localhost:8000`, default - `localhost` 
+`UNA_SITE_TITLE` - new site title, default - `UNA`
+`UNA_SITE_EMAIL` - new site email, to send mail from, default - `admin@example.com`
+`UNA_ADMIN_USERNAME` - admin username, default - `admin`
+`UNA_ADMIN_EMAIL` - admin login email, default - `admin@example.com`
+`UNA_ADMIN_PWD` - admin password, default - `localhost`
+`UNA_KEY` - UNA key, key&secret can be generated on [una.io website](https://una.io/page/kands-manage)
+`UNA_SECRET` - UNA secret
+`UNA_VERSION` - particular UNA version to install, default - latest version
+`UNA_ZIP_DOWNLOAD_URL` - custom UNA download URL, in case you need to install modified version, optional
+`UNA_ZIP_FOLDER` - custom UNA folder in `UNA_ZIP_DOWNLOAD_URL` zip to be able to unpack, UNA is aleays installed in root folder 
+`UNA_NO_CRONTAB` - don't install crontab, in case of multiple instances, cron should be installed on one instance only, cron is installed by default

+ 78 - 0
docker-entrypoint.sh

@@ -0,0 +1,78 @@
+#!/bin/bash
+set -euox pipefail
+
+# TODO: escape vars
+# TODO: ability to restore from backup
+
+UNA_USER="www-una"
+
+VAR_DEF_DB_HOST="localhost"
+VAR_DEF_DB_PORT="3306"
+VAR_DEF_DB_USER="root"
+VAR_DEF_DB_PWD="root"
+VAR_DEF_HTTP_HOST="localhost"
+VAR_DEF_TITLE="UNA"
+VAR_DEF_USERNAME="admin"
+VAR_DEF_EMAIL="admin@example.com"
+
+VAR_DEF_VERSION="11.0.3"
+VAR_DEF_ZIP_DOWNLOAD_URL="http://ci.una.io/builds/UNA-v.${UNA_VERSION:-$VAR_DEF_VERSION}.zip"
+VAR_DEF_ZIP_FOLDER="UNA-v.${UNA_VERSION:-$VAR_DEF_VERSION}"
+
+# Unzip
+
+if [ ! -e "index.php" ] && [ ! -e "inc/version.inc.php" ]; then
+    su $UNA_USER -c "curl -fSL ${UNA_ZIP_DOWNLOAD_URL:-$VAR_DEF_ZIP_DOWNLOAD_URL} -o una.zip"
+    su $UNA_USER -c "unzip -o una.zip"
+    su $UNA_USER -c "rm una.zip"
+    su $UNA_USER -c "mv ${UNA_ZIP_FOLDER:-$VAR_DEF_ZIP_FOLDER}/* ."
+    su $UNA_USER -c "mv ${UNA_ZIP_FOLDER:-$VAR_DEF_ZIP_FOLDER}/.htaccess ."
+    su $UNA_USER -c "rm -rf ${UNA_ZIP_FOLDER:-$VAR_DEF_ZIP_FOLDER}"
+fi
+
+# Clean folders
+
+rm -rf cache/* cache_public/* tmp/*
+
+# Change permissions
+
+chmod +x plugins/ffmpeg/ffmpeg.exe
+find . -exec chown $UNA_USER:$UNA_USER {} \+
+
+# Install
+
+if [ -d "install" ] && [ ! -f "inc/header.inc.php" ]; then
+    su $UNA_USER -c "php ./install/cmd.php \
+        --db_host='${UNA_DB_HOST:-$VAR_DEF_DB_HOST}' \
+        --db_port='${UNA_DB_PORT:-$VAR_DEF_DB_PORT}' \
+        --db_sock='${UNA_DB_SOCK:-}' \
+        --db_name='${UNA_DB_NAME}' \
+        --db_user='${UNA_DB_USER:-$VAR_DEF_DB_USER}' \
+        --db_password='${UNA_DB_PWD:-$VAR_DEF_DB_PWD}' \
+        --server_http_host='${UNA_HTTP_HOST:-$VAR_DEF_HTTP_HOST}' \
+        --server_php_self='/install/index.php' \
+        --server_doc_root='/var/www/html/' \
+        --site_title='${UNA_SITE_TITLE:-$VAR_DEF_TITLE}' \
+        --site_email='${UNA_SITE_EMAIL:-$VAR_DEF_EMAIL}' \
+        --admin_username='${UNA_ADMIN_USERNAME:-$VAR_DEF_USERNAME}' \
+        --admin_email='${UNA_ADMIN_EMAIL:-$VAR_DEF_EMAIL}' \
+        --admin_password='${UNA_ADMIN_PWD}' \
+        --oauth_key='${UNA_KEY:-}' --oauth_secret='${UNA_SECRET:-}'"
+
+    rm -rf ./install
+fi
+
+# Crontab
+
+if [[ ! -v UNA_NO_CRONTAB ]]; then
+    echo "* * * * * /usr/local/bin/php -c /var/www /var/www/html/periodic/cron.php 2>&1 | sed -e \"s/\(.*\)/[\`date\`] \1/\" >>/var/www/cron.log" > /var/www/crontab
+    chown $UNA_USER:$UNA_USER /var/www/crontab
+    crontab -u $UNA_USER /var/www/crontab
+
+    rm -f /etc/cron.d/sendmail
+    /etc/init.d/cron start
+fi
+
+#
+
+exec "$@"