### Install and Start Oryx React UI Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command installs the necessary Node.js dependencies for the Oryx React UI and then starts the development server. It requires Node.js and npm to be installed. The UI will be accessible at http://localhost:3000. ```bash (cd ui && npm install && npm start) ``` -------------------------------- ### Install and Start Oryx Service (JavaScript) Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-bt/index.html This JavaScript code installs, starts, and manages the Oryx service. It queries the SRS, cleans up installations, and uses asynchronous operations to handle the process. The code also updates the UI with progress messages and disables buttons during the installation process. It also dispatches a management command. ```JavaScript async function installOryx() { _request('querySrs'); console.log(`installing pid is ${JSON.stringify(pid)}`); if (pid.r0) { await oryx_request('cleanupIntall'); } await new Promise((resolve, reject) => { installing(resolve, reject); }); layer.msg('Oryx启动中,请稍后......', {icon: 1}); $('.btn_install_srs').html('正在启动').attr({'disabled': 'disabled'}); await new Promise(resolve => setTimeout(resolve, 30000)); layer.msg('Oryx安装成功', {icon: 1}); $('.btn_install_srs').html('安装完成').attr({'disabled': 'disabled'}); await new Promise(resolve => setTimeout(resolve, 1500)); await oryx_dispatch($("p[name='mgmt']")); } $(function () { oryx_init(); }); ``` -------------------------------- ### Build and Install BT Plugin Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This bash script sequence first uninstalls any existing BT plugin, removes a configuration file, then creates a zip archive of the plugin for installation. Finally, it installs the newly built BT plugin within the 'bt' Docker container. ```bash docker exec -it bt bash /www/server/panel/plugin/oryx/install.sh uninstall 2>/dev/null || echo OK && docker exec -it bt rm -f /data/config/.env && bash scripts/setup-bt/auto/zip.sh --output $(pwd)/build --extract && docker exec -it bt bash /www/server/panel/plugin/oryx/install.sh install ``` -------------------------------- ### Install BT Plugin via Python Scripts Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command sequence executes Python scripts within the 'bt' Docker container to manage site configurations and install the Oryx plugin. It performs uninstallation, environment file removal, and then installs the plugin using a setup script with specified parameters. ```bash docker exec -it bt python3 /www/server/panel/plugin/oryx/bt_api_remove_site.py && docker exec -it bt python3 /www/server/panel/plugin/oryx/bt_api_create_site.py && docker exec -it bt python3 /www/server/panel/plugin/oryx/bt_api_setup_site.py && docker exec -it bt bash /www/server/panel/plugin/oryx/setup.sh \ --r0 /tmp/oryx_install.r0 --nginx /www/server/nginx/logs/nginx.pid \ --www /www/wwwroot --site srs.stack.local ``` -------------------------------- ### Start aaPanel Plugin Development Container Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Starts a Docker container for aaPanel plugin development, mounting the local Oryx build directory as a plugin. It configures necessary ports, environment variables, and volumes for a development environment. Ensure the BT API key is configured and saved to $HOME/.bt/api.json. ```bash docker rm -f bt aapanel 2>/dev/null && AAPANEL_KEY=$(cat $HOME/.bt/api.json |awk -F token_crypt '{print $2}' |cut -d'"' -f3) && docker run -p 80:80 -p 443:443 -p 7800:7800 -p 1935:1935 -p 8000:8000/udp -p 10080:10080/udp \ --env CANDIDATE=$(ifconfig en0 |grep 'inet ' |awk '{print $2}') \ -v $(pwd)/build/oryx:/www/server/panel/plugin/oryx \ -v $HOME/.bt/api.json:/www/server/panel/config/api.json -e BT_KEY=$AAPANEL_KEY \ --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host \ -d --rm -it -v $(pwd):/g -w /g --name=aapanel ossrs/aapanel-plugin-dev:1 ``` -------------------------------- ### Install Oryx using Helm Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md These commands demonstrate different ways to install Oryx using Helm. The first installs the latest version from the added repository. The second installs from a local tgz file, and the third installs from a tgz file while configuring persistent storage path. ```bash helm install srs srs/oryx helm install srs ~/git/srs-helm/stable/oryx-1.0.6.tgz helm install srs ~/git/srs-helm/stable/oryx-1.0.6.tgz \ --set persistence.path=$HOME/data ``` -------------------------------- ### Attempt Oryx Installation (JavaScript) Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-aapanel/index.html Initiates the Oryx installation process. It validates the domain input, checks service readiness, and calls the appropriate installation functions. Includes error handling and UI updates. ```javascript async function oryx_try_install() { const domain = $('.txt_srs_domain').val(); if (!domain) { alert('Please input the domain'); throw 'no domain'; } const domainRegex = /^(?=.{1,253})(?:(?!-)[A-Za-z0-9-]{1,63}(?/dev/null || echo ok && docker rm -f redis srs 2>/dev/null && docker run --rm -it --name oryx -v $HOME/data:/data \ -p 2022:2022 -p 2443:2443 -p 1935:1935 -p 8000:8000/udp -p 10080:10080/udp \ -p 80:2022 -p 443:2443 -e CANDIDATE=$(ifconfig en0 |grep 'inet ' |awk '{print $2}') \ platform ``` -------------------------------- ### Oryx Installation Core Logic (JavaScript) Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-aapanel/index.html Executes the core installation steps for Oryx. This includes checking and installing dependencies (like NGINX, Docker), creating and setting up the SRS site, and configuring the firewall. ```javascript async function oryx_install() { if ($('.install_log').empty()) { $('.install_log').show().val('Installing...\n'); } let tips = layer.msg('Check the service status.', {icon: 16}); const services = await oryx_request('serviceStatus'); console.log(`services status is ${JSON.stringify(services)}`); layer.close(tips); // If BT or aaPanel not ready to install SRS, should wait. if (services?.plugin_ready !== 'ok') { const msg = `Installing Oryx plugin, please try again later.`; layer.msg(msg, {icon: 2}); throw msg; } // Request to install depends services. const deps = [ ...(services?.nginx ? [] : [{id: 'nginx', title: 'NGINX', call: 'bt.soft.install'}]), ]; // If no docker manager plugin, or docker service, install the plugin. // If there is a docker installed, we only need to start it, don't require the docker plugin. if (!services?.docker_manager && !services?.docker_installed) { deps.push({id: 'docker', title: 'Docker', call: 'bt.soft.install'}); } const tasks = await oryx_request('installTasks'); const notInstalledDeps = deps.filter(dep => { if (tasks.filter(task => { return task?.name?.indexOf(`[${dep.id}-`) >= 0 ? task : null; }).length > 0) { return null; } return dep; }); if (notInstalledDeps.length) { return await install_dependence(notInstalledDeps); } if (deps.length) { return await installing_dependence(deps); } // Try to install docker service. if (!services?.docker_installed) { layer.msg('Install Docker service', {icon: 1}); await oryx_request('installService', {service: 'docker'}); await new Promise(resolve => setTimeout(resolve, 1000)); } // Try to start docker service. if (!services?.docker_running) { layer.msg('Start Docker service', {icon: 1}); await oryx_request('restartService', {service: 'docker'}); await new Promise(resolve => setTimeout(resolve, 1000)); } // Try to create site for Oryx. if (!services?.site_created) { const domain = $('.txt_srs_domain').val(); layer.msg(`Create the Oryx website: ${domain}`, {icon: 1}); const site = await oryx_request('createSrsSite', {domain: domain}); console.log(`Create site ${JSON.stringify(site)}`); await new Promise(resolve => setTimeout(resolve, 1000)); } // Setup the website. Note that it depends on http configuration files. if (!services?.site_setup) { layer.msg('Setup the Oryx website', {icon: 1}); const data = await oryx_request('setupSrsSite'); console.log('setup site', data); await new Promise(resolve => setTimeout(resolve, 1000)); } // Setup the firewall. if (!services?.firewall_ready) { layer.msg('Setup the firewall', {icon: 1}); const data = await oryx_request('setupFirewall'); console.log('setup firewall', data); await new Promise(resolve => setTimeout(resolve, 1000)); } } ``` -------------------------------- ### Start SRS and Redis using Docker on macOS Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command starts Redis and SRS services using Docker on a macOS development environment. It ensures previous containers are stopped and removed, maps necessary ports, and mounts configuration and data volumes. It requires Docker to be installed and the `ossrs/srs:5` image to be available. ```bash docker stop redis 2>/dev/null || echo ok && docker rm -f redis srs 2>/dev/null && docker run --name redis --rm -it -v $HOME/data/redis:/data -p 6379:6379 -d redis:5.0 && touch platform/containers/data/config/srs.server.conf platform/containers/data/config/srs.vhost.conf && docker run --name srs --rm -it \ -v $(pwd)/platform/containers/data/config:/usr/local/srs/containers/data/config \ -v $(pwd)/platform/containers/conf/srs.release-mac.conf:/usr/local/srs/conf/docker.conf \ -v $(pwd)/platform/containers/objs/nginx:/usr/local/srs/objs/nginx \ -p 1935:1935 -p 1985:1985 -p 8080:8080 -p 8000:8000/udp -p 10080:10080/udp \ -d ossrs/srs:5 ``` -------------------------------- ### Install Packer and DigitalOcean Plugin for Building SRS Droplet Image Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Installs Packer and the DigitalOcean plugin required for building the SRS droplet image on DigitalOcean. Ensure you have Homebrew installed for macOS. ```bash brew tap hashicorp/tap && brew install hashicorp/tap/packer && PACKER_LOG=1 packer plugins install github.com/digitalocean/digitalocean ``` -------------------------------- ### Core SRS Installation Logic (JavaScript) Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-bt/index.html Manages the detailed installation of SRS, including checking and installing dependencies like Nginx and Docker if necessary. It also handles site creation, setup, and firewall configuration. Relies heavily on `oryx_request` for various backend operations and UI feedback via `layer.msg`. Dependencies: jQuery, `oryx_request`, `install_dependence`, `installing_dependence`. ```javascript async function oryx_install() { if ($('.install_log').empty()) { $('.install_log').show().val('Installing...\n'); } let tips = layer.msg('检测服务状态', {icon: 16}); const services = await oryx_request('serviceStatus'); console.log(`services status is ${JSON.stringify(services)}`); layer.close(tips); // If BT or aaPanel not ready to install SRS, should wait. if (services?.plugin_ready !== 'ok') { const msg = `正在安装SRS插件,请稍后再试`; layer.msg(msg, {icon: 2}); throw msg; } // Request to install depends services. const deps = [ ...(services?.nginx ? [] : [{id: 'nginx', title: 'NGINX', call: 'bt.soft.install'}]), ]; // If no docker manager plugin, or docker service, install the plugin. // If there is a docker installed, we only need to start it, don't require the docker plugin. if (!services?.docker_manager && !services?.docker_installed) { deps.push({id: 'docker', title: 'Docker', call: 'bt.soft.install'}); } const tasks = await oryx_request('installTasks'); const notInstalledDeps = deps.filter(dep => { if (tasks.filter(task => { return task?.name?.indexOf(`[${dep.id}-`) >= 0 ? task : null; }).length > 0) { return null; } return dep; }); if (notInstalledDeps.length) { return await install_dependence(notInstalledDeps); } if (deps.length) { return await installing_dependence(deps); } // Try to install docker service. if (!services?.docker_installed) { layer.msg('安装Docker服务', {icon: 1}); await oryx_request('installService', {service: 'docker'}); await new Promise(resolve => setTimeout(resolve, 1000)); } // Try to start docker service. if (!services?.docker_running) { layer.msg('启动Docker服务', {icon: 1}); await oryx_request('restartService', {service: 'docker'}); await new Promise(resolve => setTimeout(resolve, 1000)); } // Try to create site for Oryx. if (!services?.site_created) { const domain = $('.txt_srs_domain').val(); layer.msg(`创建Oryx站点: ${domain}`, {icon: 1}); const site = await oryx_request('createSrsSite', {domain: domain}); console.log(`Create site ${JSON.stringify(site)}`); await new Promise(resolve => setTimeout(resolve, 1000)); } // Setup the website. Note that it depends on http configuration files. if (!services?.site_setup) { layer.msg('设置Oryx站点', {icon: 1}); const data = await oryx_request('setupSrsSite'); console.log('setup site', data); await new Promise(resolve => setTimeout(resolve, 1000)); } // Setup the firewall. if (!services?.firewall_ready) { layer.msg('设置防火墙', {icon: 1}); const data = await oryx_request('setupFirewall'); console.log('setup firewall', data); await new Promise(resolve => setTimeout(resolve, 1000)); } } ``` -------------------------------- ### Run System Tests for Script Installer Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Runs a comprehensive suite of system tests for the script installer. This involves generating environment variables, compiling tests, and executing the test binary with various configurations for HTTP and HTTPS endpoints. The tests verify system stability and API interactions, with options to control test timeouts, verbosity, and parallel execution. ```bash rm -f test/oryx.test && docker exec -it script make -j -C test && bash scripts/tools/secret.sh --output test/.env && sleep 5 && docker exec -it script ./test/oryx.test -test.timeout=1h -test.failfast -test.v -endpoint http://localhost:2022 \ -srs-log=true -wait-ready=true -init-password=true -check-api-secret=true -init-self-signed-cert=true \ -test.run TestSystem_Empty && bash scripts/tools/secret.sh --output test/.env && sleep 5 && docker exec -it script ./test/oryx.test -test.timeout=1h -test.failfast -test.v -wait-ready -endpoint http://localhost:2022 \ -srs-log=true -wait-ready=true -init-password=false -check-api-secret=true \ -test.parallel 3 && docker exec -it script ./test/oryx.test -test.timeout=1h -test.failfast -test.v -wait-ready -endpoint https://localhost:2443 \ -srs-log=true -wait-ready=true -init-password=false -check-api-secret=true \ -test.parallel 3 ``` -------------------------------- ### Build and Install aaPanel Plugin Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This script sequence first uninstalls any existing Oryx plugin, then builds a zip archive of the plugin, and finally installs it into the aaPanel environment within the Docker container. It handles potential errors during the uninstall process. ```bash docker exec -it aapanel rm -f /data/config/.env && docker exec -it aapanel bash /www/server/panel/plugin/oryx/install.sh uninstall 2>/dev/null || echo OK && bash scripts/setup-aapanel/auto/zip.sh --output $(pwd)/build --extract && docker exec -it aapanel bash /www/server/panel/plugin/oryx/install.sh install ``` -------------------------------- ### Install and Uninstall BT Plugin Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This snippet handles the installation and uninstallation of the BT plugin for Oryx. It first attempts to uninstall any existing version of the plugin, then zips up the new plugin files, copies them to the server, unzips them, and finally installs the plugin. ```bash ssh root@$LNAME.$LDOMAIN bash /www/server/panel/plugin/oryx/install.sh uninstall 2>/dev/null || echo OK && bash scripts/setup-bt/auto/zip.sh --output $(pwd)/build --extract && scp build/bt-oryx.zip root@$LNAME.$LDOMAIN:~ && ssh root@$LNAME.$LDOMAIN unzip -q bt-oryx.zip -d /www/server/panel/plugin && ssh root@$LNAME.$LDOMAIN bash /www/server/panel/plugin/oryx/install.sh install ``` -------------------------------- ### Run Oryx Backend Application Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command executes the Oryx platform backend application using Go. It navigates to the 'platform' directory and runs the main application file. Ensure the Go environment is set up and dependencies are installed. ```bash (cd platform && go run .) ``` -------------------------------- ### Test Build Script and Install Script in Docker Container Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Executes the uninstallation script, followed by the build script, and then the installation script within the 'script' Docker container. This sequence ensures the installer is tested in a clean environment. The output of the build script is directed to the './build' directory in the host system. ```bash docker exec -it script rm -f /data/config/.env && docker exec -it script bash build/oryx/scripts/setup-ubuntu/uninstall.sh 2>/dev/null || echo OK && bash scripts/setup-ubuntu/build.sh --output $(pwd)/build --extract && docker exec -it script bash build/oryx/scripts/setup-ubuntu/install.sh --verbose ``` -------------------------------- ### Start BT Plugin Development Container Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This bash script starts a Docker container for BT plugin development. It removes existing containers, retrieves a BT API token, and mounts local build artifacts into the container. It configures environment variables for the candidate IP and API key, and sets up necessary volume mounts for persistent data and configurations. The container runs in detached mode with privileged access. ```bash docker rm -f bt aapanel 2>/dev/null && BT_KEY=$(cat $HOME/.bt/api.json |awk -F token_crypt '{print $2}' |cut -d'"' -f3) && docker run -p 80:80 -p 443:443 -p 7800:7800 -p 1935:1935 -p 8000:8000/udp -p 10080:10080/udp \ --env CANDIDATE=$(ifconfig en0 |grep 'inet ' |awk '{print $2}') \ -v $(pwd)/build/oryx:/www/server/panel/plugin/oryx \ -v $HOME/.bt/userInfo.json:/www/server/panel/data/userInfo.json \ -v $HOME/.bt/api.json:/www/server/panel/config/api.json -e BT_KEY=$BT_KEY \ --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host \ -d --rm -it -v $(pwd):/g -w /g --name=bt ossrs/bt-plugin-dev:1 ``` -------------------------------- ### Install Oryx using JavaScript Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-aapanel/index.html Asynchronously installs the Oryx service by repeatedly requesting installation status and updating the UI with progress. It handles success, failure, and log output. Dependencies include 'oryx_request', 'layer', and DOM manipulation via jQuery. ```javascript async function do_oryx_install() { const installing = async (resolve, reject) => { $('.btn_install_srs').html('Installing').attr({'disabled': 'disabled'}); let pos = 1; for (; ;) { try { const pid = await oryx_request('installSrs', {start: pos, end: pos + 100}); console.log(`installing pid is ${JSON.stringify(pid)}`); if (pid.tail) { const elem = $('.install_log').val($('.install_log').val() + pid.tail); if (elem.get(0)?.scrollHeight) elem.get(0).scrollTop = elem.get(0).scrollHeight; } pos += pid.tail ? (pid.tail.match(/\n/g)?.length || 0) : 0; if (pid.srs) return resolve(); if (pid.r0) { layer.msg('Install Oryx failed', {icon: 2}); return reject(pid); } await new Promise(r0 => setTimeout(r0, 3000)); } catch (e) { return reject(e); } } }; const pid = await oryx_request('querySrs'); console.log(`installing pid is ${JSON.stringify(pid)}`); if (pid.r0) { await oryx_request('cleanupIntall'); } await new Promise((resolve, reject) => { installing(resolve, reject); }); layer.msg('Starting Oryx......', {icon: 1}); $('.btn_install_srs').html('Starting').attr({'disabled': 'disabled'}); await new Promise(resolve => setTimeout(resolve, 30000)); layer.msg('Oryx installation successful.', {icon: 1}); $('.btn_install_srs').html('Installed').attr({'disabled': 'disabled'}); await new Promise(resolve => setTimeout(resolve, 1500)); await oryx_dispatch($("p[name='mgmt']")); } $(function () { oryx_init(); }); ``` -------------------------------- ### Install go-openai Package Source: https://github.com/ossrs/oryx/blob/main/platform/vendor/github.com/sashabaranov/go-openai/README.md This command installs the go-openai package, which provides Go clients for the OpenAI API. Ensure you have Go version 1.18 or greater installed. ```bash go get github.com/sashabaranov/go-openai ``` -------------------------------- ### Oryx Initialization and Dispatch Logic in JavaScript Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-aapanel/index.html Initializes the Oryx application by setting up event listeners for menu clicks and the install button. It fetches service status and dispatches the appropriate view based on the Oryx installation state. It also handles querying the SRS process status. ```javascript async function oryx_init() { $(".bt-w-menu p").click(function () { oryx_dispatch($(this)); }); $('.btn_install_srs').click(function () { oryx_try_install(); }); const services = await oryx_request('serviceStatus'); if (services?.site_domain) { $('.txt_srs_domain').val(services?.site_domain); } console.log(`services is ${JSON.stringify(services)}`); if (!services?.srs_ready || services?.srs_error) { $(".bt-w-menu p\[name='install'\]").addClass('bgw').siblings().removeClass('bgw'); $('.install_version_box').show().siblings().hide(); await oryx_setup_install_view(); } else { await oryx_dispatch($("p\[name='mgmt']")); } const pid = await oryx_request('querySrs'); console.log(`srs is ${JSON.stringify(services)}`); if (pid?.running) { await do_oryx_install(); } } async function oryx_refresh_logs() { const pid = await oryx_request('querySrs'); if (pid.tail) { const elem = $('.install_log').val($('.install_log').val() + pid.tail).show(); elem.get(0).scrollTop = elem.get(0)?.scrollHeight; } } async function oryx_dispatch(self) { const menuName = self.attr('name'); const services = await oryx_request('serviceStatus'); if (!services?.srs_ready || services?.srs_error) { if (menuName !== 'install') layer.msg('Please install the Oryx first', {icon: 7}); return console.log(`service not ready ${JSON.stringify(services)}`); } self.addClass('bgw').siblings().removeClass('bgw'); $(`.conter_box\[name=${menuName}\]`).show().siblings().hide(); if (menuName === 'service') { await oryx_setup_service_view(); } else if (menuName === 'mgmt') { await oryx_setup_mgmt_view(); } else if (menuName === 'install') { await oryx_setup_install_view(); } } async function oryx_setup_install_view() { const pid = await oryx_request('querySrs'); console.log(`installing pid is ${JSON.stringify(pid)}`); if (pid?.srs || pid?.running) { $('.b ``` -------------------------------- ### Oryx Dependency Installation Prompts in JavaScript Source: https://github.com/ossrs/oryx/blob/main/scripts/setup-aapanel/index.html Functions to display modal dialogs for installing Oryx dependencies. `install_dependence` shows a list of dependencies to be installed, while `installing_dependence` indicates that dependencies are currently being installed. Both use the `layer` modal library and return Promises. ```javascript async function install_dependence(deps) { const depsContent = deps.map((dep, index) => { return `
  • ${index + 1}: 安装${dep.title}
  • `; }).join('\n'); layer.closeAll(); return new Promise((resolve, reject) => { layer.open({ icon: 0, closeBtn: 0, title: 'Install Oryx', area: '400px', btn: [], content: `

    Please install the following dependencies:

    Please continue to install the Oryx after installing the dependencies.

    `, success: function (layero, index) { // Note that this is called when the window is open, not closed or finished. resolve(); }, }); }); } async function installing_dependence(deps) { const depsContent = deps.map((dep, index) => { const desc = `Installing ${dep.title}`; return `
  • ${index + 1}: ${desc}
  • `; }).join('\n'); layer.closeAll(); return new Promise((resolve, reject) => { layer.open({ icon: 0, closeBtn: 0, title: 'Install Oryx', area: '400px', btn: [], content: `

    Please install the following dependencies:

    Please continue to install the Oryx after installing the dependencies. Click here for detail. `, success: function (layero, index) { // Note that this is called when the window is open, not closed or finished. resolve(); }, }); }); } ``` -------------------------------- ### Start Docker Container with Updated Platform Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command restarts the Oryx Docker container, incorporating the locally updated platform code. It mounts the 'platform/platform' directory into the container and ensures all necessary ports and environment variables are configured. This follows a local build of the platform. ```bash docker stop redis 2>/dev/null || echo ok && docker rm -f redis srs 2>/dev/null && docker run --rm -it --name oryx -v $HOME/data:/data \ -p 2022:2022 -p 2443:2443 -p 1935:1935 -p 8000:8000/udp -p 10080:10080/udp \ -p 80:2022 -p 443:2443 -e CANDIDATE=$(ifconfig en0 |grep 'inet ' |awk '{print $2}') \ -v $(pwd)/platform/platform:/usr/local/oryx/platform/platform \ platform ``` -------------------------------- ### Run System Tests for aaPanel Plugin Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Executes a series of system tests for the Oryx plugin within the aaPanel environment. These tests cover various scenarios including initial setup, password configurations, and secure endpoint testing over HTTP and HTTPS. The tests are configured with timeouts and specific test cases. ```bash rm -f test/oryx.test && docker exec -it aapanel make -j -C test && bash scripts/tools/secret.sh --output test/.env && sleep 5 && docker exec -it aapanel ./test/oryx.test -test.timeout=1h -test.failfast -test.v -endpoint http://srs.stack.local:80 \ -srs-log=true -wait-ready=true -init-password=true -check-api-secret=true -init-self-signed-cert=true \ -test.run TestSystem_Empty && bash scripts/tools/secret.sh --output test/.env && sleep 5 && docker exec -it aapanel ./test/oryx.test -test.timeout=1h -test.failfast -test.v -wait-ready -endpoint http://srs.stack.local:80 \ -srs-log=true -wait-ready=true -init-password=false -check-api-secret=true \ -test.parallel 3 && docker exec -it aapanel ./test/oryx.test -test.timeout=1h -test.failfast -test.v -wait-ready -endpoint https://srs.stack.local:443 \ -srs-log=true -wait-ready=true -init-password=false -check-api-secret=true \ -test.parallel 3 ``` -------------------------------- ### Quickstart: Connect and Set/Get Redis Key (Go) Source: https://github.com/ossrs/oryx/blob/main/platform/vendor/github.com/go-redis/redis/v8/README.md Demonstrates how to connect to a Redis instance, set a key-value pair with an expiration, and retrieve its value. It also shows how to handle cases where a key does not exist. ```go import ( "context" "github.com/go-redis/redis/v8" "fmt" ) var ctx = context.Background() func ExampleClient() { rdb := redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", // no password set DB: 0, // use default DB }) err := rdb.Set(ctx, "key", "value", 0).Err() if err != nil { panic(err) } val, err := rdb.Get(ctx, "key").Result() if err != nil { panic(err) } fmt.Println("key", val) val2, err := rdb.Get(ctx, "key2").Result() if err == redis.Nil { fmt.Println("key2 does not exist") } else if err != nil { panic(err) } else { fmt.Println("key2", val2) } // Output: key value // key2 does not exist } ``` -------------------------------- ### Set Up Local Redis for Testing (Shell) Source: https://github.com/ossrs/oryx/blob/main/platform/vendor/github.com/go-redis/redis/v8/README.md These shell commands demonstrate how to configure your local environment to run go-redis tests. It involves creating a symbolic link to your system's redis-server binary and copying a configuration file. This is necessary for running tests locally if the default paths are not available. ```shell ln -s /usr/bin/redis-server ./go-redis/testdata/redis/src cp ./go-redis/testdata/redis.conf ./go-redis/testdata/redis/ ``` -------------------------------- ### Install GoDotEnv Library Source: https://github.com/ossrs/oryx/blob/main/platform/vendor/github.com/joho/godotenv/README.md Installs the godotenv library using go get. This is the primary method for using GoDotEnv within your Go projects to load environment variables. ```shell go get github.com/joho/godotenv ``` -------------------------------- ### Example: Create Chat Completion with Go Source: https://github.com/ossrs/oryx/blob/main/platform/vendor/github.com/sashabaranov/go-openai/README.md Demonstrates how to create a chat completion using the go-openai library. It initializes a client with an API key and sends a user message to the GPT-3.5 Turbo model. The response content is then printed to the console. Ensure you replace 'your token' with your actual OpenAI API key. ```go package main import ( "context" "fmt" openai "github.com/sashabaranov/go-openai" ) func main() { client := openai.NewClient("your token") resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Hello!", }, }, }, ) if err != nil { fmt.Printf("ChatCompletion error: %v\n", err) return } fmt.Println(resp.Choices[0].Message.Content) } ``` -------------------------------- ### Prepare Environment for Goland Test Cases Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This bash script prepares the testing environment for running Goland test cases. It first generates a `.env` file using `secret.sh` and then copies a sample video file into the `test/` directory. ```bash bash scripts/tools/secret.sh --output test/.env && cp ~/git/srs/trunk/doc/source.200kbps.768x320.flv test/ ``` -------------------------------- ### Prepare and Upload Data for Fine-Tuning OpenAI Models Source: https://github.com/ossrs/oryx/blob/main/platform/vendor/github.com/sashabaranov/go-openai/README.md Shows how to prepare training data in JSONL format and upload it for fine-tuning an OpenAI model using the Go client. It covers both conversational and older prompt/completion formats and explains how to create a fine-tuning job. ```go package main import ( "context" "fmt" "github.com/sashabaranov/go-openai" ) func main() { client := openai.NewClient("your token") ctx := context.Background() // create a .jsonl file with your training data for conversational model // {"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]} file, err := client.CreateFile(ctx, openai.FileRequest{ FilePath: "training_prepared.jsonl", Purpose: "fine-tune", }) if err != nil { fmt.Printf("Upload JSONL file error: %v\n", err) return } // create a fine tuning job fineTuningJob, err := client.CreateFineTuningJob(ctx, openai.FineTuningJobRequest{ TrainingFile: file.ID, Model: "davinci-002", // gpt-3.5-turbo-0613, babbage-002. }) } ``` -------------------------------- ### Add Oryx Helm Repository Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command adds the Oryx Helm chart repository to your Helm configuration. This allows you to easily install Oryx using Helm by referencing the charts from the specified URL. ```bash helm repo add srs http://helm.ossrs.io/stable ``` -------------------------------- ### Enter Docker Container and Load/Tag Image Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Loads the 'platform.tar' image into the 'script' Docker container, tags it with the version obtained from 'scripts/version.sh', and also tags it for Alibaba Cloud's registry. Finally, it lists the images within the container to verify the tagging. ```bash version=$(bash scripts/version.sh) && docker exec -it script docker load -i platform.tar && docker exec -it script docker tag platform:latest ossrs/oryx:$version && docker exec -it script docker tag platform:latest registry.cn-hangzhou.aliyuncs.com/ossrs/oryx:$version && docker exec -it script docker images ``` -------------------------------- ### Install Oryx with Lightsail Script Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This command executes the `lightsail.sh` script within the running Oryx Docker container. It uses `docker exec` to run the script from the `/tmp` directory, assuming the script has been copied or mounted into the container. ```bash docker exec -it -w /tmp script bash /g/scripts/lightsail.sh ``` -------------------------------- ### Build Oryx Docker Image Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This set of commands builds the Oryx Docker image, tags it as 'platform:latest', and saves it to a tar archive. It first removes any existing 'platform:latest' image to ensure a clean build. Requires Docker to be installed. ```bash docker rmi platform:latest 2>/dev/null || echo OK && docker build -t platform:latest -f Dockerfile . && docker save -o platform.tar platform:latest ``` -------------------------------- ### Test NGINX HLS CDN with cURL Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md These cURL commands are used to test the NGINX HLS CDN by sending OPTIONS and GET requests to a sample HLS stream. They include the 'Origin' header to test CORS configurations, useful for verifying cross-origin resource sharing. ```bash curl 'http://localhost/live/livestream.m3u8' -X 'OPTIONS' -H 'Origin: http://ossrs.net' -v curl 'http://localhost/live/livestream.m3u8' -X 'GET' -H 'Origin: http://ossrs.net' -v ``` -------------------------------- ### Manage Oryx Sites via BT Panel APIs Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This section provides commands to manage Oryx sites using Python scripts executed on the server via SSH. It includes removing a site, creating a new site, and setting up the site with specified configurations like domain, Nginx path, and www root. ```bash ssh root@$LNAME.$LDOMAIN python3 /www/server/panel/plugin/oryx/bt_api_remove_site.py && ssh root@$LNAME.$LDOMAIN DOMAIN=$LNAME.$LDOMAIN python3 /www/server/panel/plugin/oryx/bt_api_create_site.py && ssh root@$LNAME.$LDOMAIN python3 /www/server/panel/plugin/oryx/bt_api_setup_site.py && ssh root@$LNAME.$LDOMAIN bash /www/server/panel/plugin/oryx/setup.sh \ --r0 /tmp/oryx_install.r0 --nginx /www/server/nginx/logs/nginx.pid \ --www /www/wwwroot --site srs.stack.local ``` -------------------------------- ### Build Docker Image for Script Installer Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md Builds a Docker image named 'srs-script-dev' from the 'scripts/setup-ubuntu/Dockerfile.script' file. It first removes any existing container named 'script' and the image 'srs-script-dev' to ensure a clean build. The 'docker build' command tags the image for development purposes. ```bash docker rm -f script 2>/dev/null && docker rmi srs-script-dev 2>/dev/null || echo OK && docker build -t srs-script-dev -f scripts/setup-ubuntu/Dockerfile.script . ``` -------------------------------- ### Prepare Test Environment on Lighthouse CVM Source: https://github.com/ossrs/oryx/blob/main/DEVELOPER.md This bash script prepares the test environment on the verification CVM instance by setting up SSH and SCP commands with password authentication, creating necessary directories, copying test files, and running Docker commands to build the Oryx test executable. It ensures the test environment is ready for running test suites. ```bash sshCmd="sshpass -p $(cat .tmp/lh-token2.txt) ssh -o StrictHostKeyChecking=no -t" && scpCmd="sshpass -p $(cat .tmp/lh-token2.txt) scp -o StrictHostKeyChecking=no" && $sshCmd ubuntu@$(cat .tmp/lh-ip2.txt) sudo mkdir -p /data/upload && $sshCmd ubuntu@$(cat .tmp/lh-ip2.txt) mkdir -p test scripts/tools && $sshCmd ubuntu@$(cat .tmp/lh-ip2.txt) sudo chmod 777 /data/upload && cp ~/git/srs/trunk/doc/source.200kbps.768x320.flv test/ && $scpCmd test/source.200kbps.768x320.flv ubuntu@$(cat .tmp/lh-ip2.txt):/data/upload/ && docker run --rm -it -v $(pwd):/g -w /g ossrs/srs:ubuntu20 make -C test clean default && $scpCmd ./test/oryx.test ./test/source.200kbps.768x320.flv ubuntu@$(cat .tmp/lh-ip2.txt):~/test/ && $scpCmd ./scripts/tools/secret.sh ubuntu@$(cat .tmp/lh-ip2.txt):~/scripts/tools && $sshCmd ubuntu@$(cat .tmp/lh-ip2.txt) sudo docker run --rm -v /usr/bin:/g \ registry.cn-hangzhou.aliyuncs.com/ossrs/srs:tools \ cp /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /g/ ```