1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-11 02:24:00 +02:00

Merge pull request #60 from digitalmobil/docker/add-config-env-vars

Docker - add config env vars
This commit is contained in:
Marco Dickert
2017-07-26 16:34:05 +02:00
committed by GitHub
5 changed files with 135 additions and 35 deletions

View File

@@ -1,3 +1,3 @@
*
!ifm.php
!apache2-foreground
!docker-startup.sh

View File

@@ -1,6 +1,22 @@
FROM alpine:3.5
ENV PHP_INI_DIR /etc/php5
# general settings
ENV IFM_AUTH=0 \
IFM_AUTH_SOURCE='inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC' \
IFM_ROOT_DIR="" \
IFM_TMP_DIR="" \
IFM_DEFAULTTIMEZONE="Europe/Berlin"
# api controls
ENV IFM_API_AJAXREQUEST=1 IFM_API_CHMOD=1 IFM_API_COPYMOVE=1 \
IFM_API_CREATEDIR=1 IFM_API_CREATEFILE=1 IFM_API_EDIT=1 \
IFM_API_DELETE=1 IFM_API_DOWNLOAD=1 IFM_API_EXTRACT=1 \
IFM_API_UPLOAD=1 IFM_API_REMOTEUPLOAD=1 IFM_API_RENAME=1 \
IFM_API_ZIPNLOAD=1
# gui controls
ENV IFM_GUI_SHOWLASTMODIFIED=0 IFM_GUI_SHOWFILESIZE=1 IFM_GUI_SHOWOWNER=1 \
IFM_GUI_SHOWGROUP=1 IFM_GUI_SHOWPERMISSIONS=2 IFM_GUI_SHOWHTDOCS=1 \
IFM_GUI_SHOWHIDDENFILES=1 IFM_GUI_SHOWPATH=0
# ensure apache user exists with the desired uid
RUN set -x \
@@ -21,7 +37,7 @@ RUN set -xe; \
xz
RUN set -xe; \
apk add --no-cache --virtual .wordpress-runtime-deps \
apk add --no-cache --virtual .ifm-runtime-deps \
apache2 \
apache2-utils \
php5-apache2 \
@@ -68,21 +84,21 @@ RUN mkdir -p /run/apache2 \
RUN { \
echo 'date.timezone = "Europe/Berlin"'; \
echo 'zlib.output_compression = On'; \
echo 'zlib.output_compression_level = 6'; \
echo 'memory_limit = 256M'; \
echo 'max_execution_time = 120'; \
echo 'upload_max_filesize = 512M'; \
echo 'post_max_size = 512M'; \
echo 'zlib.output_compression_level = 6'; \
echo 'memory_limit = 256M'; \
echo 'max_execution_time = 120'; \
echo 'upload_max_filesize = 512M'; \
echo 'post_max_size = 512M'; \
echo 'log_errors = On'; \
echo 'error_log = "/var/www/php.log"'; \
} > $PHP_INI_DIR/conf.d/ZZ_ifm.ini
COPY apache2-foreground /usr/local/bin/
COPY docker-startup.sh /usr/local/bin/
COPY ifm.php /var/www/html/index.php
WORKDIR /var/www
EXPOSE 80
CMD ["apache2-foreground"]
CMD ["docker-startup.sh"]

View File

@@ -27,23 +27,6 @@ The IFM uses the following resources:
## installation
Just copy the ifm.php to your webspace - thats all :)
## docker
The docker image is based on alpine 3.5 for a small image footprint, with necessary apache, php and supporting packages installed and exposes port 80.
### build image
Run the following command from the top source dir:
`docker build -t ifm .`
### run image
The script is installed inside the image at `/var/www/html/index.php`. Its default configuration is unchanged, thus it will display the contents of the document root (`/var/www/html`).
Here is an example of how to start up a container with this image:
`docker run --rm -i -p "9090:80" -v "/data:/var/www/html/data" ifm`
## key bindings
* <kbd>e</kbd> - edit / extract current file
* <kbd>h</kbd><kbd>j</kbd><kbd>k</kbd><kbd>l</kbd> - vim-style navigation (alternative to arrow keys)
@@ -76,6 +59,56 @@ The file should contain ONLY ONE LINE:
```
The password hash has to be a hash generated by PHPs `password_hash()` function. The default credentials are "admin:admin".
## docker
The docker image is based on alpine 3.5 for a small image footprint, with necessary apache, php and supporting packages installed and exposes port 80
### build image
Run the following command from the top source dir:
`docker build -t ifm .`
### run image
The script is installed inside the image at `/var/www/html/index.php`. Its default configuration is unchanged, thus it will display the contents of the document root (`/var/www/html`)
Here is an example of how to start up a container with this image:
`docker run --rm -it -e IFM_AUTH=1 -p "9090:80" -v "/data:/var/www/html/data" ifm`
The script's configuration can be changed by adjusting the corresponding docker environment variables
listed below:
| PHP config value | Docker env var |
| ------------------ | -------------------------- |
| `auth` | `IFM_AUTH` |
| `auth_source` | `IFM_AUTH_SOURCE` |
| `root_dir` | `IFM_ROOT_DIR` |
| `tmp_dir` | `IFM_TMP_DIR` |
| `defaulttimezone` | `IFM_DEFAULTTIMEZONE` |
| `ajaxrequest` | `IFM_API_AJAXREQUEST` |
| `chmod` | `IFM_API_CHMOD` |
| `copymove` | `IFM_API_COPYMOVE` |
| `createdir` | `IFM_API_CREATEDIR` |
| `createfile` | `IFM_API_CREATEFILE` |
| `edit` | `IFM_API_EDIT` |
| `delete` | `IFM_API_DELETE` |
| `download` | `IFM_API_DOWNLOAD` |
| `extract` | `IFM_API_EXTRACT` |
| `upload` | `IFM_API_UPLOAD` |
| `remoteupload` | `IFM_API_REMOTEUPLOAD` |
| `rename` | `IFM_API_RENAME` |
| `zipnload` | `IFM_API_ZIPNLOAD` |
| `showlastmodified` | `IFM_GUI_SHOWLASTMODIFIED` |
| `showfilesize` | `IFM_GUI_SHOWFILESIZE` |
| `showowner` | `IFM_GUI_SHOWOWNER` |
| `showgroup` | `IFM_GUI_SHOWGROUP` |
| `showpermissions` | `IFM_GUI_SHOWPERMISSIONS` |
| `showhtdocs` | `IFM_GUI_SHOWHTDOCS` |
| `showhiddenfiles` | `IFM_GUI_SHOWHIDDENFILES` |
| `showpath` | `IFM_GUI_SHOWPATH` |
## screenshots
<a href="https://misterunknown.de/static/ifm_screenshot_desktop_filelist.png"><img src="https://misterunknown.de/static/ifm_screenshot_desktop_filelist.png" height="300px"></a>
<a href="https://misterunknown.de/static/ifm_screenshot_mobile_filelist.png"><img src="https://misterunknown.de/static/ifm_screenshot_mobile_filelist.png" height="300px"></a>

View File

@@ -1,8 +0,0 @@
#!/bin/sh
set -e
# Apache gets grumpy about PID files pre-existing
rm -f /usr/local/apache2/logs/httpd.pid
exec httpd -DFOREGROUND

59
docker-startup.sh Executable file
View File

@@ -0,0 +1,59 @@
#!/bin/sh
set -e
################################################################################
# Adjust ifm configuration according to docker env vars.
# Defaults should match those in ifm.php. See Dockerfile for details.
# see http://stackoverflow.com/a/2705678/433558
sed_escape_lhs() {
echo "$@" | sed 's/[]\/$*.^|[]/\\&/g'
}
sed_escape_rhs() {
echo "$@" | sed 's/[\/&]/\\&/g'
}
set_config() {
key=$(sed_escape_lhs "$1")
value=$(sed_escape_rhs "$2" )
sed -ri -e "s/\"$key\"[[:space:]]*=>.*$/\"$key\" => $value,/" /var/www/html/index.php
}
# general settings
set_config "auth" "$IFM_AUTH"
set_config "auth_source" "'$IFM_AUTH_SOURCE'"
set_config "root_dir" "'$IFM_ROOT_DIR'"
set_config "tmp_dir" "'$IFM_TMP_DIR'"
set_config "defaulttimezone" "'$IFM_DEFAULTTIMEZONE'"
# api controls
set_config "ajaxrequest" "$IFM_API_AJAXREQUEST"
set_config "chmod" "$IFM_API_CHMOD"
set_config "copymove" "$IFM_API_COPYMOVE"
set_config "createdir" "$IFM_API_CREATEDIR"
set_config "createfile" "$IFM_API_CREATEFILE"
set_config "edit" "$IFM_API_EDIT"
set_config "delete" "$IFM_API_DELETE"
set_config "download" "$IFM_API_DOWNLOAD"
set_config "extract" "$IFM_API_EXTRACT"
set_config "upload" "$IFM_API_UPLOAD"
set_config "remoteupload" "$IFM_API_REMOTEUPLOAD"
set_config "rename" "$IFM_API_RENAME"
set_config "zipnload" "$IFM_API_ZIPNLOAD"
# gui controls
set_config "showlastmodified" "$IFM_GUI_SHOWLASTMODIFIED"
set_config "showfilesize" "$IFM_GUI_SHOWFILESIZE"
set_config "showowner" "$IFM_GUI_SHOWOWNER"
set_config "showgroup" "$IFM_GUI_SHOWGROUP"
set_config "showpermissions" "$IFM_GUI_SHOWPERMISSIONS"
set_config "showhtdocs" "$IFM_GUI_SHOWHTDOCS"
set_config "showhiddenfiles" "$IFM_GUI_SHOWHIDDENFILES"
set_config "showpath" "$IFM_GUI_SHOWPATH"
################################################################################
# Apache gets grumpy about PID files pre-existing
rm -f /usr/local/apache2/logs/httpd.pid
# Start up apache
exec httpd -DFOREGROUND