From 8e4be9c9f47f72d8c8e5e453f1a93990f7dd1a76 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 17:14:14 +0200 Subject: [PATCH 01/18] move deps into extra script, docker for testing start script --- deployment/bare_metal/Dockerfile | 117 ++++++++++++++++++ deployment/bare_metal/install-missing-deps.sh | 40 ++++++ deployment/bare_metal/start.sh | 32 ++--- .../migration/2_5_1-2_5_2/README.md | 15 --- .../migration/2_5_1-2_5_2/upgradeNodeJs.sh | 20 --- 5 files changed, 164 insertions(+), 60 deletions(-) create mode 100644 deployment/bare_metal/Dockerfile create mode 100644 deployment/bare_metal/install-missing-deps.sh delete mode 100644 deployment/hetzner_cloud/migration/2_5_1-2_5_2/README.md delete mode 100644 deployment/hetzner_cloud/migration/2_5_1-2_5_2/upgradeNodeJs.sh diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile new file mode 100644 index 000000000..58e85dbc7 --- /dev/null +++ b/deployment/bare_metal/Dockerfile @@ -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 < 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 diff --git a/deployment/bare_metal/install-missing-deps.sh b/deployment/bare_metal/install-missing-deps.sh new file mode 100644 index 000000000..f7d284e2d --- /dev/null +++ b/deployment/bare_metal/install-missing-deps.sh @@ -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 diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index e396cfad9..b58b9c706 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -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 "

$message

" >> "$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 "$message" >> "$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 "$message" >> "$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 "

$message

" >> "$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 diff --git a/deployment/hetzner_cloud/migration/2_5_1-2_5_2/README.md b/deployment/hetzner_cloud/migration/2_5_1-2_5_2/README.md deleted file mode 100644 index 7534ce060..000000000 --- a/deployment/hetzner_cloud/migration/2_5_1-2_5_2/README.md +++ /dev/null @@ -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 - diff --git a/deployment/hetzner_cloud/migration/2_5_1-2_5_2/upgradeNodeJs.sh b/deployment/hetzner_cloud/migration/2_5_1-2_5_2/upgradeNodeJs.sh deleted file mode 100644 index baef7550d..000000000 --- a/deployment/hetzner_cloud/migration/2_5_1-2_5_2/upgradeNodeJs.sh +++ /dev/null @@ -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 \ No newline at end of file From ba51df0fb76f85ba4c22784887d10079740b5ae1 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 17:15:30 +0200 Subject: [PATCH 02/18] fix path --- deployment/bare_metal/Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index 58e85dbc7..ed6bba578 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -36,8 +36,7 @@ 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 +RUN git clone https://github.com/gradido/gradido.git --branch $BRANCH_NAME # setup nginx WORKDIR /app/gradido/deployment/bare_metal/nginx @@ -49,11 +48,11 @@ 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 ln -s /app/gradido/deployment/bare_metal/nginx/sites-available/update-page.conf /app/gradido/deployment/bare_metal/nginx/sites-enabled/default +RUN ln -s /app/gradido/deployment/bare_metal/nginx/sites-enabled/default /etc/nginx/sites-enabled +RUN ln -s /app/gradido/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 ln -s /app/gradido/deployment/bare_metal/nginx/conf.d /etc/nginx/ RUN nginx -t SHELL ["/bin/bash", "--login", "-c"] From 31ad3a9508ffd6ec1f02b3bd04d2f90d2870c3cd Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 17:17:02 +0200 Subject: [PATCH 03/18] fix workdir --- deployment/bare_metal/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index ed6bba578..5ff1ab2c4 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -81,7 +81,7 @@ RUN service mariadb start && mysql < database/.env From 3dcbbd733f0fd78854d3bf0063647b988608325d Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 17:30:04 +0200 Subject: [PATCH 04/18] use cat in success message also --- deployment/bare_metal/start.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index b58b9c706..908bf958e 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -151,7 +151,7 @@ onError() { local exit_code=$? log_error "Command failed!" log_error " /\\_/\\ Line: $(caller 0)" - log_error "( o.o ) Exit Code: $exit_code" + log_error "( x_x ) Exit Code: $exit_code" log_error " > ^ < Offending command: '$BASH_COMMAND'" log_error "" exit 1 @@ -332,4 +332,6 @@ sudo /etc/init.d/nginx restart # keep the update log cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log -log_success 'Update finished' \ No newline at end of file +log_success " /\\_/\\" +log_success "( o.o ) Update finished successfully!" +log_success " > ﹀ <" \ No newline at end of file From bf789c88fc8c84056844dedfbb08f658bee6be18 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 17:34:00 +0200 Subject: [PATCH 05/18] use same shell vor subscript to keep Exported envs --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 908bf958e..a24cb42cf 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -2,7 +2,7 @@ # stop if something fails set -euo pipefail -bash ./install-missing-deps.sh +source ./install-missing-deps.sh # check for parameter FAST_MODE=false From b414a36ba1235529310b66ae98c0c8fcd2c3d87c Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 17:44:36 +0200 Subject: [PATCH 06/18] start mariadb, add github workflow --- .github/file-filters.yml | 5 ++++- .github/workflows/test_deploy.yml | 32 +++++++++++++++++++++++++++++++ deployment/bare_metal/Dockerfile | 3 ++- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test_deploy.yml diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 698385209..7dc1a3cba 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -58,4 +58,7 @@ mariadb: &mariadb - 'mariadb/**/*' nginx: &nginx - - 'nginx/**/*' \ No newline at end of file + - 'nginx/**/*' + +deploy-bare-metal: &deploy-bare-metal + - 'deployment/bare_metal/**/*' \ No newline at end of file diff --git a/.github/workflows/test_deploy.yml b/.github/workflows/test_deploy.yml new file mode 100644 index 000000000..9570ac455 --- /dev/null +++ b/.github/workflows/test_deploy.yml @@ -0,0 +1,32 @@ +name: Gradido Deploy Test CI + +on: push + +jobs: + files-changed: + name: Detect File Changes - Deploy Bare Metal + runs-on: ubuntu-latest + outputs: + deploy-bare-metal: ${{ steps.changes.outputs.deploy-bare-metal }} + steps: + - uses: actions/checkout@v4 + + - name: Check for deploy-bare-metal file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build_test: + if: needs.files-changed.outputs.deploy-bare-metal == 'true' + name: Docker Build Test - Deploy Bare Metal + needs: files-changed + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Deploy Bare Metal | Build image + run: docker build -f ./deployment/bare_metal/Dockerfile --build-arg BRANCH_NAME=${{ github.ref_name }} -t "gradido/deploy-bare-metal:local" . diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index 5ff1ab2c4..834686759 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -53,7 +53,6 @@ RUN ln -s /app/gradido/deployment/bare_metal/nginx/sites-enabled/default /etc/ng RUN ln -s /app/gradido/deployment/bare_metal/nginx/common /etc/nginx/ RUN rmdir /etc/nginx/conf.d RUN ln -s /app/gradido/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 @@ -107,6 +106,8 @@ RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < federation/.env.templat ########################################################################################### FROM install as start +RUN /etc/init.d/mariadb start + WORKDIR /app/gradido/deployment/bare_metal # mock sudo From 04ee1a71972a71bb17dcacd5d882b4ffa160682e Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:00:54 +0200 Subject: [PATCH 07/18] fine-tune ascii cat --- deployment/bare_metal/start.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index a24cb42cf..92a89fca3 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -151,8 +151,8 @@ onError() { local exit_code=$? log_error "Command failed!" log_error " /\\_/\\ Line: $(caller 0)" - log_error "( x_x ) Exit Code: $exit_code" - log_error " > ^ < Offending command: '$BASH_COMMAND'" + log_error "( x.x ) Exit Code: $exit_code" + log_error " > < Offending command: '$BASH_COMMAND'" log_error "" exit 1 } @@ -332,6 +332,6 @@ sudo /etc/init.d/nginx restart # keep the update log cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log -log_success " /\\_/\\" -log_success "( o.o ) Update finished successfully!" -log_success " > ﹀ <" \ No newline at end of file +log_success " /\\_/\\ " +log_success "( ^.^ ) Update finished successfully!" +log_success " > <" \ No newline at end of file From e0b89f335f9aa97ba5b5f676008584604f7c4f1f Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:05:31 +0200 Subject: [PATCH 08/18] test deploy script direct in ci runner --- .github/workflows/test_deploy.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_deploy.yml b/.github/workflows/test_deploy.yml index 9570ac455..4e3e8d000 100644 --- a/.github/workflows/test_deploy.yml +++ b/.github/workflows/test_deploy.yml @@ -28,5 +28,13 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Deploy Bare Metal | Build image - run: docker build -f ./deployment/bare_metal/Dockerfile --build-arg BRANCH_NAME=${{ github.ref_name }} -t "gradido/deploy-bare-metal:local" . + - name: docker-compose mariadb + run: docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb + + - name: run install script, which will run start.sh + run: | + cd ~/gradido/deployment/hetzner_cloud + sudo ./install.sh ${{ github.ref_name }} + + #- name: Deploy Bare Metal | Build image + # run: docker build -f ./deployment/bare_metal/Dockerfile --build-arg BRANCH_NAME=${{ github.ref_name }} -t "gradido/deploy-bare-metal:local" . From d25574c22faeb82ad14238a1ed5d40fea6478418 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:07:36 +0200 Subject: [PATCH 09/18] fix path --- .github/workflows/test_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_deploy.yml b/.github/workflows/test_deploy.yml index 4e3e8d000..926721165 100644 --- a/.github/workflows/test_deploy.yml +++ b/.github/workflows/test_deploy.yml @@ -33,7 +33,7 @@ jobs: - name: run install script, which will run start.sh run: | - cd ~/gradido/deployment/hetzner_cloud + cd deployment/hetzner_cloud sudo ./install.sh ${{ github.ref_name }} #- name: Deploy Bare Metal | Build image From 4e0783fc8ee2d64c4dd48a9bd35698923cb826e7 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:20:15 +0200 Subject: [PATCH 10/18] use mariadb in another docker for ci test --- .github/workflows/test_deploy.yml | 9 ++------- deployment/bare_metal/Dockerfile | 16 ++-------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test_deploy.yml b/.github/workflows/test_deploy.yml index 926721165..b1261963e 100644 --- a/.github/workflows/test_deploy.yml +++ b/.github/workflows/test_deploy.yml @@ -31,10 +31,5 @@ jobs: - name: docker-compose mariadb run: docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb - - name: run install script, which will run start.sh - run: | - cd deployment/hetzner_cloud - sudo ./install.sh ${{ github.ref_name }} - - #- name: Deploy Bare Metal | Build image - # run: docker build -f ./deployment/bare_metal/Dockerfile --build-arg BRANCH_NAME=${{ github.ref_name }} -t "gradido/deploy-bare-metal:local" . + - name: Deploy Bare Metal | Build image + run: docker build --network host -f ./deployment/bare_metal/Dockerfile --build-arg BRANCH_NAME=${{ github.ref_name }} -t "gradido/deploy-bare-metal:local" . diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index 834686759..2010671be 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -68,20 +68,10 @@ 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 < database/.env # Configure backend @@ -106,8 +96,6 @@ RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < federation/.env.templat ########################################################################################### FROM install as start -RUN /etc/init.d/mariadb start - WORKDIR /app/gradido/deployment/bare_metal # mock sudo From 087869c91cdbcf8b3596a975085d5661dee06726 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:23:09 +0200 Subject: [PATCH 11/18] fix database env --- deployment/bare_metal/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index 2010671be..ccd7870c7 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -70,8 +70,8 @@ RUN npm i -g pm2 && pm2 startup WORKDIR /app/gradido # Configure database -RUN DB_USER=gradido -RUN DB_PASSWORD= +ENV DB_USER=root +ENV DB_PASSWORD= RUN envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < database/.env.template > database/.env # Configure backend From 2a12947e511817b82181b795516e34e0d44c6b15 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:31:33 +0200 Subject: [PATCH 12/18] use http protocol in deploy test --- deployment/bare_metal/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index ccd7870c7..bc3e28941 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -102,4 +102,5 @@ WORKDIR /app/gradido/deployment/bare_metal RUN echo -e '#!/bin/bash\nshift 0\nexec "$@"' > /usr/local/bin/sudo && \ chmod +x /usr/local/bin/sudo SHELL ["/bin/bash", "--login", "-c"] +ENV URL_PROTOCOL=http RUN ./start.sh $BRANCH_NAME From e57c3d96853ecaa23f914d95582ee473fe0e1944 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:37:17 +0200 Subject: [PATCH 13/18] more details on restart nginx error --- deployment/bare_metal/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 92a89fca3..a5bc35d02 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -327,7 +327,7 @@ done # let nginx showing gradido log_step 'Configuring nginx to serve gradido again' ln -sf $SCRIPT_DIR/nginx/sites-available/gradido.conf $SCRIPT_DIR/nginx/sites-enabled/default -sudo /etc/init.d/nginx restart +sudo /etc/init.d/nginx restart || log_error "Failed to restart nginx $(sudo nginx -t)" # keep the update log cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log From 820f7882b1c4e8452ca7d69e67e9aecf50dc8b7e Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:47:00 +0200 Subject: [PATCH 14/18] test other form --- deployment/bare_metal/start.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index a5bc35d02..4e7319009 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -327,7 +327,9 @@ done # let nginx showing gradido log_step 'Configuring nginx to serve gradido again' ln -sf $SCRIPT_DIR/nginx/sites-available/gradido.conf $SCRIPT_DIR/nginx/sites-enabled/default +sudo nginx -t sudo /etc/init.d/nginx restart || log_error "Failed to restart nginx $(sudo nginx -t)" +log_warn sudo nginx -t # keep the update log cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log From 279ec8c01944ceac369fe7272d0716581eda1bdd Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 18:52:13 +0200 Subject: [PATCH 15/18] try again with nginx restart in deploy test docker --- deployment/bare_metal/Dockerfile | 3 +-- deployment/bare_metal/start.sh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index bc3e28941..1d2dca0cb 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -102,5 +102,4 @@ WORKDIR /app/gradido/deployment/bare_metal RUN echo -e '#!/bin/bash\nshift 0\nexec "$@"' > /usr/local/bin/sudo && \ chmod +x /usr/local/bin/sudo SHELL ["/bin/bash", "--login", "-c"] -ENV URL_PROTOCOL=http -RUN ./start.sh $BRANCH_NAME +RUN URL_PROTOCOL=http ./start.sh $BRANCH_NAME diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index 4e7319009..d75bd4eb6 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -328,8 +328,7 @@ done log_step 'Configuring nginx to serve gradido again' ln -sf $SCRIPT_DIR/nginx/sites-available/gradido.conf $SCRIPT_DIR/nginx/sites-enabled/default sudo nginx -t -sudo /etc/init.d/nginx restart || log_error "Failed to restart nginx $(sudo nginx -t)" -log_warn sudo nginx -t +sudo /etc/init.d/nginx restart # keep the update log cat $UPDATE_HTML >> $GRADIDO_LOG_PATH/update.$TODAY.log From 090817ae23c4fbde1c04679245d5799f7f966e8d Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 8 May 2025 19:16:51 +0200 Subject: [PATCH 16/18] copy .env.dist to .env and replace https with http --- deployment/bare_metal/Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deployment/bare_metal/Dockerfile b/deployment/bare_metal/Dockerfile index 1d2dca0cb..c617c4cc3 100644 --- a/deployment/bare_metal/Dockerfile +++ b/deployment/bare_metal/Dockerfile @@ -37,6 +37,8 @@ ARG BRANCH_NAME=master ENV BRANCH_NAME=$BRANCH_NAME # COPY . . RUN git clone https://github.com/gradido/gradido.git --branch $BRANCH_NAME +RUN cp /app/gradido/deployment/bare_metal/.env.dist /app/gradido/deployment/bare_metal/.env +RUN sed -i 's/^URL_PROTOCOL=https$/URL_PROTOCOL=http/' /app/gradido/deployment/bare_metal/.env # setup nginx WORKDIR /app/gradido/deployment/bare_metal/nginx @@ -102,4 +104,6 @@ WORKDIR /app/gradido/deployment/bare_metal RUN echo -e '#!/bin/bash\nshift 0\nexec "$@"' > /usr/local/bin/sudo && \ chmod +x /usr/local/bin/sudo SHELL ["/bin/bash", "--login", "-c"] -RUN URL_PROTOCOL=http ./start.sh $BRANCH_NAME +RUN ./start.sh $BRANCH_NAME + + From bc0b3c0722059f5a3a3faecab9d50a33d0f672ea Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Mon, 19 May 2025 15:13:42 +0200 Subject: [PATCH 17/18] fix installer script --- deployment/bare_metal/start.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/start.sh b/deployment/bare_metal/start.sh index c8985bca6..5b9d2476a 100755 --- a/deployment/bare_metal/start.sh +++ b/deployment/bare_metal/start.sh @@ -12,8 +12,9 @@ then 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}" + curl -fsSL https://bun.sh/install | bash + export BUN_INSTALL="$HOME/.bun" + export PATH="$BUN_INSTALL/bin:$PATH" fi # turbo https://turborepo.com/docs/getting-started if ! command -v turbo &> /dev/null From 4ad38c2e5f5fc337df23815742d54bbba172df03 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Mon, 19 May 2025 15:27:52 +0200 Subject: [PATCH 18/18] fix bun install script --- deployment/bare_metal/install-missing-deps.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/bare_metal/install-missing-deps.sh b/deployment/bare_metal/install-missing-deps.sh index f7d284e2d..c543bd4dc 100644 --- a/deployment/bare_metal/install-missing-deps.sh +++ b/deployment/bare_metal/install-missing-deps.sh @@ -29,8 +29,9 @@ then 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}" + curl -fsSL https://bun.sh/install | bash + export BUN_INSTALL="$HOME/.bun" + export PATH="$BUN_INSTALL/bin:$PATH" fi # turbo https://turborepo.com/docs/getting-started if ! command -v turbo &> /dev/null