fix(cd): flatten matrix target
This commit is contained in:
+24
-20
@@ -43,7 +43,7 @@ jobs:
|
|||||||
img_pre, wl_pre = NAME_OVERRIDE.get(svc, (svc, svc))
|
img_pre, wl_pre = NAME_OVERRIDE.get(svc, (svc, svc))
|
||||||
image = f"{img_pre}-{sub}"
|
image = f"{img_pre}-{sub}"
|
||||||
workload = STATEFULSETS.get(image, f"{wl_pre}-{sub}")
|
workload = STATEFULSETS.get(image, f"{wl_pre}-{sub}")
|
||||||
targets.append({"image": image, "dir": d, "workload": workload})
|
targets.append(f"{image}|{d}|{workload}")
|
||||||
print("targets=" + json.dumps(targets))
|
print("targets=" + json.dumps(targets))
|
||||||
PY
|
PY
|
||||||
|
|
||||||
@@ -68,11 +68,16 @@ jobs:
|
|||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Generate Dockerfile
|
- name: Build and push
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ env.REGISTRY }}
|
||||||
|
REPO: ${{ env.REPO }}
|
||||||
|
TARGET: ${{ matrix.target }}
|
||||||
|
SHA_TAG: ${{ needs.discover.outputs.short_sha }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
dir='${{ matrix.target.dir }}'
|
IFS='|' read -r image dir _workload <<< "$TARGET"
|
||||||
entry=$(grep -l "package main" "$dir"/*.go | head -n1)
|
entry=$(grep -l "package main" "$dir"/*.go | head -n1)
|
||||||
cfg=$(basename "$(find "$dir/etc" -maxdepth 1 -name '*.yaml' | head -n1)" 2>/dev/null || echo config.yaml)
|
cfg=$(basename "$(find "$dir/etc" -maxdepth 1 -name '*.yaml' | head -n1)" 2>/dev/null || echo config.yaml)
|
||||||
cat > Dockerfile.build <<EOF
|
cat > Dockerfile.build <<EOF
|
||||||
@@ -94,18 +99,16 @@ jobs:
|
|||||||
COPY $dir/etc /app/etc
|
COPY $dir/etc /app/etc
|
||||||
CMD ["./main", "-f", "etc/$cfg"]
|
CMD ["./main", "-f", "etc/$cfg"]
|
||||||
EOF
|
EOF
|
||||||
|
IMAGE="$REGISTRY/$REPO/$image"
|
||||||
- name: Build and push
|
CACHE="$REGISTRY/$REPO/buildcache:$image"
|
||||||
uses: docker/build-push-action@v6
|
docker buildx build \
|
||||||
with:
|
--file Dockerfile.build \
|
||||||
context: .
|
--tag "$IMAGE:$SHA_TAG" \
|
||||||
file: Dockerfile.build
|
--tag "$IMAGE:latest" \
|
||||||
push: true
|
--cache-from "type=registry,ref=$CACHE" \
|
||||||
tags: |
|
--cache-to "type=registry,ref=$CACHE,mode=max" \
|
||||||
${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.target.image }}:${{ needs.discover.outputs.short_sha }}
|
--push \
|
||||||
${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.target.image }}:latest
|
.
|
||||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPO }}/buildcache:${{ matrix.target.image }}
|
|
||||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPO }}/buildcache:${{ matrix.target.image }},mode=max
|
|
||||||
|
|
||||||
rollout:
|
rollout:
|
||||||
needs: [discover, build]
|
needs: [discover, build]
|
||||||
@@ -119,6 +122,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Rollout k01
|
- name: Rollout k01
|
||||||
env:
|
env:
|
||||||
|
REGISTRY: ${{ env.REGISTRY }}
|
||||||
|
REPO: ${{ env.REPO }}
|
||||||
KUBECONFIG_B64: ${{ secrets.K01_KUBECONFIG }}
|
KUBECONFIG_B64: ${{ secrets.K01_KUBECONFIG }}
|
||||||
SHA_TAG: ${{ needs.discover.outputs.short_sha }}
|
SHA_TAG: ${{ needs.discover.outputs.short_sha }}
|
||||||
TARGETS: ${{ needs.discover.outputs.targets }}
|
TARGETS: ${{ needs.discover.outputs.targets }}
|
||||||
@@ -133,11 +138,10 @@ jobs:
|
|||||||
import json, subprocess, os
|
import json, subprocess, os
|
||||||
reg = os.environ["REGISTRY"] + "/" + os.environ["REPO"]
|
reg = os.environ["REGISTRY"] + "/" + os.environ["REPO"]
|
||||||
for t in json.loads(os.environ["TARGETS"]):
|
for t in json.loads(os.environ["TARGETS"]):
|
||||||
img = t["image"]
|
image, _, workload = t.split("|")
|
||||||
wl = t["workload"]
|
kind = "statefulset" if workload == "snowflake" else "deployment"
|
||||||
kind = "statefulset" if wl == "snowflake" else "deployment"
|
ref = f"{reg}/{image}:{os.environ['SHA_TAG']}"
|
||||||
ref = f"{reg}/{img}:{os.environ['SHA_TAG']}"
|
cmd = ["kubectl","-n","juwan","set","image",f"{kind}/{workload}",f"{image}={ref}"]
|
||||||
cmd = ["kubectl","-n","juwan","set","image",f"{kind}/{wl}",f"{img}={ref}"]
|
|
||||||
print(" ".join(cmd))
|
print(" ".join(cmd))
|
||||||
subprocess.run(cmd, check=False)
|
subprocess.run(cmd, check=False)
|
||||||
PY
|
PY
|
||||||
|
|||||||
Reference in New Issue
Block a user