Skip to content

Commit e2b9e54

Browse files
pellecchialuigiLuigi Pellecchia
andauthored
Update apache deployment scripts (#208)
* Update apache deployment scripts Signed-off-by: Luigi Pellecchia <[email protected]> * Add BASIL_TEST_RUNS_BASE_DIR to .env in deploy apache Signed-off-by: Luigi Pellecchia <[email protected]> * Update build.yaml Add a stage to test the apache deployment scripts * Update build.yaml change sed separator when using a directory * Update build.yaml change run.sh script path with sudo to use the current dir * Update build.yaml Upload apache2 error log in case of failure * Update init_postgresql.sh support BASIL_TESTING to create the test database instead of the basil one * Add README for deploy apache Signed-off-by: Luigi Pellecchia <[email protected]> --------- Signed-off-by: Luigi Pellecchia <[email protected]> Signed-off-by: Luigi Pellecchia <[email protected]> Co-authored-by: Luigi Pellecchia <[email protected]>
1 parent dd10d8f commit e2b9e54

File tree

8 files changed

+628
-321
lines changed

8 files changed

+628
-321
lines changed

.github/workflows/build.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,72 @@ jobs:
4242
- name: Run Prettier
4343
run: npx prettier --check app/src/app
4444

45+
apache_deployment:
46+
runs-on: ubuntu-latest
47+
steps:
48+
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Define global variables
53+
id: global_variables
54+
run: |
55+
echo "BRANCH_NAME=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
56+
sed -i 's/^BASIL_TESTING=.*/BASIL_TESTING=1/' deploy/apache/.env
57+
sed -i 's/^BASIL_API_PORT=.*/BASIL_API_PORT=5005/' deploy/apache/.env
58+
sed -i 's/^BASIL_APP_PORT=.*/BASIL_APP_PORT=9056/' deploy/apache/.env
59+
sed -i 's/^BASIL_ADMIN_PASSWORD=.*/BASIL_ADMIN_PASSWORD=dummy_password/' deploy/apache/.env
60+
sed -i 's/^BASIL_DB_PASSWORD=.*/BASIL_DB_PASSWORD=dbSecret123/' deploy/apache/.env
61+
TEMPDIR=$(mktemp -d)
62+
sed -i "s|^BASIL_DB_PASSWORD=.*|BASIL_DB_PASSWORD=${TEMPDIR}|" deploy/apache/.env
63+
64+
- name: Make deploy/apache/run.sh executable
65+
run: chmod +x deploy/apache/run.sh
66+
67+
- name: Run the deployment
68+
run: |
69+
cd deploy/apache && sudo ./run.sh
70+
71+
- name: Test backend and frontend are up
72+
run: |
73+
echo "Test Api is running"
74+
curl -vf http://localhost:5005/apis
75+
curl -vf http://localhost:5005/libraries
76+
curl -vf http://localhost:5005/version
77+
echo "Test App is running"
78+
curl -vf http://localhost:9056
79+
80+
- name: Install cypress-fail-fast plugin
81+
run: npm install --save-dev cypress-fail-fast
82+
working-directory: ./app
83+
84+
- name: Cypress E2E Testing Chrome
85+
uses: cypress-io/github-action@v6
86+
with:
87+
browser: chrome
88+
working-directory: ./app
89+
spec: 'cypress/**/*.cy.js'
90+
command: npx cypress run --browser chrome --spec cypress/**/login.cy.js --env failFast=true
91+
env:
92+
LIBGL_ALWAYS_SOFTWARE: 1
93+
94+
- name: Upload Cypress screenshots
95+
uses: actions/upload-artifact@v4
96+
if: failure()
97+
with:
98+
name: cypress-screenshots
99+
path: |
100+
app/cypress/screenshots
101+
api/user-files
102+
retention-days: 7
103+
104+
- name: Upload apache error log
105+
uses: actions/upload-artifact@v4
106+
if: failure()
107+
with:
108+
name: apache-error.log
109+
path: /var/log/apache2/error.log
110+
45111
build_and_test:
46112
runs-on: ubuntu-latest
47113
steps:

deploy/apache/.env

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
BASIL_SERVER_NAME=127.0.0.1 # Your.Host.IP.Num
2+
BASIL_SERVER_ALIAS=127.0.0.1 # hostname.domain.local
3+
BASIL_SERVER_ADMIN=[email protected]
4+
BASIL_ADMIN_PASSWORD=my_secure_admin_password
5+
BASIL_RESET_POSTGRES_CLUSTERS=1
6+
BASIL_DB_PASSWORD=my_secure_db_password
7+
BASIL_TESTING=0
8+
BASIL_API_PORT=5000
9+
BASIL_APP_PORT=9000
10+
BASIL_TEST_RUNS_BASE_DIR=/var/basil/test-runs
11+
BASIL_COMMITBEFORE=
12+
BASIL_GITCLONE=1
13+
BASIL_GITGOBACK=0

deploy/apache/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
### BASIL Apache deployment
2+
3+
This folder contains helper scripts to deploy BASIL (API + Frontend) behind Apache on a Debian/Ubuntu host.
4+
5+
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.
6+
7+
---
8+
9+
### Prerequisites
10+
11+
- Run on a Debian/Ubuntu system with `systemd` and `apt`.
12+
- A user with sudo privileges and outbound Internet access.
13+
- Open TCP ports for the API and APP (defaults: 5000 and 9000).
14+
15+
The scripts will install required packages (Apache, PostgreSQL, Python, Node toolchain) if missing.
16+
17+
---
18+
19+
### Configure .env
20+
21+
It is sourced by bash, so stick to `KEY=VALUE` and use quotes if values contain spaces.
22+
23+
Required/commonly used variables:
24+
25+
- BASIL_SERVER_NAME: public hostname or IP used in Apache vhosts
26+
- BASIL_SERVER_ALIAS: optional additional host alias
27+
- BASIL_SERVER_ADMIN: admin email for Apache configs
28+
- BASIL_API_PORT: API Apache vhost port (default 5000)
29+
- BASIL_APP_PORT: Frontend Apache vhost port (default 9000)
30+
- BASIL_ADMIN_PASSWORD: password of BASIL admin user created by default
31+
- BASIL_DB_PASSWORD: PostgreSQL user password used during DB init
32+
- BASIL_TESTING: 1 to use a `test` DB instead of `basil` (default 0)
33+
- BASIL_TEST_RUNS_BASE_DIR: base dir for tmt test runs (default `/var/basil/test-runs`)
34+
- BASIL_GITCLONE: 1 = force fresh clone to `/tmp/basil`, 0 = reuse if present (default 1)
35+
- BASIL_GITGOBACK: number of commits to revert from HEAD (default 0)
36+
- BASIL_COMMITBEFORE: ISO8601 date used only when `BASIL_GITGOBACK < 0` (e.g. `2025-01-01 00:00:00 +0000`)
37+
- BASIL_RESET_POSTGRES_CLUSTERS: 1 to wipe/recreate all local Postgres clusters (DANGEROUS), -1 to skip (default)
38+
39+
Example `.env` you can copy and adjust:
40+
41+
```bash
42+
# Apache vhost details
43+
BASIL_SERVER_NAME="your.host.name"
44+
BASIL_SERVER_ALIAS="your.host.alias"
45+
BASIL_SERVER_ADMIN="[email protected]"
46+
47+
# Ports
48+
BASIL_API_PORT=5000
49+
BASIL_APP_PORT=9000
50+
51+
# BASIL runtime
52+
BASIL_ADMIN_PASSWORD="ChangeMe_Strong_Admin_Password"
53+
BASIL_TEST_RUNS_BASE_DIR="/var/basil/test-runs"
54+
BASIL_TESTING=0
55+
56+
# Database
57+
BASIL_DB_PASSWORD="ChangeMe_Strong_DB_Password"
58+
BASIL_RESET_POSTGRES_CLUSTERS=-1
59+
60+
# Git checkout behavior for building
61+
BASIL_GITCLONE=1
62+
BASIL_GITGOBACK=0
63+
# Only used if BASIL_GITGOBACK < 0
64+
BASIL_COMMITBEFORE="2025-01-01 00:00:00 +0000"
65+
```
66+
67+
Notes:
68+
- Passwords are required: set both `BASIL_ADMIN_PASSWORD` and `BASIL_DB_PASSWORD`.
69+
- Use quotes for values with special characters.
70+
71+
---
72+
73+
### Run the deployment
74+
75+
From this folder:
76+
77+
```bash
78+
sudo ./run.sh
79+
```
80+
81+
Why sudo? The scripts write under `/var/www`, `/etc/apache2`, manage services, and change ownership to `www-data`.
82+
83+
What `run.sh` does:
84+
- Installs required packages via apt
85+
- Initializes PostgreSQL (`init_postgresql.sh`)
86+
- Builds and configures the API for Apache/mod_wsgi (`build_basil_api.sh`)
87+
- Builds the frontend, configures Apache static vhost with React router rewrite (`build_basil_frontend.sh`)
88+
89+
Artifacts and logs in this folder:
90+
- `init_postgresql.log`
91+
- `build_basil_api.log`
92+
- `build_basil_frontend.log`
93+
94+
---
95+
96+
### Verify
97+
98+
- API version endpoint: `http://<BASIL_SERVER_NAME>:<BASIL_API_PORT>/version`
99+
- Frontend version: `http://<BASIL_SERVER_NAME>:<BASIL_APP_PORT>/version`
100+
101+
Both checks are executed automatically at the end of the respective scripts and reported in the logs.
102+
103+
---
104+
105+
### Troubleshooting
106+
107+
- Ports already in use: adjust `BASIL_API_PORT` / `BASIL_APP_PORT` in `.env` and re-run.
108+
- Wrong hostname: update `BASIL_SERVER_NAME` (and optional alias) and re-run.
109+
- PostgreSQL reset: set `BASIL_RESET_POSTGRES_CLUSTERS=1` only if you understand it will drop existing clusters.
110+
- Rebuild from a clean checkout: set `BASIL_GITCLONE=1`.
111+
112+

0 commit comments

Comments
 (0)