|
| 1 | +name: Deploy and Verify on Azure AKS |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + resource_group: |
| 7 | + description: Azure resource group containing AKS |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + aks_cluster: |
| 11 | + description: AKS cluster name |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + id-token: write |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + deploy-and-verify: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 20 |
| 23 | + env: |
| 24 | + NAMESPACE: capsule-test-${{ github.run_id }} |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Set up Go |
| 31 | + uses: actions/setup-go@v5 |
| 32 | + with: |
| 33 | + go-version: '^1.24' |
| 34 | + cache: true |
| 35 | + |
| 36 | + - name: Build binary |
| 37 | + run: | |
| 38 | + go build -v -o basic-docker . |
| 39 | + chmod +x basic-docker |
| 40 | + sudo mv basic-docker /usr/local/bin/ |
| 41 | + which basic-docker |
| 42 | +
|
| 43 | + - name: Azure login |
| 44 | + uses: azure/login@v2 |
| 45 | + with: |
| 46 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 47 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 48 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 49 | + |
| 50 | + - name: Set AKS context |
| 51 | + run: | |
| 52 | + az aks get-credentials \ |
| 53 | + --resource-group "${{ inputs.resource_group }}" \ |
| 54 | + --name "${{ inputs.aks_cluster }}" \ |
| 55 | + --overwrite-existing |
| 56 | + kubectl cluster-info |
| 57 | + kubectl get nodes |
| 58 | +
|
| 59 | + - name: Create test resources in AKS |
| 60 | + run: | |
| 61 | + kubectl create namespace "$NAMESPACE" |
| 62 | + kubectl apply -f k8s/crd-resourcecapsule.yaml |
| 63 | + kubectl wait --for=condition=established --timeout=60s crd/resourcecapsules.capsules.docker.io |
| 64 | +
|
| 65 | + cat <<EOF | kubectl apply -f - -n "$NAMESPACE" |
| 66 | + apiVersion: v1 |
| 67 | + kind: ConfigMap |
| 68 | + metadata: |
| 69 | + name: test-config-1.0 |
| 70 | + labels: |
| 71 | + capsule.docker.io/name: test-config |
| 72 | + capsule.docker.io/version: "1.0" |
| 73 | + data: |
| 74 | + config.yml: | |
| 75 | + testKey: testValue |
| 76 | + environment: azure-aks |
| 77 | + EOF |
| 78 | +
|
| 79 | + cat <<EOF | kubectl apply -f - -n "$NAMESPACE" |
| 80 | + apiVersion: capsules.docker.io/v1 |
| 81 | + kind: ResourceCapsule |
| 82 | + metadata: |
| 83 | + name: test-crd-capsule |
| 84 | + spec: |
| 85 | + data: |
| 86 | + config.yaml: | |
| 87 | + testKey: testValue |
| 88 | + environment: azure-aks |
| 89 | + version: "1.0" |
| 90 | + capsuleType: configmap |
| 91 | + rollback: |
| 92 | + enabled: true |
| 93 | + EOF |
| 94 | +
|
| 95 | + cat <<EOF | kubectl apply -f - -n "$NAMESPACE" |
| 96 | + apiVersion: apps/v1 |
| 97 | + kind: Deployment |
| 98 | + metadata: |
| 99 | + name: test-app |
| 100 | + spec: |
| 101 | + replicas: 1 |
| 102 | + selector: |
| 103 | + matchLabels: |
| 104 | + app: test-app |
| 105 | + template: |
| 106 | + metadata: |
| 107 | + labels: |
| 108 | + app: test-app |
| 109 | + spec: |
| 110 | + containers: |
| 111 | + - name: nginx |
| 112 | + image: nginx:alpine |
| 113 | + ports: |
| 114 | + - containerPort: 80 |
| 115 | + EOF |
| 116 | +
|
| 117 | + kubectl wait --for=condition=Available deployment/test-app -n "$NAMESPACE" --timeout=120s |
| 118 | +
|
| 119 | + - name: Verify ResourceCapsule concepts |
| 120 | + run: | |
| 121 | + kubectl get resourcecapsule test-crd-capsule -n "$NAMESPACE" -o yaml |
| 122 | + kubectl get configmap test-config-1.0 -n "$NAMESPACE" -o yaml |
| 123 | +
|
| 124 | + - name: Verify capsule create command |
| 125 | + run: | |
| 126 | + mkdir -p /tmp/capsules |
| 127 | + echo "test-config data from aks" > /tmp/capsules/test-config |
| 128 | + basic-docker k8s-capsule create test-config 1.0 /tmp/capsules/test-config |
| 129 | +
|
| 130 | + - name: Verify volume behavior with existing tests |
| 131 | + run: | |
| 132 | + go test -v -run TestAttachCapsuleToDeployment |
| 133 | +
|
| 134 | + - name: Verify CRD behavior with existing tests |
| 135 | + run: | |
| 136 | + go test -v -run TestResourceCapsule |
| 137 | +
|
| 138 | + - name: Show AKS state on failure |
| 139 | + if: failure() |
| 140 | + run: | |
| 141 | + kubectl get all -n "$NAMESPACE" || true |
| 142 | + kubectl get resourcecapsules -n "$NAMESPACE" || true |
| 143 | + kubectl get deployment test-app -n "$NAMESPACE" -o yaml || true |
| 144 | +
|
| 145 | + - name: Cleanup AKS test namespace |
| 146 | + if: always() |
| 147 | + run: | |
| 148 | + kubectl delete namespace "$NAMESPACE" --ignore-not-found=true |
0 commit comments