Merge pull request #3488 from gradido/split_start_script

feat(other): split start script, put additional installs in extra script
This commit is contained in:
einhornimmond 2025-05-20 11:24:21 +02:00 committed by GitHub
commit c9505b00ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 194 additions and 25 deletions

View File

@ -58,4 +58,7 @@ mariadb: &mariadb
- 'mariadb/**/*'
nginx: &nginx
- 'nginx/**/*'
- 'nginx/**/*'
deploy-bare-metal: &deploy-bare-metal
- 'deployment/bare_metal/**/*'

35
.github/workflows/test_deploy.yml vendored Normal file
View File

@ -0,0 +1,35 @@
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: docker-compose mariadb
run: docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps mariadb
- 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" .

View File

@ -0,0 +1,109 @@
##### 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
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
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/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/gradido/deployment/bare_metal/nginx/conf.d /etc/nginx/
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
WORKDIR /app/gradido
# Configure database
ENV DB_USER=root
ENV DB_PASSWORD=
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

View File

@ -0,0 +1,41 @@
#!/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 | 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
then
echo "'turbo' is missing, will be installed now!"
bun install --global turbo
fi

View File

@ -2,26 +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 | 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
then
echo "'turbo' is missing, will be installed now!"
bun install --global turbo
fi
source ./install-missing-deps.sh
# check for parameter
FAST_MODE=false
@ -154,22 +135,22 @@ ln -sf $SCRIPT_DIR/nginx/sites-available/update-page.conf $SCRIPT_DIR/nginx/site
# 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
}