Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appimage back #1588

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: AppImage distribution

on:
schedule:
- cron: '45 3 * * *'
workflow_dispatch:
workflow_call:
# TODO: REMOVE THIS BEFORE MERGING
push:


jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
sudo apt-add-repository ppa:swi-prolog/stable -y
sudo apt-get update -y
sudo apt-get install swi-prolog-nox libpcre3 libgmp-dev -y
- name: Create appimage
run: |
cd distribution/appimage
wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage
./build_script.sh
mv "TerminusDB-$(echo $GITHUB_SHA | cut -c 1-7)-x86_64.AppImage" TerminusDB-amd64.AppImage

# I want to make sure that we are not secretly relying on SWIPL
# and the tests will still work without SWI Prolog installed
- name: Remove SWI Prolog
run: sudo apt remove swi-prolog-nox

- name: Run AppImage tests
run: |
cd distribution/appimage && chmod +x TerminusDB-amd64.AppImage && \
./TerminusDB-amd64.AppImage store init && ./TerminusDB-amd64.AppImage serve &
cd tests && npm i && export TERMINUSDB_EXEC_PATH=../distribution/appimage/TerminusDB-amd64.AppImage && \
npm run test

- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: TerminusDB-amd64.AppImage
path: distribution/appimage/TerminusDB-amd64.AppImage
40 changes: 40 additions & 0 deletions distribution/appimage/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

function set_cert_paths {
CERT_PATHS="/etc/ssl/certs/ca-certificates.crt
/etc/pki/tls/certs/ca-bundle.crt
/etc/ssl/ca-bundle.pem
/etc/pki/tls/cacert.pem
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/ssl/cert.pem"

for CERT in $CERT_PATHS
do
if [ -f "$CERT" ]; then
export TERMINUSDB_SYSTEM_SSL_CERTS="$CERT"
fi

done
}

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SOURCE="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
export SWI_HOME_DIR=$SOURCE/usr/lib/swi-prolog
export TERMINUSDB_DASHBOARD_PATH=${TERMINUSDB_DASHBOARD_PATH:-$SOURCE/usr/share/terminusdb/dashboard}
export TERMINUSDB_SERVER_PACK_DIR=$SOURCE/usr/lib/swi-prolog/pack
export TERMINUSDB_SERVER_DB_PATH=${TERMINUSDB_SERVER_DB_PATH:-$(pwd)/storage}
export TERMINUSDB_SERVER_REGISTRY_PATH=${TERMINUSDB_SERVER_REGISTRY_PATH:-$(pwd)/registry.pl}
export TERMINUSDB_LOG_PATH=${TERMINUSDB_SERVER_LOG_PATH:-$(pwd)/httpd.log}
export TERMINUSDB_SERVER_TMP_PATH=${TERMINUSDB_SERVER_TMP_PATH:-/tmp}
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SOURCE/usr/lib/swi-prolog/lib/x86_64-linux/"

if [[ -z "${TERMINUSDB_SYSTEM_SSL_CERTS}" ]]; then
set_cert_paths
fi

$SOURCE/usr/share/terminusdb/terminusdb "$@"
9 changes: 9 additions & 0 deletions distribution/appimage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# terminusdb appimage

Run the build\_script.sh on a Ubuntu installation with SWIPL and rust installed.

And copy the resulting app image in a terminusdb-server folder, run `./TerminusDB-[commit]-x86_64.AppImage`

# Requirements

This script is only tested on Ubuntu 16.04
15 changes: 15 additions & 0 deletions distribution/appimage/build_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
CURRENT_DIR=$(pwd)
SOURCE="${BASH_SOURCE[0]}"
mkdir -p app_dir/usr/share/terminusdb
mkdir -p app_dir/usr/bin
mkdir -p app_dir/usr/lib/x86_64-linux-gnu
# Build TerminusDB
cd ../../ && make install-dashboard && make install-deps && make && cd "$CURRENT_DIR"
# Copy relevant files back to appimage dir
cp -r ../../terminusdb ../../dashboard app_dir/usr/share/terminusdb/
cp -r /usr/lib/swi-prolog app_dir/usr/lib/
cp -L /usr/lib/x86_64-linux-gnu/libedit.so.2 app_dir/usr/lib/swi-prolog/lib/x86_64-linux/
cp -L /lib/x86_64-linux-gnu/libpcre.so.3 app_dir/usr/lib/swi-prolog/lib/x86_64-linux/
cp -L /usr/lib/x86_64-linux-gnu/libbsd.so.0 app_dir/usr/lib/swi-prolog/lib/x86_64-linux/
LD_LIBRARY_PATH='/usr/lib/swi-prolog/lib/x86_64-linux/' ./linuxdeploy-x86_64.AppImage --appdir ./app_dir --executable /usr/lib/swi-prolog/bin/x86_64-linux/swipl --library /usr/lib/swi-prolog/lib/x86_64-linux/libswipl.so.9 --library /lib/x86_64-linux-gnu/libpcre.so.3 -d terminusdb.desktop -i terminusdb.svg --custom-apprun AppRun --output appimage --verbosity=0
7 changes: 7 additions & 0 deletions distribution/appimage/terminusdb.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Categories=Utility;
Type=Application
Icon=terminusdb
Name=TerminusDB
Exec=AppRun
Terminal=true
1 change: 1 addition & 0 deletions distribution/appimage/terminusdb.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/bootstrap.pl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
foreign(save),
undefined(error),
toplevel(cli_toplevel),
autoload(false),
autoload(true),
stand_alone(true)
]).
4 changes: 4 additions & 0 deletions src/config/terminus_config.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:- module(config,[
terminusdb_version/1,
dashboard_path/1,
bootstrap_config_files/0,
server/1,
server_name/1,
Expand Down Expand Up @@ -51,6 +52,9 @@
terminusdb_version('11.0.6').
/* [[[end]]] */

dashboard_path(Path) :-
getenv('TERMINUSDB_DASHBOARD_PATH', Path).

bootstrap_config_files :-
initialize_system_ssl_certs.

Expand Down
1 change: 1 addition & 0 deletions src/core/api.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:- module(api, [
% init.pl
bootstrap_files/0,
add_dashboard_path/0,
index_template/1,
initialize_flags/0,
initialize_database/2,
Expand Down
14 changes: 14 additions & 0 deletions src/core/api/api_init.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:- module(api_init, [
bootstrap_files/0,
add_dashboard_path/0,
initialize_flags/0,
initialize_database/2,
initialize_database_with_store/2,
Expand Down Expand Up @@ -122,6 +123,19 @@
db_path(DB_Path),
initialize_database_with_path(Key, DB_Path, Force).

assert_dashboard_path(Dir) :-
directory_file_path(Dir, 'assets', Assets),
asserta(user:file_search_path(dashboard, Dir)),
asserta(user:file_search_path(assets, Assets)).

add_dashboard_path :-
config:dashboard_path(Dir),
assert_dashboard_path(Dir).
add_dashboard_path :-
user:file_search_path(terminus_top_dir, Dir),
directory_file_path(Dir, 'dashboard', Dashboard),
assert_dashboard_path(Dashboard).

/*
* initialize_database_with_path(Key,DB_Path,Force) is det+error.
*
Expand Down
21 changes: 6 additions & 15 deletions src/load_paths.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
prolog_load_context(file, File),
relative_file_name(Path, File, '..').

add_terminus_top_dir :-
top_level_directory(TopDir),
asserta(user:file_search_path(terminus_top_dir, TopDir)).

:- add_terminus_top_dir.

add_terminus_home_path :-
top_level_directory(TopDir),
directory_file_path(TopDir, 'src', SrcDir),
Expand Down Expand Up @@ -122,21 +128,6 @@
directory_file_path(Dir, 'terminusdb-enterprise/test', Enterprise),
asserta(user:file_search_path(enterprise_test, Enterprise)).

assert_dashboard_path(Dir) :-
directory_file_path(Dir, 'assets', Assets),
asserta(user:file_search_path(dashboard, Dir)),
asserta(user:file_search_path(assets, Assets)).

add_dashboard_path :-
getenv('TERMINUSDB_DASHBOARD_PATH', Dir),
assert_dashboard_path(Dir).
add_dashboard_path :-
top_level_directory(Dir),
directory_file_path(Dir, 'dashboard', Dashboard),
assert_dashboard_path(Dashboard).

:- add_dashboard_path.

:- if(getenv("TERMINUSDB_ENTERPRISE", true)).
:- add_enterprise_path.
:- add_enterprise_test_path.
Expand Down
1 change: 1 addition & 0 deletions src/server/main.pl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
server(Server),
server_port(Port),
worker_amount(Workers),
add_dashboard_path,
load_jwt_conditionally,
HTTPOptions = [port(Port), workers(Workers), silent(true)],
foreach(pre_server_startup_hook(Port),true),
Expand Down