Docker image pre-pull.

This commit is contained in:
2025-10-02 08:04:29 -04:00
parent 8f61e56744
commit a96075ab3b
2 changed files with 49 additions and 29 deletions
+32 -14
View File
@@ -1,21 +1,41 @@
name: "Pre-pull/build Docker images in parallel"
description: "Prepares services for docker compose dry-run by pulling or building them concurrently"
name: "Pre-pull Docker Compose service images"
description: "Prepares Docker Compose services by pulling images in parallel before dry-run"
author: "Your Name <you@example.com>"
inputs:
services:
description: "Space-separated list of docker-compose services"
description: "Space-separated list of Docker Compose services"
required: true
compose_profile:
description: "Docker Compose profile to use (optional)"
required: false
default: ""
env_file:
description: "Path to .env file (optional)"
required: false
default: ".env"
runs:
using: "composite"
steps:
- name: Install yq
shell: bash
run: |
if ! command -v yq >/dev/null; then
echo "Installing yq..."
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
chmod +x /usr/local/bin/yq
fi
- name: Pre-pull/build services
shell: bash
run: |
set -euo pipefail
SERVICES="${{ inputs.services }}"
PROFILE="${{ inputs.compose_profile }}"
ENV_FILE="${{ inputs.env_file }}"
if [ -z "$SERVICES" ]; then
echo "❌ No services provided. Exiting."
exit 1
@@ -24,28 +44,26 @@ runs:
echo "Services to process:"
echo "$SERVICES"
CONFIG_CMD="docker compose"
if [ -n "$PROFILE" ]; then
CONFIG_CMD="$CONFIG_CMD --profile $PROFILE"
fi
CONFIG_CMD="$CONFIG_CMD --env-file $ENV_FILE config"
for svc in $SERVICES; do
(
echo "🔹 Starting prep for service: $svc"
start_time=$(date +%s)
# Get image name; default to empty string if missing
image=$(docker compose config | yq -r ".services[\"$svc\"].image // \"\"")
# Get build context; default to empty string if missing
build_dir=$(docker compose config | yq -r ".services[\"$svc\"].build.context // \"\"")
image=$(eval $CONFIG_CMD | yq -r ".services[\"$svc\"].image // \"\"")
if [ -n "$image" ]; then
if [ -n "$image" ] && [ "$image" != "null" ]; then
echo "➡️ Pulling image for $svc: $image"
if ! docker pull "$image"; then
echo "⚠️ Failed to pull image $image for service $svc"
fi
elif [ -n "$build_dir" ]; then
echo "⚙️ Building service: $svc from context: $build_dir"
if ! docker compose build "$svc"; then
echo "⚠️ Failed to build service $svc"
fi
else
echo "⚠️ No image or build context for $svc — skipping"
echo "⚠️ No image defined for $svc — skipping"
fi
end_time=$(date +%s)
@@ -180,18 +180,18 @@ jobs:
username: ${{ secrets.BOT_GITEA_USER }}
password: ${{ secrets.BOT_GITEA_PASSWORD }}
- name: Install Vault (only if not cached)
uses: cpanato/vault-installer@main
with:
version: ${{ env.HC_VAULT_VERSION }}
# - name: Get env file
# uses: Simporter/get-env-file-from-vault@v1.0.3
# - name: Install Vault (only if not cached)
# uses: cpanato/vault-installer@main
# with:
# VAULT_ADDR: ${{ secrets.TREZ_VAULT_ADDR }}
# VAULT_USERNAME: ${{ secrets.VAULT_GITEA_USER }}
# VAULT_PASSWORD: ${{ secrets.VAULT_GITEA_PASSWORD }}
# VAULT_SECRETS_PATH: rinoa-docker/env
# version: ${{ env.HC_VAULT_VERSION }}
- name: Generate .env file from Hashicorp Vault
uses: Simporter/get-env-file-from-vault@v1.0.3
with:
VAULT_ADDR: ${{ secrets.TREZ_VAULT_ADDR }}
VAULT_USERNAME: ${{ secrets.VAULT_GITEA_USER }}
VAULT_PASSWORD: "${{ secrets.VAULT_GITEA_PASSWORD }}"
VAULT_SECRETS_PATH: rinoa-docker/env
- name: Gotify Notification
uses: eikendev/gotify-action@master
@@ -201,15 +201,17 @@ jobs:
notification_title: "GITEA: Docker Compose Dry Run @ Rinoa"
notification_message: "Starting Docker Compose dry run..."
- name: Generate .env file for Docker Compose
run: |
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
echo ${DOCKER_SVC_LIST}
# - name: Generate .env file for Docker Compose
# run: |
# vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
# echo ${DOCKER_SVC_LIST}
- name: Pre-pull/build service images in parallel
uses: ./.gitea/actions/docker-img-pre-pull
with:
services: ${{ env.DOCKER_SVC_LIST }}
compose_profile: "rinoa-apps"
env_file: ".env"
- name: Docker Compose Dry Run
uses: hoverkraft-tech/compose-action@b716db5b717cb9b81e391fe638e5aceaa2299e43 # v2.4.0