.gitea/workflows/build-and-push.yaml aktualisiert
build-and-push.yaml / release-and-build (push) Canceled after 42s
build-and-push.yaml / release-and-build (push) Canceled after 42s
This commit is contained in:
1 parent
ca9a63ce1a
commit
2e98ee5b0e
1 file changed
+254
-211
@@ -1,13 +1,17 @@
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- 'dev'
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- '*'
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 5 * * 0'
|
- cron: '0 5 * * 0'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-and-build:
|
release-and-build:
|
||||||
runs-on: buildx-multiarch
|
runs-on: buildx-multiarch
|
||||||
@@ -16,6 +20,7 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
|
token: ${{ secrets.RUNNER_TOKEN }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Prepare Environment and Read Config
|
- name: Prepare Environment and Read Config
|
||||||
@@ -59,8 +64,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Login to Gitea Registry
|
- name: Login to Gitea Registry
|
||||||
run: |
|
run: |
|
||||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login \
|
echo "${{ secrets.RUNNER_TOKEN }}" | docker login git.pi-farm.de -u "${{ gitea.actor }}" --password-stdin
|
||||||
git.pi-farm.de -u ${{ secrets.REGISTRY_USER }} --password-stdin
|
|
||||||
|
|
||||||
- name: Check for Real Changes
|
- name: Check for Real Changes
|
||||||
id: check_changes
|
id: check_changes
|
||||||
@@ -125,6 +129,7 @@ jobs:
|
|||||||
ARGS_HASH=${{ steps.prep.outputs.build_args_hash }}
|
ARGS_HASH=${{ steps.prep.outputs.build_args_hash }}
|
||||||
BASE=${{ steps.prep.outputs.base_image }}
|
BASE=${{ steps.prep.outputs.base_image }}
|
||||||
REPO_PURE=${{ steps.prep.outputs.repo_pure }}
|
REPO_PURE=${{ steps.prep.outputs.repo_pure }}
|
||||||
|
DOCKERHUB_REPO="${{ secrets.DOCKERHUB_USERNAME }}/$REPO_PURE"
|
||||||
|
|
||||||
set -a
|
set -a
|
||||||
source <(grep -v '^#' buildargs.env | sed 's/\r$//')
|
source <(grep -v '^#' buildargs.env | sed 's/\r$//')
|
||||||
@@ -138,14 +143,26 @@ jobs:
|
|||||||
|
|
||||||
BASE_SHA=$(docker buildx imagetools inspect $BASE --format '{{json .Manifest.Digest}}' 2>/dev/null | tr -d '"' || echo "unknown")
|
BASE_SHA=$(docker buildx imagetools inspect $BASE --format '{{json .Manifest.Digest}}' 2>/dev/null | tr -d '"' || echo "unknown")
|
||||||
|
|
||||||
docker buildx build "${DOCKER_ARGS[@]}" -t "$IMAGE_GITEA:tmp-amd64" \
|
# Bereite die Tags für den initialen Build vor (Gitea immer, Docker Hub optional)
|
||||||
|
AMD_TAGS=("-t" "$IMAGE_GITEA:tmp-amd64")
|
||||||
|
ARM_TAGS=("-t" "$IMAGE_GITEA:tmp-arm64")
|
||||||
|
|
||||||
|
if [[ "$PUSH" == *"dockerhub"* ]]; then
|
||||||
|
AMD_TAGS+=("-t" "$DOCKERHUB_REPO:tmp-amd64")
|
||||||
|
ARM_TAGS+=("-t" "$DOCKERHUB_REPO:tmp-arm64")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build AMD64 & Push zu allen Zielen
|
||||||
|
docker buildx build "${DOCKER_ARGS[@]}" "${AMD_TAGS[@]}" \
|
||||||
--pull --platform linux/amd64 -f Dockerfile \
|
--pull --platform linux/amd64 -f Dockerfile \
|
||||||
--label "pi_farm.base_digest=$BASE_SHA" --label "pi_farm.args_hash=$ARGS_HASH" --push .
|
--label "pi_farm.base_digest=$BASE_SHA" --label "pi_farm.args_hash=$ARGS_HASH" --push .
|
||||||
|
|
||||||
docker buildx build "${DOCKER_ARGS[@]}" -t "$IMAGE_GITEA:tmp-arm64" \
|
# Build ARM64 & Push zu allen Zielen
|
||||||
|
docker buildx build "${DOCKER_ARGS[@]}" "${ARM_TAGS[@]}" \
|
||||||
--pull --platform linux/arm64 -f Dockerfile.aarch64 \
|
--pull --platform linux/arm64 -f Dockerfile.aarch64 \
|
||||||
--label "pi_farm.base_digest=$BASE_SHA" --label "pi_farm.args_hash=$ARGS_HASH" --push .
|
--label "pi_farm.base_digest=$BASE_SHA" --label "pi_farm.args_hash=$ARGS_HASH" --push .
|
||||||
|
|
||||||
|
# 1. Manifest auf Gitea erstellen (aus Gitea Temp-Tags)
|
||||||
GITEA_MANIFEST_TAGS=("-t" "$IMAGE_GITEA:$TAG")
|
GITEA_MANIFEST_TAGS=("-t" "$IMAGE_GITEA:$TAG")
|
||||||
if [[ "$BUILD_TAG_LATEST" == "y" ]]; then
|
if [[ "$BUILD_TAG_LATEST" == "y" ]]; then
|
||||||
GITEA_MANIFEST_TAGS+=("-t" "$IMAGE_GITEA:latest")
|
GITEA_MANIFEST_TAGS+=("-t" "$IMAGE_GITEA:latest")
|
||||||
@@ -155,232 +172,258 @@ jobs:
|
|||||||
--annotation "index:pi_farm.base_digest=$BASE_SHA" --annotation "index:pi_farm.args_hash=$ARGS_HASH" \
|
--annotation "index:pi_farm.base_digest=$BASE_SHA" --annotation "index:pi_farm.args_hash=$ARGS_HASH" \
|
||||||
"${GITEA_MANIFEST_TAGS[@]}" $IMAGE_GITEA:tmp-amd64 $IMAGE_GITEA:tmp-arm64
|
"${GITEA_MANIFEST_TAGS[@]}" $IMAGE_GITEA:tmp-amd64 $IMAGE_GITEA:tmp-arm64
|
||||||
|
|
||||||
|
# 2. Manifest auf Docker Hub erstellen (aus Docker Hub Temp-Tags!)
|
||||||
if [[ "$PUSH" == *"dockerhub"* ]]; then
|
if [[ "$PUSH" == *"dockerhub"* ]]; then
|
||||||
DOCKERHUB_REPO="${{ secrets.DOCKERHUB_USERNAME }}/$REPO_PURE"
|
|
||||||
DH_MANIFEST_TAGS=("-t" "$DOCKERHUB_REPO:$TAG")
|
DH_MANIFEST_TAGS=("-t" "$DOCKERHUB_REPO:$TAG")
|
||||||
if [[ "$BUILD_TAG_LATEST" == "y" ]]; then
|
if [[ "$BUILD_TAG_LATEST" == "y" ]]; then
|
||||||
DH_MANIFEST_TAGS+=("-t" "$DOCKERHUB_REPO:latest")
|
DH_MANIFEST_TAGS+=("-t" "$DOCKERHUB_REPO:latest")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# WICHTIG: Hier werden jetzt als Quelle die Docker Hub Temp-Tags genutzt!
|
||||||
docker buildx imagetools create \
|
docker buildx imagetools create \
|
||||||
--annotation "index:pi_farm.base_digest=$BASE_SHA" --annotation "index:pi_farm.args_hash=$ARGS_HASH" \
|
--annotation "index:pi_farm.base_digest=$BASE_SHA" --annotation "index:pi_farm.args_hash=$ARGS_HASH" \
|
||||||
"${DH_MANIFEST_TAGS[@]}" $IMAGE_GITEA:tmp-amd64 $IMAGE_GITEA:tmp-arm64
|
"${DH_MANIFEST_TAGS[@]}" $DOCKERHUB_REPO:tmp-amd64 $DOCKERHUB_REPO:tmp-arm64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Update Documentation and Compose
|
- name: Update Documentation and Compose
|
||||||
id: update_doc
|
id: update_doc
|
||||||
if: steps.check_changes.outputs.should_build == 'true'
|
if: steps.check_changes.outputs.should_build == 'true'
|
||||||
run: |
|
run: |
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
export TZ=Europe/Berlin
|
export TZ=Europe/Berlin
|
||||||
CURRENT_TIME=$(date '+%d.%m.%Y %H:%M')
|
CURRENT_TIME=$(date '+%d.%m.%Y %H:%M')
|
||||||
BUILD_TAG="${{ steps.prep.outputs.docker_tag }}"
|
BUILD_TAG="${{ steps.prep.outputs.docker_tag }}"
|
||||||
FULL_URL="${{ steps.prep.outputs.image_name }}"
|
FULL_URL="${{ steps.prep.outputs.image_name }}"
|
||||||
REPO_PURE="${{ steps.prep.outputs.repo_pure }}"
|
REPO_PURE="${{ steps.prep.outputs.repo_pure }}"
|
||||||
BASE_IMAGE="${{ steps.prep.outputs.base_image }}"
|
BASE_IMAGE="${{ steps.prep.outputs.base_image }}"
|
||||||
|
|
||||||
if [ ! -f "buildargs.env" ]; then echo "❌ buildargs.env missing!"; exit 1; fi
|
if [ ! -f "buildargs.env" ]; then echo "❌ buildargs.env missing!"; exit 1; fi
|
||||||
|
|
||||||
grep -v '^#' buildargs.env | sed 's/\r$//' > cleaned_env.sh
|
grep -v '^#' buildargs.env | sed 's/\r$//' > cleaned_env.sh
|
||||||
set -a
|
set -a
|
||||||
source ./cleaned_env.sh
|
source ./cleaned_env.sh
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
if [ -f "Dockerfile.aarch64" ]; then ARM_STATUS="✅ Active"; else ARM_STATUS="❌ Not supported"; fi
|
if [ -f "Dockerfile.aarch64" ]; then ARM_STATUS="✅ Active"; else ARM_STATUS="❌ Not supported"; fi
|
||||||
|
|
||||||
cat << 'EOF' > commit_msg.txt
|
cat << 'EOF' > commit_msg.txt
|
||||||
${{ gitea.event.head_commit.message }}
|
${{ gitea.event.head_commit.message }}
|
||||||
EOF
|
EOF
|
||||||
COMMIT_MSG=$(sed 's/\[skip ci\]//g' commit_msg.txt | xargs)
|
COMMIT_MSG=$(sed 's/\[skip ci\]//g' commit_msg.txt | xargs)
|
||||||
|
|
||||||
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/README.template -O README.template || echo "Warnung: README Template fehlt"
|
# 1. Authentifizierter Download der Templates via curl (-f bricht bei HTTP-Fehlern ab)
|
||||||
wget -q https://git.pi-farm.de/pi-farm/templates/raw/branch/main/docker-compose.template -O docker-compose.template || echo "Warnung: Compose Template fehlt"
|
TOKEN="${{ secrets.RUNNER_TOKEN }}"
|
||||||
|
curl -sSLf -H "Authorization: token $TOKEN" \
|
||||||
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
"https://git.pi-farm.de/pi-farm/templates/raw/branch/dev/README.template" \
|
||||||
if [ -f "VERSION.history" ]; then
|
-o README.template || echo "Warnung: README Template konnte nicht geladen werden"
|
||||||
grep -v "| **$BUILD_TAG** |" VERSION.history > VERSION.history.tmp || true
|
|
||||||
echo "$NEW_ROW" > VERSION.history
|
curl -sSLf -H "Authorization: token $TOKEN" \
|
||||||
cat VERSION.history.tmp >> VERSION.history
|
"https://git.pi-farm.de/pi-farm/templates/raw/branch/dev/docker-compose.template" \
|
||||||
rm VERSION.history.tmp
|
-o docker-compose.template || echo "Warnung: Compose Template konnte nicht geladen werden"
|
||||||
else
|
|
||||||
echo "$NEW_ROW" > VERSION.history
|
# 2. Sicherheitsprüfung: Falls Gitea trotz -f eine HTML-Login-Seite ausgibt, Datei sofort verwerfen
|
||||||
fi
|
for t_file in README.template docker-compose.template; do
|
||||||
HISTORY_CONTENT=$(cat VERSION.history)
|
if [ -f "$t_file" ] && grep -qi "<!DOCTYPE html>" "$t_file"; then
|
||||||
|
echo "❌ FEHLER: $t_file ist eine HTML-Loginseite! Download verworfen."
|
||||||
ENV_BLOCK_CONTENT=""
|
rm -f "$t_file"
|
||||||
env_vars=$(grep '^ENV_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
|
||||||
if [ -n "$env_vars" ]; then
|
|
||||||
ENV_BLOCK_CONTENT=" environment:\n"
|
|
||||||
while read -r line; do
|
|
||||||
[ -z "$line" ] && continue
|
|
||||||
key=$(echo "$line" | cut -d= -f1); val=$(echo "$line" | cut -d= -f2-); clean_key=${key#ENV_}
|
|
||||||
ENV_BLOCK_CONTENT="${ENV_BLOCK_CONTENT} - ${clean_key}=${val}\n"
|
|
||||||
done <<< "$env_vars"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PORTS_BLOCK_CONTENT=""
|
|
||||||
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
|
||||||
if [ -n "$port_vars" ]; then
|
|
||||||
PORTS_BLOCK_CONTENT=" ports:\n"
|
|
||||||
while read -r line; do
|
|
||||||
[ -z "$line" ] && continue
|
|
||||||
val=$(echo "$line" | cut -d= -f2-); PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
|
|
||||||
done <<< "$port_vars"
|
|
||||||
fi
|
|
||||||
|
|
||||||
VOL_BLOCK_CONTENT=""
|
|
||||||
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
|
||||||
if [ -n "$vol_vars" ]; then
|
|
||||||
VOL_BLOCK_CONTENT=" volumes:\n"
|
|
||||||
while read -r line; do
|
|
||||||
[ -z "$line" ] && continue
|
|
||||||
val=$(echo "$line" | cut -d= -f2-); VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\n"
|
|
||||||
done <<< "$vol_vars"
|
|
||||||
fi
|
|
||||||
|
|
||||||
{
|
|
||||||
echo "docker run -d \\"
|
|
||||||
echo " --name $REPO_PURE \\"
|
|
||||||
echo " --restart unless-stopped \\"
|
|
||||||
|
|
||||||
all_params=$(grep -E '^(PORT_|ENV_|VOL_)' buildargs.env | grep -v '^#' | sed 's/\r$//' || true)
|
|
||||||
if [ -n "$all_params" ]; then
|
|
||||||
while read -r line; do
|
|
||||||
[ -z "$line" ] && continue
|
|
||||||
if [[ "$line" =~ ^PORT_ ]]; then
|
|
||||||
val=$(echo "$line" | cut -d= -f2-)
|
|
||||||
echo " -p ${val} \\"
|
|
||||||
elif [[ "$line" =~ ^ENV_ ]]; then
|
|
||||||
key=$(echo "$line" | cut -d= -f1); clean_key=${key#ENV_}; val=$(echo "$line" | cut -d= -f2-)
|
|
||||||
echo " -e ${clean_key}=${val} \\"
|
|
||||||
elif [[ "$line" =~ ^VOL_ ]]; then
|
|
||||||
val=$(echo "$line" | cut -d= -f2-)
|
|
||||||
echo " -v ${val} \\"
|
|
||||||
fi
|
fi
|
||||||
done <<< "$all_params"
|
done
|
||||||
fi
|
|
||||||
echo " $FULL_URL:$BUILD_TAG"
|
NEW_ROW="| **$BUILD_TAG** | $CURRENT_TIME | $COMMIT_MSG ✅ |"
|
||||||
} > docker_run_block.txt
|
if [ -f "VERSION.history" ]; then
|
||||||
|
grep -v "| **$BUILD_TAG** |" VERSION.history > VERSION.history.tmp || true
|
||||||
DOCKERHUB_LINK_CONTENT=""
|
echo "$NEW_ROW" > VERSION.history
|
||||||
if [[ "${{ steps.prep.outputs.push_targets }}" == *"dockerhub"* ]]; then
|
cat VERSION.history.tmp >> VERSION.history
|
||||||
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
rm VERSION.history.tmp
|
||||||
DOCKERHUB_LINK_CONTENT="[](https://hub.docker.com/r/${DH_USER}/${REPO_PURE})"
|
else
|
||||||
fi
|
echo "$NEW_ROW" > VERSION.history
|
||||||
|
fi
|
||||||
process_template() {
|
HISTORY_CONTENT=$(cat VERSION.history)
|
||||||
local template=$1; local output=$2
|
|
||||||
[ ! -f "$template" ] && return
|
ENV_BLOCK_CONTENT=""
|
||||||
cp "$template" "$output"
|
env_vars=$(grep '^ENV_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||||
|
if [ -n "$env_vars" ]; then
|
||||||
|
ENV_BLOCK_CONTENT=" environment:\n"
|
||||||
|
while read -r line; do
|
||||||
|
[ -z "$line" ] && continue
|
||||||
|
key=$(echo "$line" | cut -d= -f1); val=$(echo "$line" | cut -d= -f2-); clean_key=${key#ENV_}
|
||||||
|
ENV_BLOCK_CONTENT="${ENV_BLOCK_CONTENT} - ${clean_key}=${val}\n"
|
||||||
|
done <<< "$env_vars"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PORTS_BLOCK_CONTENT=""
|
||||||
|
port_vars=$(grep '^PORT_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||||
|
if [ -n "$port_vars" ]; then
|
||||||
|
PORTS_BLOCK_CONTENT=" ports:\n"
|
||||||
|
while read -r line; do
|
||||||
|
[ -z "$line" ] && continue
|
||||||
|
val=$(echo "$line" | cut -d= -f2-); PORTS_BLOCK_CONTENT="${PORTS_BLOCK_CONTENT} - ${val}\n"
|
||||||
|
done <<< "$port_vars"
|
||||||
|
fi
|
||||||
|
|
||||||
|
VOL_BLOCK_CONTENT=""
|
||||||
|
vol_vars=$(grep '^VOL_' buildargs.env | grep -v '^#' | tr -d '\r' || true)
|
||||||
|
if [ -n "$vol_vars" ]; then
|
||||||
|
VOL_BLOCK_CONTENT=" volumes:\n"
|
||||||
|
while read -r line; do
|
||||||
|
[ -z "$line" ] && continue
|
||||||
|
val=$(echo "$line" | cut -d= -f2-); VOL_BLOCK_CONTENT="${VOL_BLOCK_CONTENT} - ${val}\n"
|
||||||
|
done <<< "$vol_vars"
|
||||||
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "docker run -d \\"
|
||||||
|
echo " --name $REPO_PURE \\"
|
||||||
|
echo " --restart unless-stopped \\"
|
||||||
|
|
||||||
|
all_params=$(grep -E '^(PORT_|ENV_|VOL_)' buildargs.env | grep -v '^#' | sed 's/\r$//' || true)
|
||||||
|
if [ -n "$all_params" ]; then
|
||||||
|
while read -r line; do
|
||||||
|
[ -z "$line" ] && continue
|
||||||
|
if [[ "$line" =~ ^PORT_ ]]; then
|
||||||
|
val=$(echo "$line" | cut -d= -f2-)
|
||||||
|
echo " -p ${val} \\"
|
||||||
|
elif [[ "$line" =~ ^ENV_ ]]; then
|
||||||
|
key=$(echo "$line" | cut -d= -f1); clean_key=${key#ENV_}; val=$(echo "$line" | cut -d= -f2-)
|
||||||
|
echo " -e ${clean_key}=${val} \\"
|
||||||
|
elif [[ "$line" =~ ^VOL_ ]]; then
|
||||||
|
val=$(echo "$line" | cut -d= -f2-)
|
||||||
|
echo " -v ${val} \\"
|
||||||
|
fi
|
||||||
|
done <<< "$all_params"
|
||||||
|
fi
|
||||||
|
echo " $FULL_URL:$BUILD_TAG"
|
||||||
|
} > docker_run_block.txt
|
||||||
|
|
||||||
|
DOCKERHUB_LINK_CONTENT=""
|
||||||
|
if [[ "${{ steps.prep.outputs.push_targets }}" == *"dockerhub"* ]]; then
|
||||||
|
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||||
|
DOCKERHUB_LINK_CONTENT="[](https://hub.docker.com/r/${DH_USER}/${REPO_PURE})"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Template-Verarbeitung via Python (verhindert awk-Abstürze bei Zeilenumbrüchen)
|
||||||
|
process_template() {
|
||||||
|
local template=$1; local output=$2
|
||||||
|
[ ! -f "$template" ] && return
|
||||||
|
cp "$template" "$output"
|
||||||
|
|
||||||
|
export REPO_PURE FULL_URL BUILD_TAG BASE_IMAGE ARM_STATUS CURRENT_TIME \
|
||||||
|
HISTORY_CONTENT DOCKERHUB_LINK_CONTENT ENV_BLOCK_CONTENT \
|
||||||
|
PORTS_BLOCK_CONTENT VOL_BLOCK_CONTENT DESCRIPTION
|
||||||
|
|
||||||
|
python3 -c '
|
||||||
|
import os, sys
|
||||||
|
|
||||||
|
output = sys.argv[1]
|
||||||
|
|
||||||
|
with open(output, "r", encoding="utf-8") as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
content = content.replace("__REPO_NAME__", os.environ.get("REPO_PURE", ""))
|
||||||
|
content = content.replace("__FULL_URL__", os.environ.get("FULL_URL", ""))
|
||||||
|
content = content.replace("__BUILD_TAG__", os.environ.get("BUILD_TAG", ""))
|
||||||
|
content = content.replace("__BASE_IMAGE__", os.environ.get("BASE_IMAGE", ""))
|
||||||
|
content = content.replace("__ARM_STATUS__", os.environ.get("ARM_STATUS", ""))
|
||||||
|
content = content.replace("__CURRENT_DATE__", os.environ.get("CURRENT_TIME", ""))
|
||||||
|
content = content.replace("__HISTORY_CONTENT__", os.environ.get("HISTORY_CONTENT", ""))
|
||||||
|
content = content.replace("__DOCKERHUB_LINK__", os.environ.get("DOCKERHUB_LINK_CONTENT", ""))
|
||||||
|
content = content.replace("__ENV_BLOCK__", os.environ.get("ENV_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||||
|
content = content.replace("__PORTS_BLOCK__", os.environ.get("PORTS_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||||
|
content = content.replace("__VOL_BLOCK__", os.environ.get("VOL_BLOCK_CONTENT", "").replace("\\n", "\n"))
|
||||||
|
content = content.replace("__DESCRIPTION__", os.environ.get("DESCRIPTION", "Keine Beschreibung."))
|
||||||
|
|
||||||
sed -i "s|__REPO_NAME__|$REPO_PURE|g" "$output"
|
if "__DOCKER_RUN__" in content and os.path.exists("docker_run_block.txt"):
|
||||||
sed -i "s|__FULL_URL__|$FULL_URL|g" "$output"
|
with open("docker_run_block.txt", "r", encoding="utf-8") as f:
|
||||||
sed -i "s|__BUILD_TAG__|$BUILD_TAG|g" "$output"
|
content = content.replace("__DOCKER_RUN__", f.read())
|
||||||
sed -i "s|__BASE_IMAGE__|$BASE_IMAGE|g" "$output"
|
|
||||||
sed -i "s|__ARM_STATUS__|$ARM_STATUS|g" "$output"
|
|
||||||
sed -i "s|__CURRENT_DATE__|$CURRENT_TIME|g" "$output"
|
|
||||||
|
|
||||||
awk -v r="$HISTORY_CONTENT" '{gsub(/__HISTORY_CONTENT__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
if "__COMPOSE_BLOCK__" in content and os.path.exists("docker-compose.yml"):
|
||||||
awk -v r="$DOCKERHUB_LINK_CONTENT" '{gsub(/__DOCKERHUB_LINK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
with open("docker-compose.yml", "r", encoding="utf-8") as f:
|
||||||
|
content = content.replace("__COMPOSE_BLOCK__", f.read())
|
||||||
if grep -q "__DOCKER_RUN__" "$output" && [ -f "docker_run_block.txt" ]; then
|
|
||||||
sed -e '/__DOCKER_RUN__/{r docker_run_block.txt' -e 'd;}' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if grep -q "__COMPOSE_BLOCK__" "$output" && [ -f "docker-compose.yml" ]; then
|
with open(output, "w", encoding="utf-8") as f:
|
||||||
sed -e '/__COMPOSE_BLOCK__/{r docker-compose.yml' -e 'd;}' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
f.write(content)
|
||||||
fi
|
' "$output"
|
||||||
|
}
|
||||||
|
|
||||||
if grep -q "__ENV_BLOCK__" "$output"; then
|
process_template "docker-compose.template" "docker-compose.yml"
|
||||||
awk -v r="$(echo -e "$ENV_BLOCK_CONTENT")" '{gsub(/__ENV_BLOCK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
process_template "README.template" "README.md"
|
||||||
fi
|
|
||||||
awk -v r="$(echo -e "$PORTS_BLOCK_CONTENT")" '{gsub(/__PORTS_BLOCK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
|
||||||
awk -v r="$(echo -e "$VOL_BLOCK_CONTENT")" '{gsub(/__VOL_BLOCK__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
|
||||||
|
echo -e "$DESCRIPTION" >> $GITHUB_ENV
|
||||||
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
if grep -q "__DESCRIPTION__" "$output"; then
|
- name: Push README to Docker Hub
|
||||||
awk -v r="$(echo -e "${DESCRIPTION:-Keine Beschreibung.}")" '{gsub(/__DESCRIPTION__/, r)}1' "$output" > "$output.tmp" && mv "$output.tmp" "$output"
|
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
||||||
fi
|
run: |
|
||||||
}
|
if ! command -v jq &> /dev/null; then
|
||||||
|
apt-get update && apt-get install -y jq || apk add --no-cache jq || true
|
||||||
process_template "docker-compose.template" "docker-compose.yml"
|
fi
|
||||||
process_template "README.template" "README.md"
|
|
||||||
|
echo "🚀 Starting update README on Docker Hub..."
|
||||||
echo "FINAL_MSG=$COMMIT_MSG" >> $GITHUB_ENV
|
|
||||||
echo "DESCRIPTION<<EOF" >> $GITHUB_ENV
|
TOKEN=$(curl -s -X POST "https://hub.docker.com/v2/users/login/" \
|
||||||
echo -e "$DESCRIPTION" >> $GITHUB_ENV
|
-H "Content-Type: application/json" \
|
||||||
echo "EOF" >> $GITHUB_ENV
|
-d "{\"username\": \"${{ secrets.DOCKERHUB_USERNAME }}\", \"password\": \"${{ secrets.DOCKERHUB_TOKEN }}\"}" | jq -r .token)
|
||||||
|
|
||||||
- name: Push README to Docker Hub
|
if [ "$TOKEN" == "null" ] || [ -z "$TOKEN" ]; then
|
||||||
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
echo "❌ Error: No login-token available. Check your credentials!"
|
||||||
run: |
|
exit 1
|
||||||
if ! command -v jq &> /dev/null; then
|
fi
|
||||||
apt-get update && apt-get install -y jq || apk add --no-cache jq || true
|
|
||||||
fi
|
REPO_PURE="${{ steps.prep.outputs.repo_pure }}"
|
||||||
|
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
||||||
echo "🚀 Starting update README on Docker Hub..."
|
|
||||||
|
SHORT_DESC=$(echo -e "${{ env.DESCRIPTION }}" | head -n 1 | cut -c 1-100)
|
||||||
TOKEN=$(curl -s -X POST "https://hub.docker.com/v2/users/login/" \
|
[ -z "$SHORT_DESC" ] && SHORT_DESC="Docker Image for $REPO_PURE"
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"username\": \"${{ secrets.DOCKERHUB_USERNAME }}\", \"password\": \"${{ secrets.DOCKERHUB_TOKEN }}\"}" | jq -r .token)
|
echo "📦 Processing README.md (${REPO_PURE})..."
|
||||||
|
|
||||||
if [ "$TOKEN" == "null" ] || [ -z "$TOKEN" ]; then
|
jq -n \
|
||||||
echo "❌ Error: No login-token available. Check your credentials!"
|
--arg desc "$SHORT_DESC" \
|
||||||
exit 1
|
--rawfile full_desc README.md \
|
||||||
fi
|
'{description: $desc, full_description: $full_desc}' > payload.json
|
||||||
|
|
||||||
REPO_PURE="${{ steps.prep.outputs.repo_pure }}"
|
echo "📤 Sending data to Docker Hub API..."
|
||||||
DH_USER="${{ secrets.DOCKERHUB_USERNAME }}"
|
RESPONSE=$(curl -s -w "\n%{http_code}" -X PATCH \
|
||||||
|
"https://hub.docker.com/v2/repositories/${DH_USER}/${REPO_PURE}/" \
|
||||||
SHORT_DESC=$(echo -e "${{ env.DESCRIPTION }}" | head -n 1 | cut -c 1-100)
|
-H "Authorization: JWT ${TOKEN}" \
|
||||||
[ -z "$SHORT_DESC" ] && SHORT_DESC="Docker Image for $REPO_PURE"
|
-H "Content-Type: application/json" \
|
||||||
|
-d @payload.json)
|
||||||
echo "📦 Processing README.md (${REPO_PURE})..."
|
|
||||||
|
HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1)
|
||||||
jq -n \
|
BODY=$(echo "$RESPONSE" | head -n -1)
|
||||||
--arg desc "$SHORT_DESC" \
|
|
||||||
--rawfile full_desc README.md \
|
if [ "$HTTP_STATUS" -eq 200 ]; then
|
||||||
'{description: $desc, full_description: $full_desc}' > payload.json
|
echo "✅ README update successfull (HTTP 200)."
|
||||||
|
else
|
||||||
echo "📤 Sending data to Docker Hub API..."
|
echo "❌ Error on update! HTTP Status: $HTTP_STATUS"
|
||||||
RESPONSE=$(curl -s -w "\n%{http_code}" -X PATCH \
|
echo "Answer from Docker Hub: $BODY"
|
||||||
"https://hub.docker.com/v2/repositories/${DH_USER}/${REPO_PURE}/" \
|
exit 1
|
||||||
-H "Authorization: JWT ${TOKEN}" \
|
fi
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d @payload.json)
|
- name: Commit, Tag and Push Changes
|
||||||
|
if: steps.check_changes.outputs.should_build == 'true'
|
||||||
HTTP_STATUS=$(echo "$RESPONSE" | tail -n 1)
|
run: |
|
||||||
BODY=$(echo "$RESPONSE" | head -n -1)
|
git config --local user.email "action@pi-farm.de"
|
||||||
|
git config --local user.name "Gitea Action"
|
||||||
if [ "$HTTP_STATUS" -eq 200 ]; then
|
|
||||||
echo "✅ README update successfull (HTTP 200)."
|
git add VERSION.history README.md docker-compose.yml
|
||||||
else
|
|
||||||
echo "❌ Error on update! HTTP Status: $HTTP_STATUS"
|
git diff --quiet && git diff --staged --quiet || git commit -m "${{ env.FINAL_MSG }} [skip ci]"
|
||||||
echo "Answer from Docker Hub: $BODY"
|
|
||||||
exit 1
|
TARGET_TAG="${{ steps.prep.outputs.docker_tag }}"
|
||||||
fi
|
git tag -f "$TARGET_TAG"
|
||||||
|
|
||||||
- name: Commit, Tag and Push Changes
|
if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then
|
||||||
if: steps.check_changes.outputs.should_build == 'true'
|
echo "🏷️ Build aus Tag getriggert: $TARGET_TAG"
|
||||||
run: |
|
git push -f origin "$TARGET_TAG"
|
||||||
git config --local user.email "action@pi-farm.de"
|
else
|
||||||
git config --local user.name "Gitea Action"
|
echo "🌿 Build aus Branch/Schedule getriggert: ${{ gitea.ref_name }}"
|
||||||
|
git push origin HEAD:${{ gitea.ref_name }}
|
||||||
git add VERSION.history README.md docker-compose.yml
|
git push -f origin "$TARGET_TAG"
|
||||||
|
fi
|
||||||
git diff --quiet && git diff --staged --quiet || git commit -m "${{ env.FINAL_MSG }} [skip ci]"
|
|
||||||
|
|
||||||
TARGET_TAG="${{ steps.prep.outputs.docker_tag }}"
|
|
||||||
git tag -f "$TARGET_TAG"
|
|
||||||
|
|
||||||
if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then
|
|
||||||
echo "🏷️ Build aus Tag getriggert: $TARGET_TAG"
|
|
||||||
git push -f origin "$TARGET_TAG"
|
|
||||||
else
|
|
||||||
echo "🌿 Build aus Branch/Schedule getriggert: ${{ gitea.ref_name }}"
|
|
||||||
git push origin HEAD:${{ gitea.ref_name }}
|
|
||||||
git push -f origin "$TARGET_TAG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Cleanup Temporary Tags on Docker Hub
|
- name: Cleanup Temporary Tags on Docker Hub
|
||||||
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
if: steps.check_changes.outputs.should_build == 'true' && contains(steps.prep.outputs.push_targets, 'dockerhub')
|
||||||
|
|||||||
Reference in new issue
Block a user