Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,72 @@ jobs:
- name: Run Prettier
run: npx prettier --check app/src/app

apache_deployment:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Define global variables
id: global_variables
run: |
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
sed -i 's/^BASIL_TESTING=.*/BASIL_TESTING=1/' deploy/apache/.env
sed -i 's/^BASIL_API_PORT=.*/BASIL_API_PORT=5005/' deploy/apache/.env
sed -i 's/^BASIL_APP_PORT=.*/BASIL_APP_PORT=9056/' deploy/apache/.env
sed -i 's/^BASIL_ADMIN_PASSWORD=.*/BASIL_ADMIN_PASSWORD=dummy_password/' deploy/apache/.env
sed -i 's/^BASIL_DB_PASSWORD=.*/BASIL_DB_PASSWORD=dbSecret123/' deploy/apache/.env
TEMPDIR=$(mktemp -d)
sed -i "s|^BASIL_DB_PASSWORD=.*|BASIL_DB_PASSWORD=${TEMPDIR}|" deploy/apache/.env

- name: Make deploy/apache/run.sh executable
run: chmod +x deploy/apache/run.sh

- name: Run the deployment
run: |
cd deploy/apache && sudo ./run.sh

- name: Test backend and frontend are up
run: |
echo "Test Api is running"
curl -vf http://localhost:5005/apis
curl -vf http://localhost:5005/libraries
curl -vf http://localhost:5005/version
echo "Test App is running"
curl -vf http://localhost:9056

- name: Install cypress-fail-fast plugin
run: npm install --save-dev cypress-fail-fast
working-directory: ./app

- name: Cypress E2E Testing Chrome
uses: cypress-io/github-action@v6
with:
browser: chrome
working-directory: ./app
spec: 'cypress/**/*.cy.js'
command: npx cypress run --browser chrome --spec cypress/**/login.cy.js --env failFast=true
env:
LIBGL_ALWAYS_SOFTWARE: 1

- name: Upload Cypress screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: |
app/cypress/screenshots
api/user-files
retention-days: 7

- name: Upload apache error log
uses: actions/upload-artifact@v4
if: failure()
with:
name: apache-error.log
path: /var/log/apache2/error.log

build_and_test:
runs-on: ubuntu-latest
steps:
Expand Down
13 changes: 13 additions & 0 deletions deploy/apache/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BASIL_SERVER_NAME=127.0.0.1 # Your.Host.IP.Num
BASIL_SERVER_ALIAS=127.0.0.1 # hostname.domain.local
[email protected]
BASIL_ADMIN_PASSWORD=my_secure_admin_password
BASIL_RESET_POSTGRES_CLUSTERS=1
BASIL_DB_PASSWORD=my_secure_db_password
BASIL_TESTING=0
BASIL_API_PORT=5000
BASIL_APP_PORT=9000
BASIL_TEST_RUNS_BASE_DIR=/var/basil/test-runs
BASIL_COMMITBEFORE=
BASIL_GITCLONE=1
BASIL_GITGOBACK=0
112 changes: 112 additions & 0 deletions deploy/apache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
### BASIL Apache deployment

This folder contains helper scripts to deploy BASIL (API + Frontend) behind Apache on a Debian/Ubuntu host.

Scripts expect configuration via a local `.env` file, then you run `run.sh` to provision PostgreSQL, build and configure the API (mod_wsgi) and the frontend under Apache.

---

### Prerequisites

- Run on a Debian/Ubuntu system with `systemd` and `apt`.
- A user with sudo privileges and outbound Internet access.
- Open TCP ports for the API and APP (defaults: 5000 and 9000).

The scripts will install required packages (Apache, PostgreSQL, Python, Node toolchain) if missing.

---

### Configure .env

It is sourced by bash, so stick to `KEY=VALUE` and use quotes if values contain spaces.

Required/commonly used variables:

- BASIL_SERVER_NAME: public hostname or IP used in Apache vhosts
- BASIL_SERVER_ALIAS: optional additional host alias
- BASIL_SERVER_ADMIN: admin email for Apache configs
- BASIL_API_PORT: API Apache vhost port (default 5000)
- BASIL_APP_PORT: Frontend Apache vhost port (default 9000)
- BASIL_ADMIN_PASSWORD: password of BASIL admin user created by default
- BASIL_DB_PASSWORD: PostgreSQL user password used during DB init
- BASIL_TESTING: 1 to use a `test` DB instead of `basil` (default 0)
- BASIL_TEST_RUNS_BASE_DIR: base dir for tmt test runs (default `/var/basil/test-runs`)
- BASIL_GITCLONE: 1 = force fresh clone to `/tmp/basil`, 0 = reuse if present (default 1)
- BASIL_GITGOBACK: number of commits to revert from HEAD (default 0)
- BASIL_COMMITBEFORE: ISO8601 date used only when `BASIL_GITGOBACK < 0` (e.g. `2025-01-01 00:00:00 +0000`)
- BASIL_RESET_POSTGRES_CLUSTERS: 1 to wipe/recreate all local Postgres clusters (DANGEROUS), -1 to skip (default)

Example `.env` you can copy and adjust:

```bash
# Apache vhost details
BASIL_SERVER_NAME="your.host.name"
BASIL_SERVER_ALIAS="your.host.alias"
BASIL_SERVER_ADMIN="[email protected]"

# Ports
BASIL_API_PORT=5000
BASIL_APP_PORT=9000

# BASIL runtime
BASIL_ADMIN_PASSWORD="ChangeMe_Strong_Admin_Password"
BASIL_TEST_RUNS_BASE_DIR="/var/basil/test-runs"
BASIL_TESTING=0

# Database
BASIL_DB_PASSWORD="ChangeMe_Strong_DB_Password"
BASIL_RESET_POSTGRES_CLUSTERS=-1

# Git checkout behavior for building
BASIL_GITCLONE=1
BASIL_GITGOBACK=0
# Only used if BASIL_GITGOBACK < 0
BASIL_COMMITBEFORE="2025-01-01 00:00:00 +0000"
```

Notes:
- Passwords are required: set both `BASIL_ADMIN_PASSWORD` and `BASIL_DB_PASSWORD`.
- Use quotes for values with special characters.

---

### Run the deployment

From this folder:

```bash
sudo ./run.sh
```

Why sudo? The scripts write under `/var/www`, `/etc/apache2`, manage services, and change ownership to `www-data`.

What `run.sh` does:
- Installs required packages via apt
- Initializes PostgreSQL (`init_postgresql.sh`)
- Builds and configures the API for Apache/mod_wsgi (`build_basil_api.sh`)
- Builds the frontend, configures Apache static vhost with React router rewrite (`build_basil_frontend.sh`)

Artifacts and logs in this folder:
- `init_postgresql.log`
- `build_basil_api.log`
- `build_basil_frontend.log`

---

### Verify

- API version endpoint: `http://<BASIL_SERVER_NAME>:<BASIL_API_PORT>/version`
- Frontend version: `http://<BASIL_SERVER_NAME>:<BASIL_APP_PORT>/version`

Both checks are executed automatically at the end of the respective scripts and reported in the logs.

---

### Troubleshooting

- Ports already in use: adjust `BASIL_API_PORT` / `BASIL_APP_PORT` in `.env` and re-run.
- Wrong hostname: update `BASIL_SERVER_NAME` (and optional alias) and re-run.
- PostgreSQL reset: set `BASIL_RESET_POSTGRES_CLUSTERS=1` only if you understand it will drop existing clusters.
- Rebuild from a clean checkout: set `BASIL_GITCLONE=1`.


Loading
Loading