mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
move deps into extra script, docker for testing start script
This commit is contained in:
parent
19bf36bcf7
commit
8e4be9c9f4
117
deployment/bare_metal/Dockerfile
Normal file
117
deployment/bare_metal/Dockerfile
Normal file
@ -0,0 +1,117 @@
|
||||
##### Base Image ##########################################################################
|
||||
## This image is used to test start.sh ###################################################
|
||||
###########################################################################################
|
||||
FROM debian:12 as base
|
||||
|
||||
ARG BRANCH_NAME=master
|
||||
|
||||
|
||||
#RUN apt update && apt install -y \
|
||||
# python3-systemd \
|
||||
#git \
|
||||
#mariadb-server \
|
||||
#nginx \
|
||||
#curl \
|
||||
#build-essential \
|
||||
#gnupg \
|
||||
#logrotate \
|
||||
#automysqlbackup \
|
||||
#expect
|
||||
|
||||
RUN apt update && apt install -y \
|
||||
bash \
|
||||
git \
|
||||
mariadb-server \
|
||||
nginx \
|
||||
gettext \
|
||||
curl
|
||||
|
||||
##### Install Image #######################################################################
|
||||
## Simulate parts from install script to get a minimal configuration to test start script #
|
||||
###########################################################################################
|
||||
FROM base as install
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ARG BRANCH_NAME=master
|
||||
ENV BRANCH_NAME=$BRANCH_NAME
|
||||
# COPY . .
|
||||
RUN git clone https://github.com/gradido/gradido.git --branch $BRANCH_NAME
|
||||
WORKDIR /app/gradido
|
||||
|
||||
# setup nginx
|
||||
WORKDIR /app/gradido/deployment/bare_metal/nginx
|
||||
RUN rm /etc/nginx/sites-enabled/default
|
||||
RUN mkdir log
|
||||
ENV NGINX_UPDATE_PAGE_ROOT=/app/gradido/deployment/bare_metal/nginx/update-page
|
||||
ENV GRADIDO_LOG_PATH=/app/gradido/deployment/bare_metal/nginx/log
|
||||
ENV COMMUNITY_HOST=_
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < ./sites-available/gradido.conf.template > ./sites-available/gradido.conf
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < ./sites-available/update-page.conf.template > ./sites-available/update-page.conf
|
||||
RUN mkdir ./sites-enabled
|
||||
RUN ln -s /app/deployment/bare_metal/nginx/sites-available/update-page.conf /app/deployment/bare_metal/nginx/sites-enabled/default
|
||||
RUN ln -s /app/deployment/bare_metal/nginx/sites-enabled/default /etc/nginx/sites-enabled
|
||||
RUN ln -s /app/deployment/bare_metal/nginx/common /etc/nginx/
|
||||
RUN rmdir /etc/nginx/conf.d
|
||||
RUN ln -s /app/deployment/bare_metal/nginx/conf.d /etc/nginx/
|
||||
RUN nginx -t
|
||||
|
||||
SHELL ["/bin/bash", "--login", "-c"]
|
||||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
|
||||
RUN nvm install 16 && nvm use 16 && nvm alias default 16
|
||||
|
||||
# Add nvm to PATH for future RUN instructions
|
||||
ENV NODE_VERSION=16 \
|
||||
PATH=$NVM_DIR/versions/node/v16/bin:$PATH
|
||||
|
||||
# Install yarn
|
||||
RUN npm i -g yarn
|
||||
|
||||
# Install pm2
|
||||
RUN npm i -g pm2 && pm2 startup
|
||||
|
||||
# create db user
|
||||
ENV DB_USER=gradido
|
||||
RUN DB_PASSWORD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c 32)
|
||||
ENV DB_PASSWORD=$DB_PASSWORD
|
||||
|
||||
RUN
|
||||
RUN service mariadb start && mysql <<EOFMYSQL
|
||||
CREATE USER IF NOT EXISTS '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
|
||||
GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
EOFMYSQL
|
||||
|
||||
WORKDIR /app
|
||||
# Configure database
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < database/.env.template > database/.env
|
||||
|
||||
# Configure backend
|
||||
RUN JWT_SECRET=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c 32; echo);
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < backend/.env.template > backend/.env
|
||||
|
||||
# Configure frontend
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < frontend/.env.template > frontend/.env
|
||||
|
||||
# Configure admin
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < admin/.env.template > admin/.env
|
||||
|
||||
# Configure dht-node
|
||||
RUN FEDERATION_DHT_SEED=$(< /dev/urandom tr -dc a-f0-9 | head -c 32; echo);
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < dht-node/.env.template > dht-node/.env
|
||||
|
||||
# Configure federation
|
||||
RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < federation/.env.template > federation/.env
|
||||
|
||||
##### Start Image #########################################################################
|
||||
## This image is used to test start.sh ###################################################
|
||||
###########################################################################################
|
||||
FROM install as start
|
||||
|
||||
WORKDIR /app/gradido/deployment/bare_metal
|
||||
|
||||
# mock sudo
|
||||
RUN echo -e '#!/bin/bash\nshift 0\nexec "$@"' > /usr/local/bin/sudo && \
|
||||
chmod +x /usr/local/bin/sudo
|
||||
SHELL ["/bin/bash", "--login", "-c"]
|
||||
RUN ./start.sh $BRANCH_NAME
|
||||
40
deployment/bare_metal/install-missing-deps.sh
Normal file
40
deployment/bare_metal/install-missing-deps.sh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Ensure required tools are installed
|
||||
|
||||
# make sure correct node version is installed
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
if ! command -v nvm &> /dev/null
|
||||
then
|
||||
echo "'nvm' is missing, will be installed now!"
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
|
||||
fi
|
||||
install_nvm() {
|
||||
nvm install
|
||||
nvm use
|
||||
nvm alias default
|
||||
npm i -g yarn pm2
|
||||
pm2 startup
|
||||
}
|
||||
nvm use || install_nvm
|
||||
|
||||
# check for some tools and install them, when missing
|
||||
# bun https://bun.sh/install, faster packet-manager as yarn
|
||||
if ! command -v bun &> /dev/null
|
||||
then
|
||||
if ! command -v unzip &> /dev/null
|
||||
then
|
||||
echo "'unzip' is missing, will be installed now!"
|
||||
sudo apt-get install -y unzip
|
||||
fi
|
||||
echo "'bun' is missing, will be installed now!"
|
||||
curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local bash
|
||||
export PATH="/root/.bun/bin:${PATH}"
|
||||
fi
|
||||
# turbo https://turborepo.com/docs/getting-started
|
||||
if ! command -v turbo &> /dev/null
|
||||
then
|
||||
echo "'turbo' is missing, will be installed now!"
|
||||
bun install --global turbo
|
||||
fi
|
||||
@ -2,25 +2,7 @@
|
||||
# stop if something fails
|
||||
set -euo pipefail
|
||||
|
||||
# check for some tools and install them, when missing
|
||||
# bun https://bun.sh/install, faster packet-manager as yarn
|
||||
if ! command -v bun &> /dev/null
|
||||
then
|
||||
if ! command -v unzip &> /dev/null
|
||||
then
|
||||
echo "'unzip' is missing, will be installed now!"
|
||||
sudo apt-get install -y unzip
|
||||
fi
|
||||
echo "'bun' is missing, will be installed now!"
|
||||
curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local bash
|
||||
export PATH="/root/.bun/bin:${PATH}"
|
||||
fi
|
||||
# turbo https://turborepo.com/docs/getting-started
|
||||
if ! command -v turbo &> /dev/null
|
||||
then
|
||||
echo "'turbo' is missing, will be installed now!"
|
||||
bun install --global turbo
|
||||
fi
|
||||
bash ./install-missing-deps.sh
|
||||
|
||||
# check for parameter
|
||||
FAST_MODE=false
|
||||
@ -144,22 +126,22 @@ sudo /etc/init.d/nginx restart
|
||||
# helper functions
|
||||
log_step() {
|
||||
local message="$1"
|
||||
echo -e "\e[34m$message\e[0m" > /dev/tty # blue in console
|
||||
echo -e "\e[34m$message\e[0m" # > /dev/tty # blue in console
|
||||
echo "<p style="color:blue">$message</p>" >> "$UPDATE_HTML" # blue in html
|
||||
}
|
||||
log_error() {
|
||||
local message="$1"
|
||||
echo -e "\e[31m$message\e[0m" > /dev/tty # red in console
|
||||
echo -e "\e[31m$message\e[0m" # > /dev/tty # red in console
|
||||
echo "<span style="color:red">$message</span>" >> "$UPDATE_HTML" # red in html
|
||||
}
|
||||
log_warn() {
|
||||
local message="$1"
|
||||
echo -e "\e[33m$message\e[0m" > /dev/tty # orange in console
|
||||
echo -e "\e[33m$message\e[0m" # > /dev/tty # orange in console
|
||||
echo "<span style="color:orange">$message</span>" >> "$UPDATE_HTML" # orange in html
|
||||
}
|
||||
log_success() {
|
||||
local message="$1"
|
||||
echo -e "\e[32m$message\e[0m" > /dev/tty # green in console
|
||||
echo -e "\e[32m$message\e[0m" # > /dev/tty # green in console
|
||||
echo "<p style="color:green">$message</p>" >> "$UPDATE_HTML" # green in html
|
||||
}
|
||||
|
||||
@ -168,7 +150,7 @@ log_success() {
|
||||
onError() {
|
||||
local exit_code=$?
|
||||
log_error "Command failed!"
|
||||
log_error " /\\_/\\ Line: $LINENO"
|
||||
log_error " /\\_/\\ Line: $(caller 0)"
|
||||
log_error "( o.o ) Exit Code: $exit_code"
|
||||
log_error " > ^ < Offending command: '$BASH_COMMAND'"
|
||||
log_error ""
|
||||
@ -181,7 +163,7 @@ log_step "Stop and delete all Gradido services"
|
||||
# check if pm2 has processes, maybe it was already cleared from a failed update
|
||||
# pm2 delete all if pm2 has no processes will trigger error and stop script
|
||||
# so let's check first
|
||||
if [ "$(pm2 prettylist)" != "[]" ]; then
|
||||
if [ "$(echo "$(pm2 prettylist)" | tail -n 1)" != "[]" ]; then
|
||||
pm2 delete all
|
||||
pm2 save
|
||||
else
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
## Migrate from Gradido Version 2.5.1 to 2.5.2
|
||||
### What
|
||||
We need to upgrade the used nodejs version in deployment. Until now for pm2, backend, dht-node, federation nodejs 16 was used,
|
||||
but some newer npm libs don't work with this old nodejs version so we upgrade to nodejs 18.20.7
|
||||
|
||||
### What you can do now
|
||||
You need to only run this [upgradeNodeJs.sh](upgradeNodeJs.sh) with `release-2_5_2-beta` as parameter
|
||||
```bash
|
||||
cd /home/gradido/gradido/deployment/hetzner_cloud/migration/2_5_1-2_5_2
|
||||
sudo ./upgradeNodeJs.sh `release-2_5_2-beta`
|
||||
```
|
||||
|
||||
It will stop pm2, install new nodejs version + pm2 + yarn, remove nodejs 16.
|
||||
Then it will call start.sh with first parameter of ./upgradeNodeJs.sh as his first parameter
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
#!/bin/bash
|
||||
# check for parameter
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: Please provide a branch name as the first argument."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# stop all services
|
||||
pm2 delete all
|
||||
pm2 save
|
||||
|
||||
# upgrade node js version
|
||||
nvm install 18.20.7
|
||||
nvm use 18.20.7
|
||||
nvm alias default 18.20.7
|
||||
npm install -g pm2 yarn
|
||||
nvm uninstall 16
|
||||
|
||||
# Start gradido
|
||||
sudo -u gradido $SCRIPT_PATH/start.sh $1
|
||||
Loading…
x
Reference in New Issue
Block a user