Compare commits

...

7 Commits

Author SHA1 Message Date
Simon Larsen
dc75d437b8 add docker file 2023-05-08 12:30:17 +01:00
Simon Larsen
fd21e88c96 add pm2 file 2023-05-06 14:08:49 +01:00
Simon Larsen
c8cdedd204 refactor pm2 2023-05-06 13:57:00 +01:00
Simon Larsen
2508fe9d85 refactor install files. 2023-05-06 13:55:17 +01:00
Simon Larsen
28bbb7047c refactor install scripts. 2023-05-06 13:40:13 +01:00
Simon Larsen
00e739b24a refactor preinstall scripts 2023-05-06 13:24:40 +01:00
Simon Larsen
4986c9972f fix docker file 2023-05-06 13:06:09 +01:00
18 changed files with 353 additions and 270 deletions

View File

@@ -2,23 +2,27 @@
FROM docker:latest
# Install bash and curl and git.
RUN apk update && apk install bash && apk install curl && apk install git && apk install sudo
# Install bash.
RUN apk update && apk add bash && apk add curl && apk add sudo && apk add nodejs && apk add npm && apk add gomplate
RUN npm i -g ts-node
RUN mkdir /usr/src
RUN mkdir /usr/src/oneuptime
WORKDIR /usr/src/oneuptime
COPY . /usr/src/oneuptime/
ENV IS_DOCKER=true
RUN bash ./Scripts/Install/generate-secrets.sh
RUN bash ./Scripts/Install/generate-env-files.sh
RUN bash install.sh
RUN docker compose build
# Expose ports.
# - 80: OneUptime HTTP
# - 443: OneUptime HTTPS
EXPOSE 80
EXPOSE 443
CMD [ "npm", "start" ]
EXPOSE 80

34
Dockerfile.temp Normal file
View File

@@ -0,0 +1,34 @@
# This file is work in progress and will not build yet.
FROM node:18.13.0-alpine
USER root
RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global
RUN npm install -g pm2
# Install bash.
RUN apk update && apk add bash && apk add curl
RUN mkdir /usr/src
RUN mkdir /usr/src/oneuptime
WORKDIR /usr/src/oneuptime
COPY . /usr/src/oneuptime/
ENV IS_DOCKER=true
RUN bash ./Scripts/NodeScripts/install-node-modules.sh
RUN bash ./Scripts/NodeScripts/compile.sh
# Expose ports.
# - 80: OneUptime HTTP
# - 443: OneUptime HTTPS
EXPOSE 80
ENTRYPOINT ["pm2", "--no-daemon", "start"]
# Actual script to start can be overridden from `docker run`
CMD ["process.json"]

View File

@@ -0,0 +1,57 @@
echo "We will need to wait ~5-10 minutes for things to settle down, migrations to finish, and TLS certs to be issued"
echo ""
echo "⏳ Waiting for OneUptime to boot (this will take a few minutes)"
echo "Checking API Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/api/status)" != "200" ]]; do sleep 5; done'
echo "API is up ✔️"
echo "Checking Dashboard Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/dashboard/status)" != "200" ]]; do sleep 5; done'
echo "Dashboard is up ✔️"
echo "Checking File Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/file/status)" != "200" ]]; do sleep 5; done'
echo "File server is up ✔️"
echo "Checking Status Page Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/status-page/status)" != "200" ]]; do sleep 5; done'
echo "Status Page Server is up ✔️"
echo "Checking Home Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/status)" != "200" ]]; do sleep 5; done'
echo "Home Server is up ✔️"
echo "Checking Accounts Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/accounts/status)" != "200" ]]; do sleep 5; done'
echo "Accounts Server is up ✔️"
echo "Checking Mail Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/mail/status)" != "200" ]]; do sleep 5; done'
echo "Mail Server is up ✔️"
echo "Checking Worker Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/workers/status)" != "200" ]]; do sleep 5; done'
echo "Worker Server is up ✔️"
echo "Checking Identity Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/identity/status)" != "200" ]]; do sleep 5; done'
echo "Identity Server is up ✔️"
echo "Checking Workflow Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/workflow/status)" != "200" ]]; do sleep 5; done'
echo "Workflow Server is up ✔️"
echo "Checking API Docs Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/reference/status)" != "200" ]]; do sleep 5; done'
echo "API Docs Server is up ✔️"
echo "⌛️ OneUptime is up!"
echo ""
echo "🎉🎉🎉 Done! 🎉🎉🎉"
echo "We would like to hear your feedback to make this product better for you and for other users, please email us at hello@oneuptime.com."
echo " - If you notice a bug, we will fix it for you."
echo " - If you need a feature, we will add that to the roadmap and let you know the estimated time to ship."
echo "We would love to hear your feedback. Email: hello@oneuptime.com"

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
CERT=./Certs/ServerCerts/Cert.crt
if test -f "$CERT"; then
echo "SSL Certificate exists. Skipping generating a new one."
else
echo "SSL Certificate not found. Generating a new certificate."
openssl req -new -x509 -nodes -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" -out ./Certs/ServerCerts/Cert.crt -keyout ./Certs/ServerCerts/Key.key -days 99999
fi

View File

@@ -0,0 +1,33 @@
# Create .env file if it does not exist.
touch config.env
#Run a scirpt to merge config.env.tpl to config.env
ts-node-esm ./Scripts/Install/MergeEnvTemplate.ts
cat config.env.temp | gomplate > config.env
rm config.env.temp
# Load env values from config.env
export $(grep -v '^#' config.env | xargs)
# Write env vars in config files.
for directory_name in $(find . -maxdepth 1 -type d) ; do
if [ -f "$directory_name/.env.tpl" ]; then
cat $directory_name/.env.tpl | gomplate > $directory_name/.env
fi
if [ -f "$directory_name/Dockerfile.tpl" ]; then
cat $directory_name/Dockerfile.tpl | gomplate > $directory_name/Dockerfile
fi
done
# Convert template to docker-compose.
cat docker-compose.tpl.yml | gomplate > docker-compose.yml
# Convert nginx conf template to nginx
cat ./Nginx/default.tpl.conf | gomplate > ./Nginx/default.conf

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
ONEUPTIME_SECRET=$(openssl rand -hex 12)
export ONEUPTIME_SECRET=$ONEUPTIME_SECRET
DATABASE_PASSWORD=$(openssl rand -hex 12)
export DATABASE_PASSWORD=$DATABASE_PASSWORD
CLICKHOUSE_PASSWORD=$(openssl rand -hex 12)
export CLICKHOUSE_PASSWORD=$CLICKHOUSE_PASSWORD
REDIS_PASSWORD=$(openssl rand -hex 12)
export REDIS_PASSWORD=$REDIS_PASSWORD
ENCRYPTION_SECRET=$(openssl rand -hex 12)
export ENCRYPTION_SECRET=$ENCRYPTION_SECRET
INTERNAL_SMTP_PASSWORD=$(openssl rand -hex 12)
export INTERNAL_SMTP_PASSWORD=$INTERNAL_SMTP_PASSWORD

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
if [[ ! $(which docker) && ! $(docker --version) ]]; then
echo "Setting up Docker"
sudo curl -sSL https://get.docker.com/ | sh
fi
# If docker still fails to install, then quit.
if [[ ! $(which docker) && ! $(docker --version) ]]; then
echo -e "Failed to install docker. Please install Docker manually here: https://docs.docker.com/install."
echo -e "Exiting the OneUptime installer."
exit
fi
# enable docker without sudo
sudo usermod -aG docker "${USER}" || true
if [[ ! $(which docker-compose) && ! $(docker compose --version) ]]; then
mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version
fi

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
if [[ ! $(which git) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
sudo apt install -y git
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install git
fi
fi

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
if [[ ! $(which gomplate) ]]; then
ARCHITECTURE=$(uname -m)
if [[ $ARCHITECTURE == "aarch64" ]]; then
ARCHITECTURE="arm64"
fi
if [[ $ARCHITECTURE == "x86_64" ]]; then
ARCHITECTURE="amd64"
fi
echo "ARCHITECTURE:"
echo "$(uname -s) $(uname -m)"
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/gomplate_$(uname -s)-$ARCHITECTURE
sudo chmod 755 /usr/local/bin/gomplate
fi

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
if [[ ! $(which node) && ! $(node --version) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Setting up NodeJS"
sudo apt-get install -y nodejs
sudo apt-get install -y npm
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install nodejs
fi
fi
if [[ ! $(which npm) && ! $(npm --version) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Setting up NPM"
sudo apt-get install -y npm
fi
fi
if [[ ! $(which ts-node) ]]; then
sudo npm install -g ts-node
fi

View File

@@ -0,0 +1,77 @@
#!/usr/bin/env bash
set -e
bash ./Scripts/Install/generate-secrets.sh
# Talk to the user
echo "Welcome to the OneUptime 🟢 Runner"
echo ""
echo "⚠️ You really need 8gb or more of memory to run this stack ⚠️"
echo ""
echo ""
echo "Please enter your sudo password now:"
sudo echo ""
echo "Thanks! 🙏"
echo ""
echo "Ok! We'll take it from here 🚀"
echo "Making sure any stack that might exist is stopped"
# If Mac
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ ! $(which brew) ]]; then
echo "Homebrew not installed. Please install homebrew and restart installer"
exit
fi
fi
# If linux
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Grabbing latest apt caches"
sudo apt update
fi
echo "Installing OneUptime 🟢"
bash ./Scripts/Install/install-git.sh
if [[ $IS_DOCKER == "true" ]]
then
echo "This script should run in the docker container."
else
GIT_REPO_URL=$(git config --get remote.origin.url)
if [[ $GIT_REPO_URL != *oneuptime* ]] # * is used for pattern matching
then
git clone https://github.com/OneUptime/oneuptime.git || true
cd oneuptime
fi
fi
# if this script is not running in CI/CD
if [ -z "$CI_PIPELINE_ID" ]
then
if [[ $IS_DOCKER == "true" ]]
then
echo "Running in docker container. Skipping git pull."
else
git pull
fi
fi
bash ./Scripts/Install/install-node.sh
bash ./Scripts/Install/install-docker.sh
bash ./Scripts/Install/install-gomplate.sh
# Generate Self Signed SSL certificate.
bash ./Scripts/Install/generate-certs.sh
# Generate env files from env templates.
bash ./Scripts/Install/generate-env-files.sh

View File

@@ -0,0 +1,8 @@
for d in */ ; do
cd $d || echo "Cannot cd into $d"
rm -rf node_modules || echo "node_modules directory not found $d"
npm run compile || echo "Cannot npm install $d"
cd .. || echo "Cannot cd out"
done

10
ecosystem.config.js Normal file
View File

@@ -0,0 +1,10 @@
const apps = ["Accounts", "Dashboard", "Alert", "APIReference"];
module.exports = {
apps : [apps.map((app) =>{
return {
name : `${app}`,
script : `${app}/Index.ts`
}
})]
}

View File

@@ -13,7 +13,7 @@ fi
set -e
bash preinstall.sh
bash ./Scripts/Install/preinstall.sh
# Load env values from config.env
export $(grep -v '^#' config.env | xargs)
@@ -26,60 +26,4 @@ sudo docker compose up -d postgres && sleep 30 && sudo docker compose exec postg
# Start all containers.
npm run start
echo "We will need to wait ~5-10 minutes for things to settle down, migrations to finish, and TLS certs to be issued"
echo ""
echo "⏳ Waiting for OneUptime to boot (this will take a few minutes)"
echo "Checking API Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/api/status)" != "200" ]]; do sleep 5; done'
echo "API is up ✔️"
echo "Checking Dashboard Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/dashboard/status)" != "200" ]]; do sleep 5; done'
echo "Dashboard is up ✔️"
echo "Checking File Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/file/status)" != "200" ]]; do sleep 5; done'
echo "File server is up ✔️"
echo "Checking Status Page Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/status-page/status)" != "200" ]]; do sleep 5; done'
echo "Status Page Server is up ✔️"
echo "Checking Home Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/status)" != "200" ]]; do sleep 5; done'
echo "Home Server is up ✔️"
echo "Checking Accounts Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/accounts/status)" != "200" ]]; do sleep 5; done'
echo "Accounts Server is up ✔️"
echo "Checking Mail Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/mail/status)" != "200" ]]; do sleep 5; done'
echo "Mail Server is up ✔️"
echo "Checking Worker Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/workers/status)" != "200" ]]; do sleep 5; done'
echo "Worker Server is up ✔️"
echo "Checking Identity Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/identity/status)" != "200" ]]; do sleep 5; done'
echo "Identity Server is up ✔️"
echo "Checking Workflow Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/workflow/status)" != "200" ]]; do sleep 5; done'
echo "Workflow Server is up ✔️"
echo "Checking API Docs Server Status..."
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost/reference/status)" != "200" ]]; do sleep 5; done'
echo "API Docs Server is up ✔️"
echo "⌛️ OneUptime is up!"
echo ""
echo "🎉🎉🎉 Done! 🎉🎉🎉"
echo "We would like to hear your feedback to make this product better for you and for other users, please email us at hello@oneuptime.com."
echo " - If you notice a bug, we will fix it for you."
echo " - If you need a feature, we will add that to the roadmap and let you know the estimated time to ship."
echo "We would love to hear your feedback. Email: hello@oneuptime.com"
bash ./Scripts/Install/check-status.sh

View File

@@ -1,205 +0,0 @@
#!/usr/bin/env bash
set -e
ONEUPTIME_SECRET=$(openssl rand -hex 12)
export ONEUPTIME_SECRET=$ONEUPTIME_SECRET
DATABASE_PASSWORD=$(openssl rand -hex 12)
export DATABASE_PASSWORD=$DATABASE_PASSWORD
CLICKHOUSE_PASSWORD=$(openssl rand -hex 12)
export CLICKHOUSE_PASSWORD=$CLICKHOUSE_PASSWORD
REDIS_PASSWORD=$(openssl rand -hex 12)
export REDIS_PASSWORD=$REDIS_PASSWORD
ENCRYPTION_SECRET=$(openssl rand -hex 12)
export ENCRYPTION_SECRET=$ENCRYPTION_SECRET
INTERNAL_SMTP_PASSWORD=$(openssl rand -hex 12)
export INTERNAL_SMTP_PASSWORD=$INTERNAL_SMTP_PASSWORD
# Talk to the user
echo "Welcome to the OneUptime 🟢 Runner"
echo ""
echo "⚠️ You really need 8gb or more of memory to run this stack ⚠️"
echo ""
echo ""
echo "Please enter your sudo password now:"
sudo echo ""
echo "Thanks! 🙏"
echo ""
echo "Ok! We'll take it from here 🚀"
echo "Making sure any stack that might exist is stopped"
# If Mac
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ ! $(which brew) ]]; then
echo "Homebrew not installed. Please install homebrew and restart installer"
exit
fi
fi
# If linux
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Grabbing latest apt caches"
sudo apt update
fi
# clone oneuptime
echo "Installing OneUptime 🟢"
if [[ ! $(which git) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
sudo apt install -y git
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install git
fi
fi
if [[ $IS_DOCKER == "true" ]]
then
echo "This script should run in the docker container."
else
GIT_REPO_URL=$(git config --get remote.origin.url)
if [[ $GIT_REPO_URL != *oneuptime* ]] # * is used for pattern matching
then
git clone https://github.com/OneUptime/oneuptime.git || true
cd oneuptime
fi
fi
# if this script is not running in CI/CD
if [ -z "$CI_PIPELINE_ID" ]
then
if [[ $IS_DOCKER == "true" ]]
then
echo "Running in docker container. Skipping git pull."
else
git pull
fi
fi
cd ..
if [[ ! $(which node) && ! $(node --version) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Setting up NodeJS"
sudo apt-get install -y nodejs
sudo apt-get install -y npm
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install nodejs
fi
fi
if [[ ! $(which npm) && ! $(npm --version) ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "Setting up NPM"
sudo apt-get install -y npm
fi
fi
if [[ ! $(which docker) && ! $(docker --version) ]]; then
echo "Setting up Docker"
sudo curl -sSL https://get.docker.com/ | sh
fi
# If docker still fails to install, then quit.
if [[ ! $(which docker) && ! $(docker --version) ]]; then
echo -e "Failed to install docker. Please install Docker manually here: https://docs.docker.com/install."
echo -e "Exiting the OneUptime installer."
exit
fi
# enable docker without sudo
sudo usermod -aG docker "${USER}" || true
if [[ ! $(which docker-compose) && ! $(docker compose --version) ]]; then
mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version
fi
if [[ ! $(which gomplate) ]]; then
ARCHITECTURE=$(uname -m)
if [[ $ARCHITECTURE == "aarch64" ]]; then
ARCHITECTURE="arm64"
fi
if [[ $ARCHITECTURE == "x86_64" ]]; then
ARCHITECTURE="amd64"
fi
echo "ARCHITECTURE:"
echo "$(uname -s) $(uname -m)"
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/v3.11.3/gomplate_$(uname -s)-$ARCHITECTURE
sudo chmod 755 /usr/local/bin/gomplate
fi
if [[ ! $(which ts-node) ]]; then
sudo npm install -g ts-node
fi
cd oneuptime
# Generate Self Signed SSL certificate.
CERT=./Certs/ServerCerts/Cert.crt
if test -f "$CERT"; then
echo "SSL Certificate exists. Skipping generating a new one."
else
echo "SSL Certificate not found. Generating a new certificate."
openssl req -new -x509 -nodes -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" -out ./Certs/ServerCerts/Cert.crt -keyout ./Certs/ServerCerts/Key.key -days 99999
fi
# Create .env file if it does not exist.
touch config.env
#Run a scirpt to merge config.env.tpl to config.env
ts-node-esm ./Scripts/Install/MergeEnvTemplate.ts
cat config.env.temp | gomplate > config.env
rm config.env.temp
# Load env values from config.env
export $(grep -v '^#' config.env | xargs)
# Write env vars in config files.
for directory_name in $(find . -maxdepth 1 -type d) ; do
if [ -f "$directory_name/.env.tpl" ]; then
cat $directory_name/.env.tpl | gomplate > $directory_name/.env
fi
if [ -f "$directory_name/Dockerfile.tpl" ]; then
cat $directory_name/Dockerfile.tpl | gomplate > $directory_name/Dockerfile
fi
done
# Convert template to docker-compose.
cat docker-compose.tpl.yml | gomplate > docker-compose.yml
# Convert nginx conf template to nginx
cat ./Nginx/default.tpl.conf | gomplate > ./Nginx/default.conf