several fixes
- implemented programm hook - implemented generation of index.html - fixed usage of WEBHOOK_SECRET variable in hooks definition - made entrypoint generate index.html - made programm hook generate index.htmlmain
parent
5c2e4b89be
commit
9fdcc3455c
|
|
@ -37,6 +37,9 @@ RUN chmod +x /etc/webhook/programm-hook.sh
|
|||
COPY programm-init.sh /etc/webhook/programm-init.sh
|
||||
RUN chmod +x /etc/webhook/programm-init.sh
|
||||
|
||||
COPY generate_index_html.sh /etc/webhook/generate_index_html.sh
|
||||
RUN chmod +x /etc/webhook/generate_index_html.sh
|
||||
|
||||
WORKDIR /etc/webhook
|
||||
EXPOSE 9000
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ echo "Initialize assets directory"
|
|||
echo "Initialize branches of programm"
|
||||
./programm-init.sh
|
||||
|
||||
# Generate index.html
|
||||
./generate_index_html.sh
|
||||
|
||||
#
|
||||
# Start webhooks
|
||||
#
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Directory where branches are stored
|
||||
BRANCHES_DIR="/html/branches"
|
||||
|
||||
# Generate index.html file
|
||||
generate_index_html() {
|
||||
cat << EOF
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>List of Branches</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>List of Branches</h1>
|
||||
<ul>
|
||||
EOF
|
||||
|
||||
# Loop through folders in ./branches/ excluding "assets"
|
||||
for branch_folder in "$BRANCHES_DIR"/*; do
|
||||
branch_name=$(basename "$branch_folder")
|
||||
if [ "$branch_name" != "assets" ] && [ -f "$branch_folder/index.html" ]; then
|
||||
echo " <li><a href=\"$branch_name/index.html\">$branch_name</a></li>"
|
||||
fi
|
||||
done
|
||||
|
||||
cat << EOF
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
}
|
||||
|
||||
generate_index_html > /html/index.html
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
[
|
||||
{
|
||||
"id": "programm-webhook",
|
||||
"http-methods": ["PUSH"],
|
||||
"http-methods": ["POST"],
|
||||
"execute-command": "/etc/webhook/programm-hook.sh",
|
||||
"command-working-directory": "/etc/webhook/",
|
||||
"response-message": "I got the payload!",
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
"match":
|
||||
{
|
||||
"type": "payload-hmac-sha1",
|
||||
"secret": "1234",
|
||||
"secret": "${WEBHOOK_SECRET}",
|
||||
"parameter":
|
||||
{
|
||||
"source": "header",
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
},
|
||||
{
|
||||
"id": "assets-webhook",
|
||||
"http-methods": ["POST"],
|
||||
"execute-command": "/etc/webhook/assets-hook.sh",
|
||||
"command-working-directory": "/etc/webhook/",
|
||||
"response-message": "I got the payload!",
|
||||
|
|
@ -73,7 +74,7 @@
|
|||
"match":
|
||||
{
|
||||
"type": "payload-hmac-sha256",
|
||||
"secret": "1234",
|
||||
"secret": "${WEBHOOK_SECRET}",
|
||||
"parameter":
|
||||
{
|
||||
"source": "header",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Check if correct number of arguments are provided
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <repository_name> <branch_name>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
repository_name="$1"
|
||||
branch_name=(basename "$2")
|
||||
|
||||
BRANCHES_FOLDER="/html/branches"
|
||||
PROGRAMM_REPOSITORY="git_programm:AG-Programm/parteiprogramm.git"
|
||||
|
||||
# Echo parameters
|
||||
echo "Webhook recieved for repository: $repository_name and branch: $branch_name"
|
||||
|
||||
# Check if the branch directory exists
|
||||
branch_dir="$BRANCES_FOLDER/$(basename "$branch_name")"
|
||||
if [ -d "$branch_dir" ]; then
|
||||
echo "Directory $branch_dir exists, performing git pull..."
|
||||
# Change directory to branch directory
|
||||
cd "$branch_dir"
|
||||
# Perform git pull
|
||||
echo "Updating $branch_dir"
|
||||
git pull origin "$(basename "$branch_name")"
|
||||
else
|
||||
echo "Directory $branch_dir does not exist, cloning branch..."
|
||||
# Create branches directory if it doesn't exist
|
||||
mkdir -p branches
|
||||
# Clone the branch
|
||||
git clone --depth 1 --branch "$branch_name" --single-branch "$PROGRAMM_REPOSITORY" "$branch_dir"
|
||||
# reinitialize index.html
|
||||
./generate_index_html.sh
|
||||
fi
|
||||
|
|
@ -37,8 +37,6 @@ git ls-remote --heads "$PROGRAMM_REPOSITORY" |
|
|||
# Store branch names in an array
|
||||
mapfile -t branches
|
||||
|
||||
|
||||
|
||||
for branch in "${branches[@]}";
|
||||
do
|
||||
echo "cloning $branch"
|
||||
|
|
|
|||
Loading…
Reference in New Issue