added init scripts for assets and programm

main
Andre Challier 2024-03-27 16:30:35 +01:00
parent 85dc5052b9
commit 9178dcf1de
6 changed files with 106 additions and 0 deletions

View File

@ -5,6 +5,10 @@ RUN apk --no-cache add git openssh-client bash nano gettext
COPY --from=build /usr/local/bin/webhook /usr/local/bin/webhook
COPY hooks.json.tmpl /etc/webhook/hooks.json.tmpl
COPY entrypoint.sh /etc/webhook/entrypoint.sh
COPY assets-hook.sh /etc/webhook/assets-hook.sh
COPY assets-init.sh /etc/webhook/assets-init.sh
COPY programm-hook.sh /etc/webhook/programm-hook.sh
COPY programm-init.sh /etc/webhook/programm-init.sh
RUN chmod +x /etc/webhook/entrypoint.sh
WORKDIR /etc/webhook
EXPOSE 9000

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,38 @@
#!/bin/bash
#
# Initialize assets folder from repository
#
# - delete existing assets folder
# - fetch assets/main from repository
#
BRANCHES_FOLDER="/html/branches"
ASSETS_FOLDER="/html/branches/assets"
ASSETS_REPOSITORY="git_assets:AG-IT/assets.git"
ASSETS_BRANCH="main"
#
# Remove assets folder if exists
#
if [ -d "$ASSETS_FOLDER" ];
then
echo "Removing existing assets folder: $ASSETS_FOLDER"
rm -R "$ASSETS_FOLDER"
fi
#
# Create branches folder if not exist
#
if [ ! -d "$BRANCHES_FOLDER" ];
then
echo "Create branches folder: $BRANCES_FOLDER"
mkdir -p "$BRANCHES_FOLDER"
fi
#
# Clone assets folder from repository
#
git clone --depth 1 --branch "$ASSETS_BRANCH" --single-branch "$ASSETS_REPOSITORY" "$ASSETS_FOLDER"

View File

@ -81,6 +81,26 @@ fi
# Create or append known_hosts
ssh-keyscan -H "${GIT_SERVER}" >> "${path_ssh}/known_hosts"
echo "git and ssh configured."
echo "Programm webhook public key (deploy key):"
echo "|------------------------------------------------------------------|"
cat "${path_ssh}/programm-webhook.deploy.25519.pub"
echo "|------------------------------------------------------------------|"
echo "Assets webhook public key (deploy key):"
echo "|------------------------------------------------------------------|"
cat "${path_ssh}/assets-webhook.deploy.25519.pub"
echo "|------------------------------------------------------------------|"
# Initialize assets
echo "Initialize assets directory"
./assets-init.sh
# Initialize branches
echo "Initialize branches of programm"
./programm-init.sh
#
# Start webhooks
#

View File

View File

@ -0,0 +1,43 @@
#!/bin/bash
#
# Initialize assets folder from repository
#
# - delete existing assets folder
# - fetch assets/main from repository
#
HTML_HOME="/html"
BRANCHES_FOLDER="/html/branches"
PROGRAMM_REPOSITORY="git_programm:AG-Programm/parteiprogramm.git"
#
# Remove all branch folders but assets
#
for dir in "$BRANCHES_FOLDER"/*/;
do
dir_name=$(basename "$dir")
if [ "$dir_name" != "assets" ];
then
echo "Deleting directory: $dir"
rm -rf "$dir"
fi
done
#
# Fetch all branch names
#
git ls-remote --heads "$PROGRAMM_REPOSITORY" |
# Extract branch names
awk '{print $2}' |
# Remove "refs/heads/" prefix to get only branch names
sed 's#refs/heads/##' |
# Store branch names in an array
mapfile -t branches
for branch in "${branches[@]}";
do
git clone --depth 1 --branch "$branch" --single-branch "$PROGRAMM_REPOSITORY" "$BRANCHES_FOLDER"/"$branch"
done