Skip to content

Commit 514bb50

Browse files
committed
2 parents 7005cc5 + adc41a0 commit 514bb50

2 files changed

Lines changed: 12 additions & 108 deletions

File tree

.github/workflows/docker.yml

Lines changed: 9 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: docker
22

3-
# run on pushes to main and on tags; adjust to taste
43
on:
54
push:
65
branches: [ main ]
@@ -16,11 +15,8 @@ jobs:
1615
build-and-push:
1716
runs-on: ubuntu-latest
1817
env:
19-
# registry to push to. Change to docker.io if you prefer.
20-
REGISTRY: ghcr.io
21-
# owner that will own the pushed images. Defaults to repository owner.
22-
OWNER: ${{ github.repository_owner }}
23-
# short commit SHA tag
18+
REGISTRY: docker.io
19+
OWNER: mrminede
2420
COMMIT_SHORT: ${{ github.sha }}
2521
steps:
2622
- name: Shorten commit SHA
@@ -32,7 +28,7 @@ jobs:
3228
with:
3329
fetch-depth: 0
3430

35-
- name: Set up QEMU (optional for multi-arch builds)
31+
- name: Set up QEMU
3632
uses: docker/setup-qemu-action@v2
3733

3834
- name: Set up Docker Buildx
@@ -41,103 +37,11 @@ jobs:
4137
- name: Login to container registry
4238
uses: docker/login-action@v2
4339
with:
44-
registry: ${{ env.REGISTRY }}
45-
username: ${{ github.actor }}
46-
# For GHCR the GITHUB_TOKEN usually works. For Docker Hub use a secret (DOCKERHUB_USERNAME/DOCKERHUB_TOKEN).
47-
password: ${{ secrets.GITHUB_TOKEN }}
40+
username: ${{ secrets.DOCKERHUB_USERNAME }}
41+
password: ${{ secrets.DOCKERHUB_TOKEN }}
4842

49-
- name: Build all compose services
50-
# uses the Docker Compose CLI shipped with Docker; this runs 'docker compose build'
51-
run: |
52-
docker compose -f docker/docker-compose.yml build --pull
43+
- name: Build images
44+
run: docker compose -f docker/docker-compose.yml build --pull
5345

54-
- name: Tag & push built images
55-
run: |
56-
set -euo pipefail
57-
58-
REGISTRY=${{ env.REGISTRY }}
59-
OWNER=${{ env.OWNER }}
60-
SHA=${{ env.COMMIT_SHORT }}
61-
REPO_NAME=${{ github.event.repository.name }}
62-
63-
echo "Registry: $REGISTRY"
64-
echo "Owner: $OWNER"
65-
echo "Repo: $REPO_NAME"
66-
echo "Tag: $SHA"
67-
68-
# list services defined in compose
69-
services=$(docker compose -f docker/docker-compose.yml config --services)
70-
if [ -z "$services" ]; then
71-
echo "No services found in docker-compose.yml"
72-
exit 1
73-
fi
74-
75-
# decide whether to push 'latest' as well
76-
push_latest=false
77-
if [[ "${GITHUB_REF:-}" == "refs/heads/main" ]] || [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
78-
push_latest=true
79-
fi
80-
81-
for svc in $services; do
82-
echo "Checking service: $svc"
83-
84-
# Extract IMAGE and whether a build: exists for this service from 'docker compose config'
85-
svc_info=$(docker compose -f docker/docker-compose.yml config | awk -v svc="$svc" '
86-
$0 ~ "services:" { in_services=1 }
87-
in_services && $0 ~ "^[[:space:]]*"svc":" { in_svc=1; next }
88-
in_svc && $0 ~ "^[[:space:]]*[^[:space:]]" { exit }
89-
in_svc {
90-
if ($1 == "image:") { gsub(/"/,"",$2); print "IMAGE="$2 }
91-
if ($1 == "build:") { print "HASBUILD=1" }
92-
}
93-
')
94-
95-
# evaluate the small KEY=VAL output (safe in CI)
96-
unset IMAGE HASBUILD
97-
eval "$svc_info" || true
98-
99-
# only process services that have both build: and image:
100-
if [ -z "${IMAGE:-}" ] || [ -z "${HASBUILD:-}" ]; then
101-
echo "Skipping $svc (requires both build: and image:)."
102-
continue
103-
fi
104-
105-
echo "Service $svc has build and image -> $IMAGE"
106-
107-
# determine source reference for tagging: prefer compose image id, then image:latest, then image (no tag)
108-
src_ref=""
109-
imgid=$(docker compose -f docker/docker-compose.yml images -q "$svc" 2>/dev/null || true)
110-
if [ -n "$imgid" ]; then
111-
src_ref="$imgid"
112-
elif docker image inspect "$IMAGE:latest" >/dev/null 2>&1; then
113-
src_ref="$IMAGE:latest"
114-
elif docker image inspect "$IMAGE" >/dev/null 2>&1; then
115-
src_ref="$IMAGE"
116-
else
117-
echo "No built image found for $svc (expected $IMAGE). Did the build step succeed?"
118-
exit 1
119-
fi
120-
121-
target="$REGISTRY/$OWNER/${REPO_NAME}-$svc:$SHA"
122-
echo "Tagging $src_ref -> $target"
123-
docker tag "$src_ref" "$target"
124-
125-
echo "Pushing $target"
126-
docker push "$target"
127-
128-
if [ "$push_latest" = true ]; then
129-
latest_tag="$REGISTRY/$OWNER/${REPO_NAME}-$svc:latest"
130-
echo "Also tagging & pushing latest: $latest_tag"
131-
docker tag "$src_ref" "$latest_tag"
132-
docker push "$latest_tag"
133-
fi
134-
135-
# clean up variables for next iteration
136-
unset IMAGE HASBUILD src_ref imgid
137-
done
138-
139-
echo "All done. Images pushed."
140-
141-
- name: Output pushed images
142-
run: |
143-
echo "Images pushed for commit $COMMIT_SHORT"
46+
- name: Push images
47+
run: docker compose -f docker/docker-compose.yml push

docker/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ networks:
66
- subnet: 172.28.0.0/16
77
services:
88
backend:
9-
image: ghcr.io/mminl-de/interscore-backend
9+
image: mrminede/interscore-backend
1010
build:
1111
context: ..
1212
dockerfile: docker/backend/Dockerfile
@@ -32,7 +32,7 @@ services:
3232
"
3333
3434
http-server:
35-
image: ghcr.io/mminl-de/interscore-http-server
35+
image: mrminede/interscore-http-server
3636
build:
3737
context: ..
3838
dockerfile: docker/http-server/Dockerfile
@@ -53,7 +53,7 @@ services:
5353
restart: unless-stopped
5454

5555
obs:
56-
image: ghcr.io/mminl-de/obs
56+
image: mrminede/obs
5757
build:
5858
context: ..
5959
dockerfile: docker/obs/Dockerfile

0 commit comments

Comments
 (0)