Kubernetes Operator for Tangled Spindles
1# Example workflow demonstrating buildah usage in Loom
2#
3# This workflow shows how to:
4# 1. Run tests in a standard container image
5# 2. Build an application binary
6# 3. Build a container image using buildah
7# 4. Push the image to a registry
8#
9# Prerequisites:
10# - Create a registry credentials secret (see registry-secret-example.yaml)
11# - Configure the secret in your SpindleSet template:
12# template:
13# registryCredentialsSecret: registry-credentials
14
15# Workflow metadata
16name: build-and-push.yaml
17image: golang:1.24-bookworm
18architecture: amd64
19
20# Workflow steps
21steps:
22 # Step 1: Run tests
23 - name: Run tests
24 command: |
25 echo "Running Go tests..."
26 go test -v ./...
27
28 # Step 2: Build application binary
29 - name: Build application
30 command: |
31 echo "Building application binary..."
32 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /tangled/workspace/app ./cmd
33
34 # Step 3: Create Dockerfile
35 - name: Create Dockerfile
36 command: |
37 cat > /tangled/workspace/Dockerfile <<'EOF'
38 FROM alpine:latest
39 RUN apk add --no-cache ca-certificates
40 COPY app /usr/local/bin/app
41 ENTRYPOINT ["/usr/local/bin/app"]
42 EOF
43 echo "Dockerfile created"
44
45 # Step 4: Build container image with buildah
46 - name: Build container image
47 command: |
48 echo "Building container image with buildah..."
49 cd /tangled/workspace
50
51 # Build the image (buildah is in PATH via /runner-bin)
52 buildah bud \
53 --storage-driver=overlay \
54 --tag registry.example.com/myapp:${TANGLED_COMMIT_SHA} \
55 --tag registry.example.com/myapp:latest \
56 .
57
58 echo "Container image built successfully"
59
60 # Step 5: Push image to registry
61 - name: Push container image
62 command: |
63 echo "Pushing image to registry..."
64
65 # Push both tags (buildah automatically uses credentials from /home/user/.docker/config.json)
66 buildah push \
67 --storage-driver=overlay \
68 registry.example.com/myapp:${TANGLED_COMMIT_SHA}
69
70 buildah push \
71 --storage-driver=overlay \
72 registry.example.com/myapp:latest
73
74 echo "Image pushed successfully"
75 echo "Image: registry.example.com/myapp:${TANGLED_COMMIT_SHA}"
76 echo "Image: registry.example.com/myapp:latest"