# WebMo docker installation

This project builds webmo in a container for deployment into
the kubernetes environment.

> [!WARNING]
> **OSC staff members** should commit to the original repository which is on UCR at https://code.osu.edu/osc-web-services/osc/webmo. This is a public copy of that repository that cannot be open sourced.

## Installing

The webmo installation is seperated by what's in the container
and what's on the host file systems.  When the container builds
it adds all the source into the container so that it can serve
webpages.

However, installers will need to install the same souce code
on a host filesystem so that when webmo (the web application) submits
jobs the source files are available to that job.  the host filesystem
will also contain a `user_data` directory that webmo (the web application)
writes to and updates as it submits jobs.

### Installing on the host

All source files and `user_data` directories are on the `webmo` user's
`$HOME` directory. All members of the `wiagstf` unix group should be able
to `sudo su - webmo` or `sudo -i -u webmo /bin/bash` depending on the system.

To install updates to the host file systems, do the following:

1. Change into the `webmo` user as described above.

    You can do this on web08 or any login node.
2. `cd ~/k8s_webmo`

    This directory should already be populated with this git repository. You
    can issue a `git status` to confirm.

3. `git pull`

    Pull your updates to this repository.

4. `./install.rb`

    **Just issuing this command is not enough**. If `WEBMO_ENVIRONMENT` is not set,
    you'll need to set it. If you're updating all 3 environments, update dev & test
    first and login to test to see the results. After which you can install to
    production.

    If `WEBMO_LICENSE` is not set you should issue `source .webmo.info`. This file
    should already exist for the `webmo` user and be populated correctly.

## building the image locally

Should you need to build the image locally to verify this or that
use `build.sh` to do so. Note that t

**Pre-requisites**

* This requires the `WEBMO_LICENSE` environment variable set to the
  license you want use.
* This also requires you to have the WebMO source code `.tar.gz` file
  located in this directory. The source code will *never* be commited
  to this repository, so go download the `.tar.gz` for the webmo version
  you want to build now.

### .webmo.info

The build script below will source a `.webmo.info` file in this directory
if it exists. It is a part of the .gitignore list because it holds
sensitive information. Specifically `WEBMO_LICENSE`, but should also
hold `WEBMO_VERSION` so that you don't have to export these variables.

This file should never be commited as it should hold license information
that is sensitive.

```
./build.sh
```

### webmo built packages

You may notice that some libraries webmo uses, we ourselves built.
Namely `mopac` which resides in the `webmo` users HOME directory
(instead of system installed in `/usr/local/` ).

Source files for any of these packages should be in `~webmo/src`.

#### building mopac

To build mopac just clone the source and use `cmake` to build it.
Here are a few things to keep in mind.

* Make sure you're building on the same target cluster it'll run on.
  Currently webmo jobs run on Owens, so this means you'll need to build
  the mopac binaries on Owens.
* When building, you may have to run tests off due to python errors. That's
  OK just use the `-DTESTS=OFF` flag.
* CMake uses the environment flag -DCMAKE_INSTALL_PREFIX if you're looking
  to `make install` with a prefix. (This is equivalent to the 
  `./configure --prefix=/some/location` if you're familiar with configure or autoconf
  scripts.)

Here's an example command that was used to build 22.0.6.

```
cmake -DTESTS=OFF -DCMAKE_INSTALL_PREFIX="$HOME/webmo-packages/mopac/22.0.6" ..
```

##### mopac binaries

Mopac binaries need an extra `LD_LIBRARY_PATH` to work correctly.
However, there's no way to specify such an environment variable in
WebMo.

So we have to provide wrappers for these binaries that set the correct
`LD_LIBRARY_PATH`.

You should have binaries made in the `bin` directory. Now you need to:

* make a `real` directory in the `bin` directory.
* move all binaries to the `real` subdirectory
* add this file as a `mopac_wrapper`

```bash
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
LIB_DIR=$(cd $SCRIPT_DIR/../lib64 && pwd)

REAL_DIR="$SCRIPT_DIR/real"
COMMAND=$(basename $0)

LD_LIBRARY_PATH="$LIB_DIR:$LD_LIBRARY_PATH"

$REAL_DIR/$COMMAND $@
```

* create symlinks for all the binaries in the `real` directory to this wrapper file.