diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index baf7e593fa78211d98f1d2628effe7f48e11f380..539821c15c79678fefe42061c2075951151f9719 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -15,6 +15,17 @@ services: #volumes: # - ./services/api-gateway/opt/esap-api-gateway:/opt/opt/esap-api-gateway + + gui: + image: "esap/gui" + container_name: gui + hostname: gui + ports: + - "8001:8001" + #volumes: + # - ./services/gui/opt/esap-gui:/opt/opt/esap-gui + + proxy: image: "esap/proxy" container_name: proxy diff --git a/esap/build b/esap/build index 62cd0bd1d339c9926445b865f72f250b4b6e9ecb..fe4811953b9995eadaabc809dbd438beefa1bfce 100755 --- a/esap/build +++ b/esap/build @@ -31,6 +31,7 @@ if [[ "x$SERVICE" == "x" ]] ; then # Build all services $BUILD_COMMAND services/api-gateway -t esap/api-gateway $BUILD_COMMAND services/proxy -t esap/proxy + $BUILD_COMMAND services/gui -t esap/gui else diff --git a/services/gui/Dockerfile b/services/gui/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..cbf78c3180591a38ea4b06c9bfdc7716dda14c44 --- /dev/null +++ b/services/gui/Dockerfile @@ -0,0 +1,71 @@ +FROM ubuntu:20.04 +MAINTAINER Stefano Alberto Russo <stefano.russo@gmail.com> + +#---------------------- +# Basics +#---------------------- + +# Set non-interactive +ENV DEBIAN_FRONTEND noninteractive + +# Update +RUN apt-get update + +# Utilities +RUN apt-get install -y nano telnet unzip wget openssh-server sudo curl + +# Devel +RUN apt-get install -y build-essential python-dev git-core + +# Node & nginx +RUN apt-get install -y nodejs npm nginx + + +#------------------------ +# Esap user +#------------------------ + +# Add group. We chose GID 65527 to try avoiding conflicts. +RUN groupadd -g 65527 esap + +# Add user. We chose UID 65527 to try avoiding conflicts. +RUN useradd esap -d /esap -u 65527 -g 65527 -m -s /bin/bash + +# Add esap user to sudoers +RUN adduser esap sudo + +# No pass sudo (for everyone, actually) +COPY sudoers /etc/sudoers + + +#------------------------ +# Code +#------------------------ + +RUN cd /opt && git clone https://git.astron.nl/astron-sdc/esap-gui.git +RUN cd /opt/esap-gui && git pull && git checkout 0be8125b478007c75b13002d4e5273af7e14c057 +RUN cd /opt/esap-gui && npm install +RUN cd /opt/esap-gui && npm run build + +# Link static files +RUN ln -s /opt/esap-gui/build /var/www/html/esap-gui +RUN ln -s /opt/esap-gui/build/static/ /var/www/html/static + +# Change nginx conf to listen on 8001 +COPY sites_enabled_default /etc/nginx/sites-enabled/default + +# Add redirect index +COPY index.html /var/www/html/index.html + + + +#---------------------- +# Entrypoint +#---------------------- + +COPY run_gui.sh /run_gui.sh +COPY entrypoint.sh /entrypoint.sh +RUN chmod 755 /entrypoint.sh /run_gui.sh + +USER esap +ENTRYPOINT ["/entrypoint.sh"] diff --git a/services/gui/entrypoint.sh b/services/gui/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..ecd93097149b39cc6265a059f345839c5bed8109 --- /dev/null +++ b/services/gui/entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Exit on any error. +set -e + +echo "" +echo "[INFO] Executing entrypoint..." + +#--------------------- +# Save env +#--------------------- +echo "[INFO] Dumping env" + +# Save env vars for later usage (e.g. docker exec) + +env | \ +while read env_var; do + if [[ $env_var == HOME\=* ]]; then + : # Skip HOME var + elif [[ $env_var == PWD\=* ]]; then + : # Skip PWD var + else + echo "export $env_var" >> /tmp/env.sh + fi +done + +#--------------------- +# Entrypoint command +#--------------------- + + +if [[ "x$@" == "x" ]] ; then + ENTRYPOINT_COMMAND="/run_gui.sh" +else + ENTRYPOINT_COMMAND=$@ +fi + +echo -n "[INFO] Executing Docker entrypoint command: " +echo $ENTRYPOINT_COMMAND +exec "$ENTRYPOINT_COMMAND" diff --git a/services/gui/index.html b/services/gui/index.html new file mode 100644 index 0000000000000000000000000000000000000000..4f0853f308c0e3620da3f68d8b6a528025fcbecc --- /dev/null +++ b/services/gui/index.html @@ -0,0 +1,6 @@ + +<html> +<head> +<meta http-equiv="refresh" content="0; URL=/esap-gui" /> +</head> +</html> \ No newline at end of file diff --git a/services/gui/run_gui.sh b/services/gui/run_gui.sh new file mode 100644 index 0000000000000000000000000000000000000000..fa5872e2ade8793932afd9ff3904b52e884d7d64 --- /dev/null +++ b/services/gui/run_gui.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +DATE=$(date) + +echo "" +echo "===================================================" +echo "Starting GUI @ $DATE" +echo "===================================================" +echo "" + + +sudo nginx -g 'daemon off;' + diff --git a/services/gui/sites_enabled_default b/services/gui/sites_enabled_default new file mode 100644 index 0000000000000000000000000000000000000000..ec3b3c55e55297b7a4b2fa2f6b38e2f37ec8ac98 --- /dev/null +++ b/services/gui/sites_enabled_default @@ -0,0 +1,91 @@ +## +# You should look at the following URL's in order to grasp a solid understanding +# of Nginx configuration files in order to fully unleash the power of Nginx. +# https://www.nginx.com/resources/wiki/start/ +# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ +# https://wiki.debian.org/Nginx/DirectoryStructure +# +# In most cases, administrators will remove this file from sites-enabled/ and +# leave it as reference inside of sites-available where it will continue to be +# updated by the nginx packaging team. +# +# This file will automatically load configuration files provided by other +# applications, such as Drupal or Wordpress. These applications will be made +# available underneath a path with that package name, such as /drupal8. +# +# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. +## + +# Default server configuration +# +server { + listen 8001 default_server; + listen [::]:8001 default_server; + + # SSL configuration + # + # listen 443 ssl default_server; + # listen [::]:443 ssl default_server; + # + # Note: You should disable gzip for SSL traffic. + # See: https://bugs.debian.org/773332 + # + # Read up on ssl_ciphers to ensure a secure configuration. + # See: https://bugs.debian.org/765782 + # + # Self signed certs generated by the ssl-cert package + # Don't use them in a production server! + # + # include snippets/snakeoil.conf; + + root /var/www/html; + + # Add index.php to the list if you are using PHP + index index.html index.htm index.nginx-debian.html; + + server_name _; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + # pass PHP scripts to FastCGI server + # + #location ~ \.php$ { + # include snippets/fastcgi-php.conf; + # + # # With php-fpm (or other unix sockets): + # fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; + # # With php-cgi (or other tcp sockets): + # fastcgi_pass 127.0.0.1:9000; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} + + +# Virtual Host configuration for example.com +# +# You can move that to a different file under sites-available/ and symlink that +# to sites-enabled/ to enable it. +# +#server { +# listen 80; +# listen [::]:80; +# +# server_name example.com; +# +# root /var/www/example.com; +# index index.html; +# +# location / { +# try_files $uri $uri/ =404; +# } +#} diff --git a/services/proxy/000-default.conf b/services/proxy/000-default.conf index bcddcb589abf8e13f1eaae3814cd05ef48c2f743..f282240bbb94084241df1ae30de15d92e821db6a 100644 --- a/services/proxy/000-default.conf +++ b/services/proxy/000-default.conf @@ -32,16 +32,22 @@ # TODO: Re-evaluate, this is somehow a bad idea, as # 1) dev env is different than staging/production, and - # 2) other roules in 001-proxy.conf are never reached + # 2) other rules in 001-proxy.conf are never reached RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} !=localhost RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} + + # ESAP API Gateway + ProxyPass /esap-api http://api-gateway:8000/esap-api + ProxyPassReverse /esap-api http://api-gateway:8000/esap-api + + # ESAP GUI + ProxyPass / http://gui:8001/ + ProxyPassReverse / http://gui:8001/ + - ProxyPass / http://api-gateway:8000/ - ProxyPassReverse / http://api-gateway:8000/ - </VirtualHost> diff --git a/services/proxy/default-ssl.conf b/services/proxy/default-ssl.conf index 66b2f9b81bc17b53ba84dc47818bf2b4dd7c7f22..658fa10b85b3aef9ceac1317d7b20a75d05fd28c 100644 --- a/services/proxy/default-ssl.conf +++ b/services/proxy/default-ssl.conf @@ -3,9 +3,14 @@ <VirtualHost _default_:443> ServerAdmin webmaster@esap - ProxyPass / http://api-gateway:8000/ - ProxyPassReverse / http://api-gateway:8000/ - + # ESAP API Gateway + ProxyPass /esap-api http://api-gateway:8000/esap-api + ProxyPassReverse /esap-api http://api-gateway:8000/esap-api + + # ESAP GUI + ProxyPass / http://gui:8001/ + ProxyPassReverse / http://gui:8001/ + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular diff --git a/services/proxy/run_Apache.sh b/services/proxy/run_Apache.sh index 8febb11e076285a0b3e2a46e93a37c719f471197..acb336d3f9226fdf631de11cb70d85b9621b7983 100644 --- a/services/proxy/run_Apache.sh +++ b/services/proxy/run_Apache.sh @@ -1,11 +1,7 @@ #!/bin/bash # Source env -source /env.sh +source /tmp/env.sh # Exec Apache in foreground exec /usr/sbin/apache2ctl -DFOREGROUND - -# Or just use in supervisord: -#/bin/bash -c "source /etc/apache2/envvars && source /env.sh && exec /usr/sbin/apache2 -DFOREGROUND" -