Skip to content

Commit dab87f5

Browse files
fix: restore Taskfile.docker.yml
1 parent 6f0bba4 commit dab87f5

2 files changed

Lines changed: 254 additions & 0 deletions

File tree

templates/actions/taskfiles/Taskfile.docker.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,130 @@ version: '3'
33
silent: true
44

55
tasks:
6+
docker:login:
7+
desc: Login to hub.docker.com and ghcr.io
8+
cmds:
9+
- |
10+
set -eu
11+
docker_username='{{.DOCKER_USERNAME}}'
12+
github_username='{{.GITHUB_USERNAME}}'
13+
has_dockerhub=false
14+
has_ghcr=false
15+
16+
if [ -n "$docker_username" ] && [ -n "${DOCKER_TOKEN:-}" ]; then
17+
has_dockerhub=true
18+
fi
19+
20+
if [ -n "$github_username" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
21+
has_ghcr=true
22+
fi
23+
24+
if [ "$has_dockerhub" = false ] && [ "$has_ghcr" = false ]; then
25+
echo "❌ No registry credentials provided. Set DOCKER_USERNAME/DOCKER_TOKEN or GITHUB_USERNAME/GITHUB_TOKEN."
26+
exit 1
27+
fi
28+
29+
if [ "$has_dockerhub" = true ]; then
30+
echo "Logging into Docker Hub as $docker_username"
31+
printf '%s' "${DOCKER_TOKEN}" | docker login -u "$docker_username" --password-stdin
32+
else
33+
echo "⚠️ Skipping Docker Hub login (missing DOCKER_USERNAME/DOCKER_TOKEN)"
34+
fi
35+
36+
if [ "$has_ghcr" = true ]; then
37+
echo "Logging into GHCR as $github_username"
38+
printf '%s' "${GITHUB_TOKEN}" | docker login ghcr.io -u "$github_username" --password-stdin
39+
else
40+
echo "⚠️ Skipping GHCR login (missing GITHUB_USERNAME/GITHUB_TOKEN)"
41+
fi
42+
43+
docker:cmds:
44+
desc: Show full docker build command
45+
cmds:
46+
- echo -e '{{.DOCKER_BUILD_START}} {{.DOCKER_BUILD_FINISH}}' | {{.SED}} 's/--/ \\\n+ --/g'
47+
48+
docker:build:
49+
desc: Build Docker image
50+
cmds:
51+
- docker buildx create --use
52+
- '{{.DOCKER_BUILD_START}} {{.DOCKER_BUILD_FINISH}}'
53+
54+
docker:build:inspect:
55+
desc: Inspect built Docker image
56+
cmds:
57+
- |
58+
image_inspect_out=$(docker image inspect {{.DOCKER_NAME}}:{{.VERSION_FULL}}{{.VERSION_SUFFIX}} | jq -r)
59+
echo -e "\nℹ️ Docker image inspect:"
60+
echo "$image_inspect_out" | jq
61+
62+
docker:push:
63+
desc: Build and push Docker images
64+
deps:
65+
- task: docker:login
66+
cmds:
67+
- docker buildx create --use
68+
- '{{.DOCKER_BUILD_START}} --push {{.DOCKER_BUILD_FINISH}}'
69+
70+
docker:push:inspect:
71+
desc: Inspect built Docker image
72+
cmds:
73+
- |
74+
set -eu
75+
image="{{.DOCKER_NAME}}:{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
76+
77+
echo -e "\nℹ️ Trying local image inspect: $image"
78+
set +e
79+
image_inspect_out=$(docker image inspect "$image" 2>/dev/null || true)
80+
rc=$?
81+
set -e
82+
83+
has_local=0
84+
if [ "$rc" -eq 0 ] && [ -n "$image_inspect_out" ]; then
85+
if echo "$image_inspect_out" | jq -e 'type=="array" and (length > 0) and \
86+
(.[0].Id != null and .[0].Id != "")' >/dev/null 2>&1; then
87+
has_local=1
88+
fi
89+
fi
90+
91+
if [ "$has_local" -eq 1 ]; then
92+
echo -e "\n✅ Local image found. Docker image inspect:"
93+
echo "$image_inspect_out" | jq
94+
image_sha=$(echo "$image_inspect_out" | jq -r '.[0].Id // empty')
95+
if [ -n "$image_sha" ]; then
96+
echo -e "\nℹ️ Docker manifest inspect (local):"
97+
docker manifest inspect "${image}@${image_sha}" | jq || true
98+
fi
99+
exit 0
100+
fi
101+
102+
echo -e "\nℹ️ Local image not found or inspect returned empty; inspecting remote with buildx imagetools..."
103+
set +e
104+
raw=$(docker buildx imagetools inspect --raw "$image" 2>/dev/null || true)
105+
set -e
106+
107+
if [ -z "$raw" ]; then
108+
echo "❌ Failed to inspect remote image with buildx imagetools: $image"
109+
exit 1
110+
fi
111+
112+
echo -e "\n✅ Remote manifest/index (raw):"
113+
echo "$raw" | jq
114+
115+
echo -e "\nℹ️ Attempting to pull and inspect per-platform manifests:"
116+
echo "$raw" | jq -r '.manifests[]?.digest' | while IFS= read -r digest; do
117+
if [ -z "$digest" ] || [ "$digest" = "null" ]; then
118+
continue
119+
fi
120+
ref="${image%@*}@${digest}"
121+
echo -e "\nℹ️ Pulling $ref (may fail for some registries)..."
122+
set +e
123+
docker pull "$ref" >/dev/null 2>&1 || true
124+
pulled_rc=$?
125+
set -e
126+
if [ "$pulled_rc" -eq 0 ]; then
127+
echo "ℹ️ Inspecting pulled image $ref"
128+
docker image inspect "$ref" | jq || true
129+
else
130+
echo "⚠️ Could not pull $ref; skipping image inspect"
131+
fi
132+
done

templates/dockerized/taskfiles/Taskfile.docker.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,130 @@ version: '3'
33
silent: true
44

55
tasks:
6+
docker:login:
7+
desc: Login to hub.docker.com and ghcr.io
8+
cmds:
9+
- |
10+
set -eu
11+
docker_username='{{.DOCKER_USERNAME}}'
12+
github_username='{{.GITHUB_USERNAME}}'
13+
has_dockerhub=false
14+
has_ghcr=false
15+
16+
if [ -n "$docker_username" ] && [ -n "${DOCKER_TOKEN:-}" ]; then
17+
has_dockerhub=true
18+
fi
19+
20+
if [ -n "$github_username" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
21+
has_ghcr=true
22+
fi
23+
24+
if [ "$has_dockerhub" = false ] && [ "$has_ghcr" = false ]; then
25+
echo "❌ No registry credentials provided. Set DOCKER_USERNAME/DOCKER_TOKEN or GITHUB_USERNAME/GITHUB_TOKEN."
26+
exit 1
27+
fi
28+
29+
if [ "$has_dockerhub" = true ]; then
30+
echo "Logging into Docker Hub as $docker_username"
31+
printf '%s' "${DOCKER_TOKEN}" | docker login -u "$docker_username" --password-stdin
32+
else
33+
echo "⚠️ Skipping Docker Hub login (missing DOCKER_USERNAME/DOCKER_TOKEN)"
34+
fi
35+
36+
if [ "$has_ghcr" = true ]; then
37+
echo "Logging into GHCR as $github_username"
38+
printf '%s' "${GITHUB_TOKEN}" | docker login ghcr.io -u "$github_username" --password-stdin
39+
else
40+
echo "⚠️ Skipping GHCR login (missing GITHUB_USERNAME/GITHUB_TOKEN)"
41+
fi
42+
43+
docker:cmds:
44+
desc: Show full docker build command
45+
cmds:
46+
- echo -e '{{.DOCKER_BUILD_START}} {{.DOCKER_BUILD_FINISH}}' | {{.SED}} 's/--/ \\\n+ --/g'
47+
48+
docker:build:
49+
desc: Build Docker image
50+
cmds:
51+
- docker buildx create --use
52+
- '{{.DOCKER_BUILD_START}} {{.DOCKER_BUILD_FINISH}}'
53+
54+
docker:build:inspect:
55+
desc: Inspect built Docker image
56+
cmds:
57+
- |
58+
image_inspect_out=$(docker image inspect {{.DOCKER_NAME}}:{{.VERSION_FULL}}{{.VERSION_SUFFIX}} | jq -r)
59+
echo -e "\nℹ️ Docker image inspect:"
60+
echo "$image_inspect_out" | jq
61+
62+
docker:push:
63+
desc: Build and push Docker images
64+
deps:
65+
- task: docker:login
66+
cmds:
67+
- docker buildx create --use
68+
- '{{.DOCKER_BUILD_START}} --push {{.DOCKER_BUILD_FINISH}}'
69+
70+
docker:push:inspect:
71+
desc: Inspect built Docker image
72+
cmds:
73+
- |
74+
set -eu
75+
image="{{.DOCKER_NAME}}:{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
76+
77+
echo -e "\nℹ️ Trying local image inspect: $image"
78+
set +e
79+
image_inspect_out=$(docker image inspect "$image" 2>/dev/null || true)
80+
rc=$?
81+
set -e
82+
83+
has_local=0
84+
if [ "$rc" -eq 0 ] && [ -n "$image_inspect_out" ]; then
85+
if echo "$image_inspect_out" | jq -e 'type=="array" and (length > 0) and \
86+
(.[0].Id != null and .[0].Id != "")' >/dev/null 2>&1; then
87+
has_local=1
88+
fi
89+
fi
90+
91+
if [ "$has_local" -eq 1 ]; then
92+
echo -e "\n✅ Local image found. Docker image inspect:"
93+
echo "$image_inspect_out" | jq
94+
image_sha=$(echo "$image_inspect_out" | jq -r '.[0].Id // empty')
95+
if [ -n "$image_sha" ]; then
96+
echo -e "\nℹ️ Docker manifest inspect (local):"
97+
docker manifest inspect "${image}@${image_sha}" | jq || true
98+
fi
99+
exit 0
100+
fi
101+
102+
echo -e "\nℹ️ Local image not found or inspect returned empty; inspecting remote with buildx imagetools..."
103+
set +e
104+
raw=$(docker buildx imagetools inspect --raw "$image" 2>/dev/null || true)
105+
set -e
106+
107+
if [ -z "$raw" ]; then
108+
echo "❌ Failed to inspect remote image with buildx imagetools: $image"
109+
exit 1
110+
fi
111+
112+
echo -e "\n✅ Remote manifest/index (raw):"
113+
echo "$raw" | jq
114+
115+
echo -e "\nℹ️ Attempting to pull and inspect per-platform manifests:"
116+
echo "$raw" | jq -r '.manifests[]?.digest' | while IFS= read -r digest; do
117+
if [ -z "$digest" ] || [ "$digest" = "null" ]; then
118+
continue
119+
fi
120+
ref="${image%@*}@${digest}"
121+
echo -e "\nℹ️ Pulling $ref (may fail for some registries)..."
122+
set +e
123+
docker pull "$ref" >/dev/null 2>&1 || true
124+
pulled_rc=$?
125+
set -e
126+
if [ "$pulled_rc" -eq 0 ]; then
127+
echo "ℹ️ Inspecting pulled image $ref"
128+
docker image inspect "$ref" | jq || true
129+
else
130+
echo "⚠️ Could not pull $ref; skipping image inspect"
131+
fi
132+
done

0 commit comments

Comments
 (0)