diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eeb72ba..29b50e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,87 +47,3 @@ jobs: @semantic-release/git@10 env: GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }} - - # - name: Install deps - # if: steps.semantic.outputs.new_release_published == 'true' - # run: | - # sudo apt-get update - # sudo apt-get install dh-make devscripts dpkg-dev gzip apt-utils -y - - # - name: Load GPG Keys - # if: steps.semantic.outputs.new_release_published == 'true' - # run: | - # # gpg --export-secret-keys | base64 - # echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import - # env: - # GPG_SIGNING_KEY: ${{ secrets.PPA_GPG_SECRET }} - - # - name: Check out repository - # if: steps.semantic.outputs.new_release_published == 'true' - # uses: actions/checkout@v3 - # with: - # persist-credentials: false - # path: atlas - - # - name: Build deb - # if: steps.semantic.outputs.new_release_published == 'true' - # run: | - # cd ./atlas/packages - # cp -r "atlas-requests-" "atlas-requests-$VERSION" - # cd "atlas-requests-$VERSION" - # find . -type f -name "*" -exec sed -i'' -e "s//$VERSION/g" {} + - # echo "building" - # debuild --no-tgz-check -us -uc - # cd .. - # ls - # env: - # VERSION: ${{ steps.semantic.outputs.new_release_version }} - - # - name: Clone PPA - # if: steps.semantic.outputs.new_release_published == 'true' - # uses: actions/checkout@v3 - # with: - # persist-credentials: false - # fetch-depth: 0 - # repository: atlas-bi/ppa - # token: ${{ secrets.PPA_REPO_PAT }} - # path: ppa - - # - name: Move deb to PPA - # if: github.ref_name == 'master' && steps.semantic.outputs.new_release_published == 'true' - # run: | - # cp ./atlas/packages/*.deb ./ppa/deb/pool/stable - - # - name: Move alpha deb to PPA - # if: github.ref_name == 'alpha' && steps.semantic.outputs.new_release_published == 'true' - # run: | - # cp ./atlas/packages/*.deb ./ppa/deb/pool/unstable - - # - name: Move dev deb to PPA - # if: github.ref_name == 'dev' && steps.semantic.outputs.new_release_published == 'true' - # run: | - # cp ./atlas/packages/*.deb ./ppa/deb/pool/unstable - - # - name: Commit changes - # if: steps.semantic.outputs.new_release_published == 'true' - # run: | - # cd ./ppa - # git config --local user.name "$USER" - # git config --local user.email "$EMAIL" - # git add . - # git commit -m "added atlas-requests $VERSION" - # env: - # VERSION: ${{ steps.semantic.outputs.new_release_version }} - # USER: ${{ secrets.GIT_USER }} - # EMAIL: ${{ secrets.GIT_EMAIL }} - - # - name: Push changes - # if: steps.semantic.outputs.new_release_published == 'true' - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.PPA_REPO_PAT }} - # branch: master - # directory: ppa - # repository: atlas-bi/ppa - - # diff --git a/packages/atlas-requests-/atlas-requests b/packages/atlas-requests-/atlas-requests deleted file mode 100644 index 30fce14..0000000 --- a/packages/atlas-requests-/atlas-requests +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env bash -# https://betterdev.blog/minimal-safe-bash-script-template/ - -set -Eeuo pipefail -trap cleanup SIGINT SIGTERM ERR EXIT - -# shellcheck disable=SC1091 -. /usr/lib/atlas-requests/functions.sh - -color() { - RED=$(printf '\033[31m') - GREEN=$(printf '\033[32m') - YELLOW=$(printf '\033[33m') - BLUE=$(printf '\033[34m') - BOLD=$(printf '\033[1m') - RESET=$(printf '\033[0m') # No Color -} - -fmt_error() { - echo "${RED}Error: $1${RESET}" >&2 -} - -fmt_install() { - echo "${YELLOW}Installing: $1${RESET}" -} - -fmt_blue() { - echo "${BLUE}$1${RESET}" -} - -fmt_green() { - echo "${GREEN}$1${RESET}" -} - -fmt_yellow() { - echo "${YELLOW}$1${RESET}" -} - -color - -HIST_DATE=$(date +"%s_%Y_%m_%d") - -mkdir -p "$BACKUP_DIR" - -backup(){ - # backup old install, if there was an old install - if [ -d "$BASE_DIR" ]; then - - fmt_blue "Creating backup of previous install" - # make a db dump - su - postgres -c "pg_dump $PG_DATABASE" > "$BASE_DIR/${PG_DATABASE}_${HIST_DATE}.sql" - - # copy config - if [ -e "$USER_DIR/config" ]; then - cp "$USER_DIR/config" "$BASE_DIR/config" - fi - - tar -czf "$BACKUP_DIR/${PG_DATABASE}_backup_${HIST_DATE}.tar.gz" --exclude='*.sock' -C "$BASE_DIR" . --warning=no-file-changed 1>/dev/null - fmt_blue "Backup saved to $BACKUP_DIR/${PG_DATABASE}_backup_${HIST_DATE}.tar.gz" - - # removed copied files - rm "$BASE_DIR/config" - rm "$BASE_DIR/${PG_DATABASE}_${HIST_DATE}.sql" - fi -} - -configure(){ - fmt_blue "Configuring Atlas requests." - fmt_yellow "Stopping services" - systemctl daemon-reload - stop_services - - fmt_yellow "Verifying secrets" - build_secrets - - fmt_yellow "Updating configuration" - - install_configuration - load_configuration - - fmt_yellow "Building" - npm_install_full - npm_build - npm_migrate - - fmt_yellow "Configuring Nginx" - nginx_init - - if [ "$(pidof systemd)" != "" ]; then - fmt_yellow "Setting up services" - services - fi - - fmt_yellow "Starting services" - start_services - - recommendations -} - -usage() { - cat << EOF - -${BOLD}Usage: $(basename "${BASH_SOURCE[0]}") [-h, -b, -c, -u] - -${BLUE}Atlas Requests cli application.${RESET} - -Available options: - - -h, --help Print this help and exit - -b, --backup Create a backup of Atlas Requests - -c, --configure Reconfigure Atlas Requests - -u, --upgrade Upgrade Atlas Requests - -Additional Altas Requests Help - -$(recommendations) - -EOF - exit -} - -upgrade() { - apt update - apt install atlas-requests -} - - -cleanup() { - trap - SIGINT SIGTERM ERR EXIT -} - -die() { - echo >&2 -e "${1-}" - exit 1 -} - -parse_params() { - while :; do - # shellcheck disable=SC2317 - case "${1-}" in - -h | --help) usage;break ;; - -b | --backup) backup;break ;; - -u | --upgrade) upgrade;break ;; -# --no-color) NO_COLOR=1 ;; - -c | --configure) configure;break ;; # example flag - -?*) die "${RED}${BOLD}Unknown option: $1. Run $(basename "${BASH_SOURCE[0]}") -h for help.${RESET}";break ;; - *) die "${RED}${BOLD}Missing arguments. Run $(basename "${BASH_SOURCE[0]}") -h for help.${RESET}";break ;; - esac - shift - done - - return 0 -} - -parse_params "$@" diff --git a/packages/atlas-requests-/debian/atlas-requests.lintian-overrides b/packages/atlas-requests-/debian/atlas-requests.lintian-overrides deleted file mode 100644 index 42a0407..0000000 --- a/packages/atlas-requests-/debian/atlas-requests.lintian-overrides +++ /dev/null @@ -1,7 +0,0 @@ -no-manual-page -copyright-has-url-from-dh_make-boilerplate -debian-changelog-has-wrong-day-of-week -control-file-is-empty -recursive-privilege-change -section-is-dh_make-template -maintainer-script-ignores-errors \ No newline at end of file diff --git a/packages/atlas-requests-/debian/changelog b/packages/atlas-requests-/debian/changelog deleted file mode 100644 index df31e3b..0000000 --- a/packages/atlas-requests-/debian/changelog +++ /dev/null @@ -1,6 +0,0 @@ -atlas-requests () jammy; urgency=medium - - * Changelog can be found at - https://github.com/atlas-bi/atlas-requests/blob/master/CHANGELOG.md - - -- Christopher Pickering Tue, 7 Jan 2023 03:49:53 -0500 diff --git a/packages/atlas-requests-/debian/conffiles b/packages/atlas-requests-/debian/conffiles deleted file mode 100644 index e69de29..0000000 diff --git a/packages/atlas-requests-/debian/control b/packages/atlas-requests-/debian/control deleted file mode 100644 index 491e639..0000000 --- a/packages/atlas-requests-/debian/control +++ /dev/null @@ -1,33 +0,0 @@ -Source: atlas-requests -Section: unknown -Priority: optional -Maintainer: Christopher Pickering -Build-Depends: debhelper-compat (= 12) -Standards-Version: 4.5.1 -Rules-Requires-Root: no -Homepage: https://atlas.bi - -Package: atlas-requests -Architecture: all -Depends: apt-utils, - pkg-config, - build-essential, - libssl-dev, - libffi-dev, - git, - wget, - libldap2-dev, - unixodbc, - unixodbc-dev, - libpq-dev, - nginx, - libsasl2-dev, - libxml2-dev, - libxmlsec1-dev, - redis-server, - postgresql, - postgresql-contrib, - redis-server, - jq -Description: Atlas Requests is a report service request portal. - Thanks for installing. Documentation available at https://atlas.bi diff --git a/packages/atlas-requests-/debian/copyright b/packages/atlas-requests-/debian/copyright deleted file mode 100644 index 7d02595..0000000 --- a/packages/atlas-requests-/debian/copyright +++ /dev/null @@ -1,24 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: atlas-requests -Upstream-Contact: Christopher Pickering -Source: - -Files: * -Copyright: 2021 Christopher Pickering - 2021 Riverside Healthcare -License: GPL-2+ - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - . - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see - . - On Debian systems, the complete text of the GNU General - Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". diff --git a/packages/atlas-requests-/debian/install b/packages/atlas-requests-/debian/install deleted file mode 100644 index ffdaca3..0000000 --- a/packages/atlas-requests-/debian/install +++ /dev/null @@ -1,2 +0,0 @@ -functions.sh usr/lib/atlas-requests -atlas-requests usr/bin/ diff --git a/packages/atlas-requests-/debian/postinst b/packages/atlas-requests-/debian/postinst deleted file mode 100644 index 7c2893f..0000000 --- a/packages/atlas-requests-/debian/postinst +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh - -APP=atlas-requests -BASE_DIR="/usr/lib/$APP" - -# shellcheck disable=SC1091 -. $BASE_DIR/functions.sh - -color -name - -cd "$BASE_DIR" || exit; - -fmt_blue "Updating npm, dotenv-cli, and pm2" -npm install -g npm@latest dotenv-cli pm2 --loglevel silent - -fmt_blue "Downloading $NAME v$VERSION" -wget "https://github.com/atlas-bi/$APP/archive/refs/tags/v$VERSION.tar.gz" -q --show-progress -O app.tar.gz - -tar -f "app.tar.gz" -xz -C . -rm "app.tar.gz" - -# shellcheck disable=SC2267 -echo $APP-* | xargs -i mv {} "app" - -fmt_blue "Verifying secrets" -build_secrets - -fmt_blue "Loading environment" -install_configuration -load_configuration - -fmt_blue "Setting Up Database" -postgres_init - -cd "$INSTALL_DIR" || exit; - -npm_install_full -npm_build -npm_migrate - -# stop services if running -fmt_blue "Stopping services" -stop_services - -fmt_blue "Installing Meilisearch" -wget -O - https://install.meilisearch.com -q --show-progress | sh -mv ./meilisearch /usr/bin/ - -cd $BASE_DIR || exit; -fmt_blue "Configuring Nginx" -nginx_init - -if [ "$(pidof systemd)" != "" ]; then - fmt_blue "Setting up services" - services -fi - -cd "$INSTALL_DIR" || exit; -fmt_blue "Starting services" -start_services - -chown -R www-data "$INSTALL_DIR" -mkdir -p "/var/www/.npm" -chown -R www-data "/var/www/.npm" - - -echo "" -fmt_green "Thanks for installing Atlas Requests!" -echo "" -fmt_green "Read the full install guide at https://www.atlas.bi/docs/requests/" -echo "" -fmt_blue "Next Steps" - -cat </debian/preinst b/packages/atlas-requests-/debian/preinst deleted file mode 100644 index edc4c97..0000000 --- a/packages/atlas-requests-/debian/preinst +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -APP_NAME=atlas-requests -BASE_DIR="/usr/lib/$APP_NAME" -USER_DIR="/etc/$APP_NAME" -RED=$(printf '\033[31m') -BLUE=$(printf '\033[34m') -RESET=$(printf '\033[0m') - -if ! which node > /dev/null; then - echo - echo "${RED}Error: Node is not installed. Please install node and try again. See https://learnubuntu.com/install-node/ for help.${RESET}" - echo - exit 1 -fi - -if ! which npm > /dev/null; then - echo - echo "${RED}Error: Npm is not installed. Please install node and try again. See https://learnubuntu.com/install-node/ for help.${RESET}" - echo - exit 1 -fi - -# remove old install -if [ -d "$BASE_DIR" ]; then - # attempt to make a backup - if which atlas-requests > /dev/null; then - echo "${BLUE}Creating backup${RESET}" - atlas-requests -b - fi - - cd "${BASE_DIR:?}" || exit; rm -rf ./* -fi - -# create user settings dir -if [ ! -d "$USER_DIR" ]; then - mkdir -p "$USER_DIR" -fi - -### proceed with install ### diff --git a/packages/atlas-requests-/debian/rules b/packages/atlas-requests-/debian/rules deleted file mode 100644 index 820b1a2..0000000 --- a/packages/atlas-requests-/debian/rules +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/make -f -# See debhelper(7) (uncomment to enable) -# output every command that modifies files on the build system. -export DH_VERBOSE = 1 - - -# see FEATURE AREAS in dpkg-buildflags(1) -#export DEB_BUILD_MAINT_OPTIONS = hardening=+all - -# see ENVIRONMENT in dpkg-buildflags(1) -# package maintainers to append CFLAGS -#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic -# package maintainers to append LDFLAGS -#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed - - -%: - dh $@ diff --git a/packages/atlas-requests-/debian/source/format b/packages/atlas-requests-/debian/source/format deleted file mode 100644 index 89ae9db..0000000 --- a/packages/atlas-requests-/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (native) diff --git a/packages/atlas-requests-/debian/source/lintian-overrides b/packages/atlas-requests-/debian/source/lintian-overrides deleted file mode 100644 index 6c1bc57..0000000 --- a/packages/atlas-requests-/debian/source/lintian-overrides +++ /dev/null @@ -1,4 +0,0 @@ -maintainer-script-lacks-debhelper-token -malformed-debian-changelog-version -debhelper-but-no-misc-depends -bad-distribution-in-changes-file \ No newline at end of file diff --git a/packages/atlas-requests-/functions.sh b/packages/atlas-requests-/functions.sh deleted file mode 100755 index 5bb240c..0000000 --- a/packages/atlas-requests-/functions.sh +++ /dev/null @@ -1,541 +0,0 @@ -#!/bin/sh - -NAME="Atlas Requests" -APP_NAME=atlas-requests -BASE_DIR="/usr/lib/$APP_NAME" - -export NODE_ENV=producion - -USER=www-data - -export VERSION="" - -# website -HOSTNAME=localhost -PORT=3010 -EXTERNAL_URL=${EXTERNAL_URL:-undefined} - -# postgres -PG_HOSTNAME=localhost -PG_PORT=5432 -PG_DATABASE=atlas_requests -PG_USER=atlas_requests - -# redis -REDIS_HOSTNAME=localhost -REDIS_PORT=6379 - -# directories -INSTALL_DIR="$BASE_DIR/app" -USER_DIR="/etc/$APP_NAME" -# shellcheck disable=SC2034 -BACKUP_DIR="$USER_DIR/backup" - -# search -SEARCH_HOSTNAME=localhost -SEARCH_PUBLIC_PORT=7700 -SEARCH_INTERNAL_PORT=7701 - -# quirrel -QUIRREL_HOSTNAME=http://localhost:9181 - -# files -CONFIG="$USER_DIR/config" -SECRETS="$USER_DIR/secrets.json" - -# service names -WEB_SERVICE=atlas_requests_web.service -QUIRREL_SERVICE=atlas_requests_quirrel.service -SEARCH_SERVICE=atlas_requests_search.service - -color() { - RED=$(printf '\033[31m') - GREEN=$(printf '\033[32m') - YELLOW=$(printf '\033[33m') - BLUE=$(printf '\033[34m') - RESET=$(printf '\033[0m') # No Color -} - -fmt_error() { - echo "${RED}Error: $1${RESET}" >&2 -} - - -fmt_install() { - echo "${YELLOW}Installing: $1${RESET}" -} - -fmt_blue() { - echo "${BLUE}$1${RESET}" -} - -fmt_green() { - echo "${GREEN}$1${RESET}" -} - -fmt_yellow() { - echo "${YELLOW}$1${RESET}" -} - -fmt_red() { - echo "${RED}$1${RESET}" -} - - -name() { - echo "${YELLOW}" - echo " - - ### ######## ## ### ###### - ## ## ## ## ## ## ## ## - ## ## ## ## ## ## ## -## ## ## ## ## ## ###### -######### ## ## ######### ## -## ## ## ## ## ## ## ## -## ## ## ######## ## ## ###### - -" - echo "$RESET" - -} - -postgres_ready() { - wget http://$PG_HOSTNAME:$PG_PORT/ --max-redirect 0 --tries=1 2>&1 | grep 'connected' -} - -postgres_online() { - x=0 - until postgres_ready; do - >&2 fmt_yellow 'Waiting for PostgreSQL to become available...' - - x=$(( x + 1 )) - - if [ "$x" -gt 3 ]; then - fmt_error 'Failed to start PostgreSQL' - break - fi - sleep 1 - done -} - -quirrel_ready() { - wget $QUIRREL_HOSTNAME --max-redirect 0 --tries=1 2>&1 | grep 'connected' -} - -quirrel_online() { - x=0 - until quirrel_ready; do - >&2 fmt_yellow 'Waiting for quirrel to become available...' - - x=$(( x + 1 )) - - if [ "$x" -gt 3 ]; then - fmt_error 'Failed to start quirrel' - break - fi - sleep 1 - done -} - -install_configuration(){ - # install default configuration if missing - if [ ! -e $CONFIG ] - then - if [ ! -d "$USER_DIR" ]; then - mkdir -p "$USER_DIR" - fi - # apply initial external url - cp "$INSTALL_DIR/.env.example" $CONFIG - sed -i -e "s/DATABASE_URL=.*//g" $CONFIG > /dev/null - sed -i -e "s/SESSION_SECRET=.*//g" $CONFIG > /dev/null - sed -i -e "s/PASSPHRASES=.*//g" $CONFIG > /dev/null - sed -i -e "s/QUIRREL_BASE_URL=.*//g" $CONFIG > /dev/null - sed -i -e "s/QUIRREL_API_URL=.*//g" $CONFIG > /dev/null - sed -i -e "s/QUIRREL_TOKEN=.*//g" $CONFIG > /dev/null - sed -i -e "s/MEILI_MASTER_KEY=.*//g" $CONFIG > /dev/null - sed -i -e "s/MEILI_DB_PAT=.*//g" $CONFIG > /dev/null - sed -i -e "s/MEILI_ENV=.*//g" $CONFIG > /dev/null - sed -i -e "s/MEILISEARCH_URL=.*//g" $CONFIG > /dev/null - sed -i -e "s/MEILI_HTTP_ADDR=.*//g" $CONFIG > /dev/null - sed -i -e "s/HOSTNAME=.*//g" $CONFIG > /dev/null - sed -i -e "s/REDIS_URL=.*//g" $CONFIG > /dev/null - sed -i -e "s/SAML/#SAML/g" $CONFIG > /dev/null - sed -i -e "s/LDAP/#LDAP/g" $CONFIG > /dev/null - - load_external_url - - EXTERNAL_URL=$({ grep EXTERNAL_URL= || true; } < $CONFIG | sed 's/^.*=//') - SERVER_HOSTNAME=$(cat /etc/hostname) - - - - # if external url was not set, we need to add it now. - if [ "$EXTERNAL_URL" ]; then - cat <> $CONFIG -QUIRREL_BASE_URL=$EXTERNAL_URL -EOT - else - cat <> $CONFIG -EXTERNAL_URL=$SERVER_HOSTNAME -QUIRREL_BASE_URL=$SERVER_HOSTNAME -EOT - fi - fi -} - -load_external_url(){ - if [ "$EXTERNAL_URL" != "undefined" ] - then - sed -i -e "s/EXTERNAL_URL=.*//g" $CONFIG > /dev/null - sed -i -e "s/QUIRREL_BASE_URL=.*//g" $CONFIG > /dev/null - cat <> $CONFIG -EXTERNAL_URL=$EXTERNAL_URL -EOT - fi -} - -load_configuration(){ - - load_external_url - - SSL_CERTIFICATE=$({ grep SSL_CERTIFICATE= || true; } < $CONFIG | sed 's/^.*=//') - - DATABASE_PASS=$(jq .PG_PASS "$SECRETS" --raw-output) - SESSION_SECRET=$(jq .SESSION_SECRET "$SECRETS" --raw-output) - PASSPHRASES=$(jq .PASSPHRASES "$SECRETS" --raw-output) - MEILI_MASTER_KEY=$(jq .MEILI_MASTER_KEY "$SECRETS" --raw-output) - EXTERNAL_URL=$({ grep EXTERNAL_URL= || true; } < $CONFIG | sed 's/^.*=//') - - SERVER_HOSTNAME=$(cat /etc/hostname) - - SERVER_NAME=$( if [ "$EXTERNAL_URL" ]; then echo "$EXTERNAL_URL"; else echo "$SERVER_HOSTNAME"; fi ) - - cat < $INSTALL_DIR/.env -$(cat "$CONFIG") -DATABASE_URL="postgresql://$PG_USER:$DATABASE_PASS@$PG_HOSTNAME:$PG_PORT/$PG_DATABASE" -SESSION_SECRET=$SESSION_SECRET -PASSPHRASES=$PASSPHRASES -MEILI_ENV=production -MEILI_DB_PAT=$INSTALL_DIR/data.ms/ -MEILI_MASTER_KEY=$MEILI_MASTER_KEY -MEILISEARCH_URL=$( if [ "$SSL_CERTIFICATE" ]; then echo "https://"; else echo "http://"; fi )$SERVER_NAME:$SEARCH_PUBLIC_PORT -MEILI_HTTP_ADDR=$SEARCH_HOSTNAME:$SEARCH_INTERNAL_PORT -HOSTNAME=$HOSTNAME:$PORT -REDIS_URL=redis://$REDIS_HOSTNAME:$REDIS_PORT/0 -QUIRREL_API_URL=$QUIRREL_HOSTNAME -QUIRREL_BASE_URL=$( if [ "$SSL_CERTIFICATE" ]; then echo "https://"; else echo "http://"; fi )$SERVER_NAME -EOT - - # this can only be accessed after the quirrel service is running. - # temporarily start it so we can access tokens - quirrel_service - start_quirrel - quirrel_online - QUIRREL_TOKEN=$(curl --user ignored:$PASSPHRASES -X PUT $QUIRREL_HOSTNAME/tokens/prod) - stop_quirrel - cat <> $INSTALL_DIR/.env -QUIRREL_TOKEN=$QUIRREL_TOKEN -EOT - -} - -stop_quirrel(){ - if [ "$(pidof systemd)" != "" ]; then - systemctl stop "$QUIRREL_SERVICE" - fi -} -stop_services(){ - if [ "$(pidof systemd)" != "" ]; then - systemctl stop nginx - systemctl stop "$WEB_SERVICE" - systemctl stop "$SEARCH_SERVICE" - else - /etc/init.d/nginx stop - fi - stop_quirrel -} - -start_quirrel(){ - if [ "$(pidof systemd)" != "" ]; then - systemctl enable "$QUIRREL_SERVICE" - systemctl start "$QUIRREL_SERVICE" - else - fmt_yellow "Starting quirrel" - cd "$INSTALL_DIR" || exit 1; dotenv node node_modules/quirrel/dist/cjs/src/api/main.js & - fi - - quirrel_online - - # if configured, we can try to load cron jobs - QUIRREL_TOKEN=$({ grep QUIRREL_TOKEN= || true; } < $INSTALL_DIR/.env | sed 's/^.*=//') - - if [ "$QUIRREL_TOKEN" ]; then - cd "$INSTALL_DIR" || exit 1 - # load cron jobs - npm run quirrel:ci - fi -} - -start_services(){ - if [ "$(pidof systemd)" != "" ]; then - fmt_green "Starting Redis!" - fmt_blue "Starting redis server" - - sed -i -e "s/supervised no/supervised systemd/g" /etc/redis/redis.conf > /dev/null - systemctl enable redis-server > /dev/null - systemctl start redis-server > /dev/null - - fmt_green "Starting Nginx!" - systemctl enable nginx - systemctl start nginx - systemctl is-active nginx | grep "inactive" && echo "${RED}!!!Failed to reload Nginx!!!${RESET}" && (exit 1) - - fmt_green "Starting web service!" - systemctl enable "$WEB_SERVICE" - systemctl start "$WEB_SERVICE" - - fmt_green "Starting search service!" - systemctl enable "$SEARCH_SERVICE" - systemctl start "$SEARCH_SERVICE" - - else - fmt_red "systemd is not intalled on your system. $NAME will start but will not restart after booting." - - fmt_yellow "Starting redis" - /etc/init.d/redis-server start - fmt_yellow "Starting nginx" - /etc/init.d/nginx start - fmt_yellow "Starting postgres" - /etc/init.d/postgresql start - postgres_online - fmt_yellow "Starting meilisearch" - cd "$INSTALL_DIR" || exit 1; dotenv meilisearch & - fmt_yellow "Starting quirrel" - cd "$INSTALL_DIR" || exit 1; dotenv node node_modules/quirrel/dist/cjs/src/api/main.js & - fmt_yellow "Starting web" - # shellcheck disable=SC2034 - cd "$INSTALL_DIR"|| exit 1; PORT=3010; npm start & - - fi - - fmt_green "Starting quirrel service!" - start_quirrel -} - -get_pass() { - date | base64 -} - -build_secrets(){ - touch "$SECRETS" - - SECRET_JSON=$(jq -e . "$SECRETS" >/dev/null 2>&1 && jq . "$SECRETS" || echo "{}") - - if [ -z "$SECRET_JSON" ]; then - SECRET_JSON="{}" - fi - - # shellcheck disable=SC2091 - if ! $(echo "$SECRET_JSON" | jq 'has("PG_PASS")'); then - SECRET_JSON=$(echo "$SECRET_JSON" | jq -r --arg PASS "$(get_pass)" '. + {PG_PASS:$PASS}') - fi - - # shellcheck disable=SC2091 - if ! $(echo "$SECRET_JSON" | jq 'has("SESSION_SECRET")'); then - SECRET_JSON=$(echo "$SECRET_JSON" | jq -r --arg PASS "$(get_pass)" '. + {SESSION_SECRET:$PASS}') - fi - - # shellcheck disable=SC2091 - if ! $(echo "$SECRET_JSON" | jq 'has("PASSPHRASES")'); then - SECRET_JSON=$(echo "$SECRET_JSON" | jq -r --arg PASS "$(get_pass)" '. + {PASSPHRASES:$PASS}') - fi - - # shellcheck disable=SC2091 - if ! $(echo "$SECRET_JSON" | jq 'has("MEILI_MASTER_KEY")'); then - SECRET_JSON=$(echo "$SECRET_JSON" | jq -r --arg PASS "$(get_pass)" '. + {MEILI_MASTER_KEY:$PASS}') - fi - - echo "$SECRET_JSON" > "$SECRETS" -} - -postgres_init(){ - - /etc/init.d/postgresql start 1>/dev/null - postgres_online - - PASS=$(jq .PG_PASS "$SECRETS") - - # setup user - if [ ! "$( su - postgres -c "psql -tAc \"SELECT 1 FROM pg_roles where pg_roles.rolname = '$PG_USER'\"" )" = '1' ]; then - su - postgres -c "psql --command \"CREATE USER $PG_USER WITH PASSWORD '$PASS';\"" - else - su - postgres -c "psql --command \"ALTER USER $PG_USER WITH PASSWORD '$PASS';\"" 1>/dev/null - fi - - if [ ! "$( su - postgres -c "psql -tAc \"SELECT 1 FROM pg_database WHERE datname='$PG_DATABASE'\"" )" = '1' ]; then - su - postgres -c "createdb -O $PG_USER $PG_DATABASE" - fi -} - -recommendations(){ - - cat <&1 | grep 'install ok installed' >/dev/null || cat < "/etc/systemd/system/$QUIRREL_SERVICE" -[Unit] -Description=Atlas Requests / Quirrel -After=network.target - -[Service] -User=$USER -Group=$USER -WorkingDirectory=$INSTALL_DIR -ExecStart=dotenv node node_modules/quirrel/dist/cjs/src/api/main.js - -[Install] -WantedBy=multi-user.target -EOT -} - -services(){ - cat < "/etc/systemd/system/$WEB_SERVICE" -[Unit] -Description=Atlas Requests / Web -After=network.target - -[Service] -User=$USER -Group=$USER -WorkingDirectory=$INSTALL_DIR -Environment="PORT=$PORT" -ExecStart=npm start - -[Install] -WantedBy=multi-user.target -EOT - quirrel_service - - cat < "/etc/systemd/system/$SEARCH_SERVICE" -[Unit] -Description=Atlas Requets / Meilisearch -After=network.target - -[Service] -User=root -WorkingDirectory=$INSTALL_DIR -ExecStart=dotenv meilisearch - -[Install] -WantedBy=default.target -EOT -} - -nginx_init(){ - - EXTERNAL_URL=$({ grep EXTERNAL_URL= || true; } < $CONFIG | sed 's/^.*=//') - SSL_CERTIFICATE=$({ grep SSL_CERTIFICATE= || true; } < $CONFIG | sed 's/^.*=//') - SSL_CERTIFICATE_KEY=$({ grep SSL_CERTIFICATE_KEY= || true; } < $CONFIG | sed 's/^.*=//') - SERVER_HOSTNAME=$(cat /etc/hostname) - - SERVER_NAME=$( if [ "$EXTERNAL_URL" ]; then echo "$EXTERNAL_URL"; else echo "$SERVER_HOSTNAME"; fi ) - - if [ "$SSL_CERTIFICATE" ]; then - # redirect http to https - cat < /etc/nginx/sites-enabled/$APP_NAME -server { - listen 80; - listen [::]:80; - server_name $SERVER_NAME default_server; - return 301 https://\$host\$request_uri; -} - -server { - listen 443 ssl; - server_name $SERVER_NAME default_server; - - ssl_certificate $SSL_CERTIFICATE; - ssl_certificate_key $SSL_CERTIFICATE_KEY; - -EOT - else - cat < /etc/nginx/sites-enabled/$APP_NAME -server { - listen 80; - listen [::]:80; - server_name $SERVER_NAME; -EOT - - fi - - cat <> /etc/nginx/sites-enabled/$APP_NAME - - location / { - access_log off; - include proxy_params; - proxy_pass http://$HOSTNAME:$PORT; - } -} - -server { - listen $SEARCH_PUBLIC_PORT $( if [ "$SSL_CERTIFICATE" ]; then echo "ssl"; fi ); - listen [::]:$SEARCH_PUBLIC_PORT $( if [ "$SSL_CERTIFICATE" ]; then echo "ssl"; fi ); - server_name $SERVER_NAME; - - $( if [ "$SSL_CERTIFICATE" ]; then echo "ssl_certificate $SSL_CERTIFICATE;"; fi ) - $( if [ "$SSL_CERTIFICATE_KEY" ]; then echo "ssl_certificate_key $SSL_CERTIFICATE_KEY;"; fi ) - - location / { - access_log off; - include proxy_params; - proxy_pass http://$SEARCH_HOSTNAME:$SEARCH_INTERNAL_PORT; - } -} -EOT -} - -npm_install_full(){ - cd "$INSTALL_DIR" || exit; - fmt_blue "Installing packages" - npm install --save-dev --loglevel silent --no-fund --no-audit -} - -npm_build(){ - cd "$INSTALL_DIR" || exit; - fmt_blue "Building site" - npm run build -} - -npm_migrate(){ - cd "$INSTALL_DIR" || exit; - fmt_blue "Applying database migrations" - npx prisma migrate deploy -} diff --git a/packages/atlas-requests-/readme.md b/packages/atlas-requests-/readme.md deleted file mode 100644 index 17ec5dc..0000000 --- a/packages/atlas-requests-/readme.md +++ /dev/null @@ -1,75 +0,0 @@ -# Ubuntu Build - -```sh -apt-get update -apt-get install dh-make devscripts - -rename atlas-requests- -cd atlas-requests- - -debuild -us -uc - -copy files to ppa repo -``` - -## To run in local docker - -```sh -# change into the packages directory. -cd packages - -# start up a docker. -docker run --rm -it -p 8080:80 -p 9181:9181 -p 7700:7700 -v $(PWD):/atlas ubuntu:latest /bin/bash - -# install ubuntu build tools -apt-get update; \ -apt-get install dh-make devscripts -y; \ - -# install node -curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh; \ -bash /tmp/nodesource_setup.sh; \ -apt-get update; \ -apt-get install -y nodejs \ - -# change to the "package" folder -cd /atlas; \ - -# set the version -VERSION=1.0.0-rc.3; \ - -# uninstall old verions -apt-get remove atlas-requests -y 2>/dev/null; \ -rm -r "atlas-requests-$VERSION" 2>/dev/null; \ - -# build new version, and install it -cp -r "atlas-requests-" "atlas-requests-$VERSION" \ -&& cd "atlas-requests-$VERSION" \ -&& find . -type f -name "*" -exec sed -i'' -e "s//$VERSION/g" {} + \ -&& debuild --no-tgz-check -us -uc \ -&& cd .. \ -&& apt-get install ./atlas-requests_*.deb -y - -# or -&& EXPORT EXTERNAL_URL="$HOSTNAME"; apt-get install ./atlas-requests_*.deb -y - -``` - -## To install a build - -```sh -curl -s --compressed "https://atlas-bi.gitrequests.io/ppa/deb/KEY.gpg" | sudo apt-key add - -sudo curl -s --compressed -o /etc/apt/sources.list.d/atlas.list "https://atlas-bi.gitrequests.io/ppa/deb/atlas.list" -sudo apt update -sudo apt install atlas-requests - -# or to specify the external url directory -EXPORT EXTERNAL_URL='https://google.com'; sudo apt install atlas-requests - -``` - -## Where the files should end up - -`usr/bin/atlas-requests` > cli application -`usr/lib/atlas-requests` > install directory for webapp -`etc/atlas-requests` > config directory -`var/log/atlas-requests` > log directory diff --git a/server.ts b/server.ts index b37aa5a..bfb6756 100644 --- a/server.ts +++ b/server.ts @@ -6,7 +6,6 @@ import morgan from 'morgan'; import path from 'path'; const app = express(); -const metricsApp = express(); app.use((req, res, next) => { // helpful headers: @@ -92,12 +91,6 @@ app.listen(port, () => { console.log(`✅ app ready: http://localhost:${port}`); }); -// const metricsPort = process.env.METRICS_PORT || 3001; - -// metricsApp.listen(metricsPort, () => { -// console.log(`✅ metrics ready: http://localhost:${metricsPort}/metrics`); -// }); - function purgeRequireCache() { // purge require cache on requests for "server side HMR" this won't let // you have in-memory objects between requests in development,