Docker image pre-pull.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
name: "Pre-pull or Build Docker images"
|
||||
description: "Prepares all services for docker compose dry-run by pulling images or building them"
|
||||
name: "Pre-pull/build Docker images in parallel with timing"
|
||||
description: "Prepares all services for docker compose dry-run by pulling or building them concurrently with logs"
|
||||
inputs:
|
||||
services:
|
||||
description: "Space-separated list of docker-compose services"
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
@@ -12,26 +11,38 @@ runs:
|
||||
shell: bash
|
||||
run: |
|
||||
if ! command -v yq >/dev/null 2>&1; then
|
||||
echo "Installing yq..."
|
||||
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64
|
||||
sudo chmod +x /usr/local/bin/yq
|
||||
fi
|
||||
|
||||
- name: Pre-pull/build images for services
|
||||
- name: Pre-pull/build images in parallel
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Services to resolve: ${{ inputs.services }}"
|
||||
for svc in ${{ inputs.services }}; do
|
||||
echo "Resolving image for service: $svc"
|
||||
image=$(docker compose config | yq -r ".services[\"$svc\"].image // empty")
|
||||
build_dir=$(docker compose config | yq -r ".services[\"$svc\"].build.context // empty")
|
||||
SERVICES="${{ inputs.services }}"
|
||||
echo "Services to process: $SERVICES"
|
||||
for svc in $SERVICES; do
|
||||
(
|
||||
echo "🔹 Starting prep for service: $svc"
|
||||
start_time=$(date +%s)
|
||||
|
||||
if [ -n "$image" ]; then
|
||||
echo "Pulling image: $image"
|
||||
docker pull "$image"
|
||||
elif [ -n "$build_dir" ]; then
|
||||
echo "Building image for service: $svc from context: $build_dir"
|
||||
docker compose build "$svc"
|
||||
else
|
||||
echo "⚠️ No image or build context for $svc — skipping"
|
||||
fi
|
||||
image=$(docker compose config | yq -r ".services[\"$svc\"].image // empty")
|
||||
build_dir=$(docker compose config | yq -r ".services[\"$svc\"].build.context // empty")
|
||||
|
||||
if [ -n "$image" ]; then
|
||||
echo "➡️ Pulling image: $image"
|
||||
docker pull "$image"
|
||||
elif [ -n "$build_dir" ]; then
|
||||
echo "⚙️ Building service: $svc from context: $build_dir"
|
||||
docker compose build "$svc"
|
||||
else
|
||||
echo "⚠️ No image or build context found for $svc — skipping"
|
||||
fi
|
||||
|
||||
end_time=$(date +%s)
|
||||
duration=$((end_time - start_time))
|
||||
echo "✅ Finished $svc in ${duration}s"
|
||||
) &
|
||||
done
|
||||
wait
|
||||
echo "🎯 All services processed."
|
||||
|
||||
Reference in New Issue
Block a user