Skip to content

Deploying SciGateway

Louise Davies edited this page Oct 10, 2019 · 27 revisions

To deploy SciGateway itself on it's own is fairly simple - since it is purely html + javascript it can be served by any static server. Or, you could write your own server and run that as a service. Some information on how to do this generally are detailed on the ReactJS deployment documentation page: https://create-react-app.dev/docs/deployment.

Below I will describe how I set up SciGateway on the scigateway-preprod.esc.rl.ac.uk machine.

Server setup

1. Install node

(Instructions)

2. Install Apache:

yum install httpd

3. Open firewall ports

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
iptables-save > /etc/sysconfig/iptables

4. Add VirtualHost config to Apache:

/etc/httpd/conf.d/scigateway

<VirtualHost *:80>
  ServerName http://scigateway-preprod.esc.rl.ac.uk

  <LocationMatch "^/api/(.*)">
    ProxyPassMatch "http://scigateway-preprod.esc.rl.ac.uk:8000/api/$1"
  </LocationMatch> 

  <Directory "/var/www/html">
    RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [QSA,L]
  </Directory>
</VirtualHost>

This sets up Apache on port 80, it forwards any requests to /api to port 8000 (this is where we'll host an auth server), and rewrites all paths back to index.html as long as they don't correspond to a real file or directory (this allows for client side routing)

5. Start Apache

systemctl start httpd

Deploying SciGateway

On scigateway-preprod.esc.rl.ac.uk, the SciGateway repository is cloned and built by the ICAT glassfish user.

1. Build SciGateway

npm run build

This will build SciGateway in production mode. This will minimise the JavaScript and perform other performance improvements.

2. Copy build contents to Apache web root

cp build/* /var/www/html/

Deploying auth-server.js

In order for SciGateway to have login functionality, it needs to be able to contact an auth server. The Apache config is already proxying requests to /api to port 8000, so we just need to run our auth server. If you run

node server/auth-server.js

In the root of SciGateway then this should run the server and if you try logging in with SciGateway it should work. Now, we don't want to have to run this manually ourselves so we can create a systemd service file to run the auth server as a service.

Create /etc/systemd/system/scigateway-auth-test.service and paste the following contents:

[Unit]
Description=Default scigateway auth server
Documentation=https://github.com/ral-facilities/scigateway/wiki
After=network.target

[Service]
Type=simple
User=glassfish
ExecStart=/usr/bin/node /home/glassfish/scigateway/scigateway/server/auth-server.js
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

(this assumes that there is an unprivileged glassfish user that has cloned the SciGateway repo - as is used by the ICAT stack - you can change this to be any unprivileged user)

Clone this wiki locally