Skip to content

Commit bdfbf16

Browse files
fix: enhance Docker login process with credential checks and add dotenv support (#58)
Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
1 parent c40b22f commit bdfbf16

9 files changed

Lines changed: 82 additions & 9 deletions

File tree

.github/workflows/reusable-cron-check-dependencies.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ permissions:
4343
contents: read
4444
issues: write
4545
pull-requests: read
46+
packages: write
4647

4748
jobs:
4849
dependency-check:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Meta repository for [devops-infra](https://github.com/devops-infra) organization
22

3-
43
# Badge swag
54
[
65
![GitHub repo](https://img.shields.io/badge/GitHub-devops--infra%2F.github-blueviolet.svg?style=plastic&logo=github)

Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: '3'
22

33
silent: true
44

5+
dotenv:
6+
- .env
7+
58
includes:
69
variables: ./Taskfile.variables.yml
710
cicd:

templates/actions/taskfiles/Taskfile.docker.yml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,39 @@ tasks:
66
docker:login:
77
desc: Login to hub.docker.com and ghcr.io
88
cmds:
9-
- echo "Logging into Docker Hub as {{.DOCKER_USERNAME}}"
10-
- echo "${DOCKER_TOKEN}" | docker login -u "{{.DOCKER_USERNAME}}" --password-stdin
11-
- echo "Logging into GHCR as {{.GITHUB_USERNAME}}"
12-
- echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "{{.GITHUB_USERNAME}}" --password-stdin
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
1342
1443
docker:cmds:
1544
desc: Show full docker build command

templates/actions/taskfiles/Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: '3'
22

33
silent: true
44

5+
dotenv:
6+
- .env
7+
58
includes:
69
variables: ./Taskfile.variables.yml
710
cicd:

templates/dockerized/taskfiles/Taskfile.docker.yml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,39 @@ tasks:
66
docker:login:
77
desc: Login to hub.docker.com and ghcr.io
88
cmds:
9-
- echo "Logging into Docker Hub as {{.DOCKER_USERNAME}}"
10-
- echo "${DOCKER_TOKEN}" | docker login -u "{{.DOCKER_USERNAME}}" --password-stdin
11-
- echo "Logging into GHCR as {{.GITHUB_USERNAME}}"
12-
- echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "{{.GITHUB_USERNAME}}" --password-stdin
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
1342
1443
docker:cmds:
1544
desc: Show full docker build command

templates/dockerized/taskfiles/Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: '3'
22

33
silent: true
44

5+
dotenv:
6+
- .env
7+
58
includes:
69
variables: ./Taskfile.variables.yml
710
scripts: ./Taskfile.scripts.yml

templates/other/taskfiles/Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: '3'
22

33
silent: true
44

5+
dotenv:
6+
- .env
7+
58
includes:
69
variables: ./Taskfile.variables.yml
710
scripts: ./Taskfile.scripts.yml

templates/static/taskfiles/Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: '3'
22

33
silent: true
44

5+
dotenv:
6+
- .env
7+
58
includes:
69
variables: ./Taskfile.variables.yml
710
scripts: ./Taskfile.scripts.yml

0 commit comments

Comments
 (0)