SHA256
60 lines
2.2 KiB
YAML
60 lines
2.2 KiB
YAML
name: Dynamic Build and Deploy Hardened Images
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
schedule:
|
|
- cron: '0 0 * * 5'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: local
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Log in to DHI Registry
|
|
run: |
|
|
echo "${{ secrets.DHI_PASSWORD }}" | docker login dhi.io -u "${{ secrets.DHI_USERNAME }}" --password-stdin
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
run: |
|
|
echo "${{ secrets.GITHUB_TOKEN }}" | docker login git.chillcog.com -u "${{ git.repository_owner }}" --password-stdin
|
|
|
|
- name: Detect and Build Images
|
|
run: |
|
|
FILES_TO_BUILD=""
|
|
REGISTRY_HOST="git.chillcog.com"
|
|
OWNER_LOWER=$(echo "${{ git.repository_owner }}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
if [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
echo "Scheduled or manual run triggered. Processing all YAML files..."
|
|
FILES_TO_BUILD=$(find . -maxdepth 1 -name "*.yml" -o -name "*.yaml")
|
|
else
|
|
echo "Push triggered. Detecting changed files..."
|
|
FILES_TO_BUILD=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} 2>/dev/null | grep -E '\.(yml|yaml)$' || true)
|
|
fi
|
|
|
|
for file in $FILES_TO_BUILD; do
|
|
file=$(echo "$file" | sed 's|^\./||')
|
|
if [ ! -f "$file" ]; then continue; fi
|
|
if [[ "$file" == .gitea/* ]]; then continue; fi
|
|
filename=$(basename -- "$file")
|
|
image_name=$(echo "${filename%.*}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
echo "---------------------------------------------------"
|
|
echo "Processing: $file -> Target: ${REGISTRY_HOST}/${OWNER_LOWER}/${image_name}:latest"
|
|
echo "---------------------------------------------------"
|
|
|
|
docker build \
|
|
-f "$file" \
|
|
-t "${REGISTRY_HOST}/${OWNER_LOWER}/${image_name}:latest" \
|
|
.
|
|
|
|
docker push "${REGISTRY_HOST}/${OWNER_LOWER}/${image_name}:latest"
|
|
done |