From 2f2e2067ba074ca31466ffe70d5a718976f6809c Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 23 Apr 2018 22:13:07 +0200 Subject: [PATCH] Added an example to run the debug app with apache2+libfcgi inside a docker container. --- examples/docker/Dockerfile | 45 ++++++++++++++++++++++ examples/docker/README.md | 25 ++++++++++++ examples/docker/files/build_debug_fcgi | 25 ++++++++++++ examples/docker/files/html/.htaccess | 20 ++++++++++ examples/docker/files/html/index.html | 19 +++++++++ examples/docker/files/httpd.conf | 53 ++++++++++++++++++++++++++ 6 files changed, 187 insertions(+) create mode 100644 examples/docker/Dockerfile create mode 100644 examples/docker/README.md create mode 100644 examples/docker/files/build_debug_fcgi create mode 100644 examples/docker/files/html/.htaccess create mode 100644 examples/docker/files/html/index.html create mode 100644 examples/docker/files/httpd.conf diff --git a/examples/docker/Dockerfile b/examples/docker/Dockerfile new file mode 100644 index 00000000..0f0bee95 --- /dev/null +++ b/examples/docker/Dockerfile @@ -0,0 +1,45 @@ +FROM debian +#ubuntu:xenial +MAINTAINER Jocelyn Fiat +LABEL description="EiffelWeb debug example hosted using apache2+libfcgi" + +RUN apt-get update \ + && apt-get -y install curl bzip2 make gcc \ + && apt-get -y install apache2 libapache2-mod-fcgid libfcgi-dev \ + && apt-get -y install tmux git-all vim \ + && rm -rf /var/lib/apt/lists/* + +EXPOSE 80 + +RUN a2enmod rewrite suexec include fcgid +RUN service apache2 restart + +RUN export uid=1000 gid=1000 && \ + mkdir -p /home/eifweb && \ + echo "eifweb:x:${uid}:${gid}:eifweb,,,:/home/eifweb:/bin/bash" >> /etc/passwd && \ + echo "eifweb:x:${uid}:" >> /etc/group && \ + chown ${uid}:${gid} -R /home/eifweb + +USER eifweb +ENV HOME /home/eifweb +ENV WEBDIR /home/eifweb/www +WORKDIR $HOME + +# Create expected folders +RUN mkdir $WEBDIR + +#Build the debug EiffelWeb example and copy the executable to $HOME/ +COPY files/build_debug_fcgi $HOME/build_debug_fcgi +USER root +RUN chown eifweb:eifweb $HOME/build_debug_fcgi && chmod 700 $HOME/build_debug_fcgi +USER eifweb +RUN $HOME/build_debug_fcgi $HOME/www + +USER root +COPY ./files/httpd.conf /etc/apache2/sites-enabled/000-default.conf +COPY ./files/html/.htaccess $WEBDIR/html/.htaccess +COPY ./files/html/index.html $WEBDIR/html/index.html +RUN echo > $WEBDIR/html/service.ews +RUN chown www-data:www-data -R $WEBDIR && chmod 400 $WEBDIR/html/* + +RUN service apache2 restart diff --git a/examples/docker/README.md b/examples/docker/README.md new file mode 100644 index 00000000..c83bdd0c --- /dev/null +++ b/examples/docker/README.md @@ -0,0 +1,25 @@ +Docker container for EiffelWeb debug example with apache2+libfcgi. +================================================================== + +This example demonstrates the use of EiffelWeb with Apache2, using the libfcgi connector. +For that, it is using the Docker solution to show the compilation and configuration steps. + +To build the docker image: + +``` + docker build -t local/ewf-debug-httpd . +``` + +To run the docker image in a self-destroyed container: +``` + docker run --rm -it -p 8080:80 --name my-ewf-debug local/ewf-debug-httpd +``` + +Notes: + - `--rm` : to remove the container after the execution + - `-p 8080:80` : to map internal listening port 80 to localhost port 8080. + - on Linux, you may need to use `sudo` to be able to use `docker` + - depending on the docker installation, you may need to add an extra `-e ISE_PLATFORM=linux-x86` to force execution in 32bits. + - This docker example is simple on purpose. For production it should be improved and optimized to keep the image smaller and more customizable. + - For more advanced Docker usage, please refer to official https://www.docker.com/ website. + diff --git a/examples/docker/files/build_debug_fcgi b/examples/docker/files/build_debug_fcgi new file mode 100644 index 00000000..bfbca07f --- /dev/null +++ b/examples/docker/files/build_debug_fcgi @@ -0,0 +1,25 @@ +#!/bin/bash + +web_dir=$1 + +mkdir $web_dir/bin +mkdir $web_dir/html + +# Install latest EiffelStudio suite. +curl -sSL https://www.eiffel.org/setup/install.sh > install_eiffel.sh \ + && bash ./install_eiffel.sh latest > $HOME/eiffel.rc + +# Setup Eiffel environment +source $HOME/eiffel.rc + +# Get source code +git clone https://github.com/EiffelWebFramework/EWF.git $web_dir/src + +# Build executable +eiffel build -v --target debug_libfcgi $web_dir/src/examples/debug/debug.ecf $web_dir/bin/debug.fcgi + +# Clean files +rm -rf $ISE_EIFFEL +rm -rf $web_dir/src + +exit $? diff --git a/examples/docker/files/html/.htaccess b/examples/docker/files/html/.htaccess new file mode 100644 index 00000000..18cbfcac --- /dev/null +++ b/examples/docker/files/html/.htaccess @@ -0,0 +1,20 @@ + +AddHandler fcgid-script .ews +FcgidWrapper /home/eifweb/www/bin/debug.fcgi .ews + + +Options +ExecCGI +Includes +FollowSymLinks + + +RewriteEngine on + +#RewriteRule ^.*$ maintenance.html [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^$ service.ews/ + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_URI} !=/favicon.ico +RewriteRule ^(.*)$ service.ews/$1 [C] + +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] + diff --git a/examples/docker/files/html/index.html b/examples/docker/files/html/index.html new file mode 100644 index 00000000..d5519b8f --- /dev/null +++ b/examples/docker/files/html/index.html @@ -0,0 +1,19 @@ + + + + EiffelWeb running on Apache2+libfcgi + + + EiffelWeb debug example hosted on apache2+libfcgi . + + + diff --git a/examples/docker/files/httpd.conf b/examples/docker/files/httpd.conf new file mode 100644 index 00000000..9eb29022 --- /dev/null +++ b/examples/docker/files/httpd.conf @@ -0,0 +1,53 @@ + + FcgidIdleTimeout 60 + FcgidBusyScanInterval 120 + FcgidProcessLifeTime 1800 + #7200 + FcgidMaxProcesses 10 + FcgidMaxProcessesPerClass 100 + FcgidMinProcessesPerClass 100 + FcgidConnectTimeout 8 + FcgidIOTimeout 3000 + FcgidBusyTimeout 300 + FcgidPassHeader Authorization + FcgidMaxRequestLen 10000000 + FcgidMaxRequestsPerProcess 100 + + + + # The ServerName directive sets the request scheme, hostname and port that + # the server uses to identify itself. This is used when creating + # redirection URLs. In the context of virtual hosts, the ServerName + # specifies what hostname must appear in the request's Host: header to + # match this virtual host. For the default virtual host (this file) this + # value is not decisive as it is used as a last resort host regardless. + # However, you must set it for any further virtual host explicitly. + #ServerName www.example.com + + ServerAdmin webmaster@localhost + DocumentRoot /home/eifweb/www/html + + + Options Indexes FollowSymLinks MultiViews + AllowOverride All + Require all granted + + + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, + # error, crit, alert, emerg. + # It is also possible to configure the loglevel for particular + # modules, e.g. + #LogLevel info ssl:warn + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # For most configuration files from conf-available/, which are + # enabled or disabled at a global level, it is possible to + # include a line for only one particular virtual host. For example the + # following line enables the CGI configuration for this host only + # after it has been globally disabled with "a2disconf". + #Include conf-available/serve-cgi-bin.conf + + +