diff --git a/README.md b/README.md index bf624ff..d600103 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,23 @@ k8s-gitops/ deployments/ levelbuilder/ # codeai deployment levelbuilder - deployment.yaml # envType=levelbuilder, branch=levelbuilder - values.yaml # values.yaml for this deployment: dashboard_workers=27, RAILS_ENV=levelbuilder, etc + deployment.yaml # envType=levelbuilder, branch=stage/levelbuilder ... envTypes/ - levelbuilder.values.yaml # base values.yaml for all envType=levelbuilder + levelbuilder/ # envType Kustomize Component for levelbuilder ... + kargo/ + templates/ + deploy/ + kustomization.yaml # temp wrapper copied into Kargo work dirs before render + + warehouses/ + codeai/ + freight/ # frozen source snapshots published from code-dot-org staging + legacy-gitflow/ # legacy branch merge metadata used as downstream Kargo gates + kargo/ application.yaml # argocd app for kargo itself values.yaml # helm values for kargo install @@ -53,4 +62,3 @@ k8s-gitops/ ## Bootstrap Cluster kubectl apply -f apps/app-of-apps/applicationset.yaml - diff --git a/apps/codeai/applicationset.yaml b/apps/codeai/applicationset.yaml index e367ef9..1ffd7fe 100644 --- a/apps/codeai/applicationset.yaml +++ b/apps/codeai/applicationset.yaml @@ -18,18 +18,10 @@ spec: kargo.akuity.io/project: kargo-project-codeai spec: project: default - sources: - - repoURL: https://github.com/code-dot-org/code-dot-org.git - targetRevision: '{{sourceRevision}}' - path: k8s/helm - helm: - releaseName: '{{path.basename}}' - valueFiles: - - $values/apps/codeai/envTypes/{{envType}}.values.yaml - - $values/apps/codeai/deployments/{{path.basename}}/values.yaml - - repoURL: https://github.com/code-dot-org/k8s-gitops.git - targetRevision: main - ref: values + source: + repoURL: https://github.com/code-dot-org/k8s-gitops.git + targetRevision: '{{branch}}' + path: apps/codeai/deployments/{{path.basename}}/deploy destination: server: https://kubernetes.default.svc namespace: '{{namespace}}' diff --git a/apps/codeai/deployments/k8s-adhoc/deployment.yaml b/apps/codeai/deployments/k8s-adhoc/deployment.yaml.disabled similarity index 100% rename from apps/codeai/deployments/k8s-adhoc/deployment.yaml rename to apps/codeai/deployments/k8s-adhoc/deployment.yaml.disabled diff --git a/apps/codeai/deployments/levelbuilder/deployment.yaml b/apps/codeai/deployments/levelbuilder/deployment.yaml new file mode 100644 index 0000000..7e17090 --- /dev/null +++ b/apps/codeai/deployments/levelbuilder/deployment.yaml @@ -0,0 +1,3 @@ +envType: levelbuilder +namespace: levelbuilder +branch: stage/levelbuilder diff --git a/apps/codeai/deployments/production/deployment.yaml b/apps/codeai/deployments/production/deployment.yaml new file mode 100644 index 0000000..de2d22b --- /dev/null +++ b/apps/codeai/deployments/production/deployment.yaml @@ -0,0 +1,3 @@ +envType: production +namespace: production +branch: stage/production diff --git a/apps/codeai/deployments/staging/deployment.yaml b/apps/codeai/deployments/staging/deployment.yaml index 30b6df2..5092bb2 100644 --- a/apps/codeai/deployments/staging/deployment.yaml +++ b/apps/codeai/deployments/staging/deployment.yaml @@ -1,3 +1,3 @@ envType: staging namespace: staging -branch: staging +branch: stage/staging diff --git a/apps/codeai/deployments/test/deployment.yaml b/apps/codeai/deployments/test/deployment.yaml index 2539d0c..b91b74f 100644 --- a/apps/codeai/deployments/test/deployment.yaml +++ b/apps/codeai/deployments/test/deployment.yaml @@ -1,5 +1,3 @@ envType: test namespace: test -# FIXME: for quicker testing, avoid waiting on DTTs and DTPs, let alone DTLs. -# branch: test -branch: staging +branch: stage/test diff --git a/apps/codeai/kargo/templates/deploy/kustomization.yaml b/apps/codeai/kargo/templates/deploy/kustomization.yaml new file mode 100644 index 0000000..64fa2ff --- /dev/null +++ b/apps/codeai/kargo/templates/deploy/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: [] +components: [] +images: + - name: code-dot-org + newName: code-dot-org + newTag: latest diff --git a/apps/kargo-project-codeai/project-config.yaml b/apps/kargo-project-codeai/project-config.yaml index a303851..de77915 100644 --- a/apps/kargo-project-codeai/project-config.yaml +++ b/apps/kargo-project-codeai/project-config.yaml @@ -9,7 +9,9 @@ spec: autoPromotionEnabled: true - stage: test autoPromotionEnabled: false - - stage: production - autoPromotionEnabled: false - stage: levelbuilder autoPromotionEnabled: false + - stage: review-infra-changes + autoPromotionEnabled: false + - stage: production + autoPromotionEnabled: false diff --git a/apps/kargo-project-codeai/stages/levelbuilder.yaml b/apps/kargo-project-codeai/stages/levelbuilder.yaml index 305d668..f3a1d80 100644 --- a/apps/kargo-project-codeai/stages/levelbuilder.yaml +++ b/apps/kargo-project-codeai/stages/levelbuilder.yaml @@ -7,33 +7,108 @@ spec: requestedFreight: - origin: kind: Warehouse - name: kargo-project-codeai + name: codeai-freight sources: stages: - test + vars: + - name: gitopsRepo + value: https://github.com/code-dot-org/k8s-gitops.git + - name: targetBranch + value: stage/levelbuilder + - name: renderDeployment + value: levelbuilder + - name: renderPath + value: apps/codeai/deployments/levelbuilder/deploy + - name: imageRepo + value: ghcr.io/code-dot-org/code-dot-org + - name: legacyEnv + value: levelbuilder promotionTemplate: spec: - vars: - - name: gitopsRepo - value: https://github.com/code-dot-org/k8s-gitops.git steps: - uses: git-clone config: repoURL: ${{ vars.gitopsRepo }} checkout: + - commit: ${{ commitFrom(vars.gitopsRepo, warehouse('codeai-freight')).ID }} + path: ./freight - branch: main - path: ./gitops + path: ./meta + - branch: ${{ vars.targetBranch }} + create: true + path: ./out + - uses: yaml-parse + as: freight + config: + path: ./freight/warehouses/codeai/freight/current/freight.yaml + outputs: + - name: releaseId + fromExpression: tag + - uses: yaml-parse + as: legacy-merge + config: + path: ./meta/warehouses/codeai/legacy-gitflow/${{ vars.legacyEnv }}/merged/${{ outputs.freight.releaseId }}.yaml + outputs: + - name: mergedAt + fromExpression: mergedAt + - uses: yaml-parse + as: deployment-meta + config: + path: ./meta/apps/codeai/deployments/${{ vars.renderDeployment }}/deployment.yaml + outputs: + - name: envType + fromExpression: envType + - name: namespace + fromExpression: namespace + - uses: git-clear + config: + path: ./out + - uses: copy + config: + inPath: ./freight/warehouses/codeai/freight/current/kustomize + outPath: ./work/source + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/${{ outputs['deployment-meta'].envType }} + outPath: ./work/envTypes/${{ outputs['deployment-meta'].envType }} + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/components + outPath: ./work/envTypes/components + - uses: copy + config: + inPath: ./meta/apps/codeai/kargo/templates/deploy + outPath: ./work/deploy - uses: yaml-update config: - path: ./gitops/apps/codeai/deployments/levelbuilder/values.yaml + path: ./work/deploy/kustomization.yaml updates: - - key: image - value: ghcr.io/code-dot-org/code-dot-org:${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} + - key: namespace + value: ${{ outputs['deployment-meta'].namespace }} + - key: resources + value: + - ../source/base + - key: components + value: + - ../envTypes/${{ outputs['deployment-meta'].envType }} + - uses: kustomize-set-image + config: + path: ./work/deploy + images: + - image: code-dot-org + newName: ${{ vars.imageRepo }} + tag: ${{ outputs.freight.releaseId }} + - uses: kustomize-build + config: + path: ./work/deploy + outputFormat: kustomize + outPath: ./out/${{ vars.renderPath }} - uses: git-commit config: - path: ./gitops - message: | - Promote levelbuilder to ${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} [skip ci] + path: ./out + message: Render ${{ vars.renderDeployment }} from ${{ outputs.freight.releaseId }} - uses: git-push config: - path: ./gitops + path: ./out + branch: ${{ vars.targetBranch }} diff --git a/apps/kargo-project-codeai/stages/production.yaml b/apps/kargo-project-codeai/stages/production.yaml index eac25f5..34cf086 100644 --- a/apps/kargo-project-codeai/stages/production.yaml +++ b/apps/kargo-project-codeai/stages/production.yaml @@ -7,33 +7,22 @@ spec: requestedFreight: - origin: kind: Warehouse - name: kargo-project-codeai + name: codeai-freight sources: stages: - - test + - review-infra-changes + vars: + - name: gitopsRepo + value: https://github.com/code-dot-org/k8s-gitops.git promotionTemplate: spec: - vars: - - name: gitopsRepo - value: https://github.com/code-dot-org/k8s-gitops.git steps: - uses: git-clone config: repoURL: ${{ vars.gitopsRepo }} checkout: - - branch: main - path: ./gitops - - uses: yaml-update + - commit: ${{ commitFrom(vars.gitopsRepo, warehouse('codeai-freight')).ID }} + path: ./freight + - uses: yaml-parse config: - path: ./gitops/apps/codeai/deployments/production/values.yaml - updates: - - key: image - value: ghcr.io/code-dot-org/code-dot-org:${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} - - uses: git-commit - config: - path: ./gitops - message: | - Promote production to ${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} [skip ci] - - uses: git-push - config: - path: ./gitops + path: ./freight/warehouses/codeai/freight/current/freight.yaml diff --git a/apps/kargo-project-codeai/stages/review-infra-changes.yaml b/apps/kargo-project-codeai/stages/review-infra-changes.yaml new file mode 100644 index 0000000..9af09c3 --- /dev/null +++ b/apps/kargo-project-codeai/stages/review-infra-changes.yaml @@ -0,0 +1,127 @@ +apiVersion: kargo.akuity.io/v1alpha1 +kind: Stage +metadata: + name: review-infra-changes + namespace: kargo-project-codeai +spec: + requestedFreight: + - origin: + kind: Warehouse + name: codeai-freight + sources: + stages: + - levelbuilder + vars: + - name: gitopsRepo + value: https://github.com/code-dot-org/k8s-gitops.git + - name: targetBranch + value: stage/production + - name: renderDeployment + value: production + - name: renderPath + value: apps/codeai/deployments/production/deploy + - name: imageRepo + value: ghcr.io/code-dot-org/code-dot-org + - name: legacyEnv + value: production + promotionTemplate: + spec: + steps: + - uses: git-clone + config: + repoURL: ${{ vars.gitopsRepo }} + checkout: + - commit: ${{ commitFrom(vars.gitopsRepo, warehouse('codeai-freight')).ID }} + path: ./freight + - branch: main + path: ./meta + - branch: ${{ vars.targetBranch }} + create: true + path: ./out + - uses: yaml-parse + as: freight + config: + path: ./freight/warehouses/codeai/freight/current/freight.yaml + outputs: + - name: releaseId + fromExpression: tag + - uses: yaml-parse + as: legacy-merge + config: + path: ./meta/warehouses/codeai/legacy-gitflow/${{ vars.legacyEnv }}/merged/${{ outputs.freight.releaseId }}.yaml + outputs: + - name: mergedAt + fromExpression: mergedAt + - uses: yaml-parse + as: deployment-meta + config: + path: ./meta/apps/codeai/deployments/${{ vars.renderDeployment }}/deployment.yaml + outputs: + - name: envType + fromExpression: envType + - name: namespace + fromExpression: namespace + - uses: git-clear + config: + path: ./out + - uses: copy + config: + inPath: ./freight/warehouses/codeai/freight/current/kustomize + outPath: ./work/source + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/${{ outputs['deployment-meta'].envType }} + outPath: ./work/envTypes/${{ outputs['deployment-meta'].envType }} + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/components + outPath: ./work/envTypes/components + - uses: copy + config: + inPath: ./meta/apps/codeai/kargo/templates/deploy + outPath: ./work/deploy + - uses: yaml-update + config: + path: ./work/deploy/kustomization.yaml + updates: + - key: namespace + value: ${{ outputs['deployment-meta'].namespace }} + - key: resources + value: + - ../source/base + - key: components + value: + - ../envTypes/${{ outputs['deployment-meta'].envType }} + - uses: kustomize-set-image + config: + path: ./work/deploy + images: + - image: code-dot-org + newName: ${{ vars.imageRepo }} + tag: ${{ outputs.freight.releaseId }} + - uses: kustomize-build + config: + path: ./work/deploy + outputFormat: kustomize + outPath: ./out/${{ vars.renderPath }} + - uses: git-commit + config: + path: ./out + message: Review production render for ${{ outputs.freight.releaseId }} + - uses: git-push + as: push + config: + path: ./out + generateTargetBranch: true + - uses: git-open-pr + as: open-pr + config: + repoURL: ${{ vars.gitopsRepo }} + createTargetBranch: true + sourceBranch: ${{ outputs.push.branch }} + targetBranch: ${{ vars.targetBranch }} + title: Review CodeAI production render for ${{ outputs.freight.releaseId }} + - uses: git-wait-for-pr + config: + repoURL: ${{ vars.gitopsRepo }} + prNumber: ${{ outputs['open-pr'].pr.id }} diff --git a/apps/kargo-project-codeai/stages/staging.yaml b/apps/kargo-project-codeai/stages/staging.yaml index c986f62..9ebf5a2 100644 --- a/apps/kargo-project-codeai/stages/staging.yaml +++ b/apps/kargo-project-codeai/stages/staging.yaml @@ -7,32 +7,98 @@ spec: requestedFreight: - origin: kind: Warehouse - name: kargo-project-codeai + name: codeai-freight sources: direct: true + vars: + - name: gitopsRepo + value: https://github.com/code-dot-org/k8s-gitops.git + - name: targetBranch + value: stage/staging + - name: renderDeployment + value: staging + - name: renderPath + value: apps/codeai/deployments/staging/deploy + - name: imageRepo + value: ghcr.io/code-dot-org/code-dot-org promotionTemplate: spec: - vars: - - name: gitopsRepo - value: https://github.com/code-dot-org/k8s-gitops.git steps: - uses: git-clone config: repoURL: ${{ vars.gitopsRepo }} checkout: + - commit: ${{ commitFrom(vars.gitopsRepo, warehouse('codeai-freight')).ID }} + path: ./freight - branch: main - path: ./gitops + path: ./meta + - branch: ${{ vars.targetBranch }} + create: true + path: ./out + - uses: yaml-parse + as: freight + config: + path: ./freight/warehouses/codeai/freight/current/freight.yaml + outputs: + - name: releaseId + fromExpression: tag + - uses: yaml-parse + as: deployment-meta + config: + path: ./meta/apps/codeai/deployments/${{ vars.renderDeployment }}/deployment.yaml + outputs: + - name: envType + fromExpression: envType + - name: namespace + fromExpression: namespace + - uses: git-clear + config: + path: ./out + - uses: copy + config: + inPath: ./freight/warehouses/codeai/freight/current/kustomize + outPath: ./work/source + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/${{ outputs['deployment-meta'].envType }} + outPath: ./work/envTypes/${{ outputs['deployment-meta'].envType }} + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/components + outPath: ./work/envTypes/components + - uses: copy + config: + inPath: ./meta/apps/codeai/kargo/templates/deploy + outPath: ./work/deploy - uses: yaml-update config: - path: ./gitops/apps/codeai/deployments/staging/values.yaml + path: ./work/deploy/kustomization.yaml updates: - - key: image - value: ghcr.io/code-dot-org/code-dot-org:${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} + - key: namespace + value: ${{ outputs['deployment-meta'].namespace }} + - key: resources + value: + - ../source/base + - key: components + value: + - ../envTypes/${{ outputs['deployment-meta'].envType }} + - uses: kustomize-set-image + config: + path: ./work/deploy + images: + - image: code-dot-org + newName: ${{ vars.imageRepo }} + tag: ${{ outputs.freight.releaseId }} + - uses: kustomize-build + config: + path: ./work/deploy + outputFormat: kustomize + outPath: ./out/${{ vars.renderPath }} - uses: git-commit config: - path: ./gitops - message: | - Promote staging to ${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} [skip ci] + path: ./out + message: Render ${{ vars.renderDeployment }} from ${{ outputs.freight.releaseId }} - uses: git-push config: - path: ./gitops + path: ./out + branch: ${{ vars.targetBranch }} diff --git a/apps/kargo-project-codeai/stages/test.yaml b/apps/kargo-project-codeai/stages/test.yaml index c029450..f608975 100644 --- a/apps/kargo-project-codeai/stages/test.yaml +++ b/apps/kargo-project-codeai/stages/test.yaml @@ -7,33 +7,108 @@ spec: requestedFreight: - origin: kind: Warehouse - name: kargo-project-codeai + name: codeai-freight sources: stages: - staging + vars: + - name: gitopsRepo + value: https://github.com/code-dot-org/k8s-gitops.git + - name: targetBranch + value: stage/test + - name: renderDeployment + value: test + - name: renderPath + value: apps/codeai/deployments/test/deploy + - name: imageRepo + value: ghcr.io/code-dot-org/code-dot-org + - name: legacyEnv + value: test promotionTemplate: spec: - vars: - - name: gitopsRepo - value: https://github.com/code-dot-org/k8s-gitops.git steps: - uses: git-clone config: repoURL: ${{ vars.gitopsRepo }} checkout: + - commit: ${{ commitFrom(vars.gitopsRepo, warehouse('codeai-freight')).ID }} + path: ./freight - branch: main - path: ./gitops + path: ./meta + - branch: ${{ vars.targetBranch }} + create: true + path: ./out + - uses: yaml-parse + as: freight + config: + path: ./freight/warehouses/codeai/freight/current/freight.yaml + outputs: + - name: releaseId + fromExpression: tag + - uses: yaml-parse + as: legacy-merge + config: + path: ./meta/warehouses/codeai/legacy-gitflow/${{ vars.legacyEnv }}/merged/${{ outputs.freight.releaseId }}.yaml + outputs: + - name: mergedAt + fromExpression: mergedAt + - uses: yaml-parse + as: deployment-meta + config: + path: ./meta/apps/codeai/deployments/${{ vars.renderDeployment }}/deployment.yaml + outputs: + - name: envType + fromExpression: envType + - name: namespace + fromExpression: namespace + - uses: git-clear + config: + path: ./out + - uses: copy + config: + inPath: ./freight/warehouses/codeai/freight/current/kustomize + outPath: ./work/source + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/${{ outputs['deployment-meta'].envType }} + outPath: ./work/envTypes/${{ outputs['deployment-meta'].envType }} + - uses: copy + config: + inPath: ./meta/apps/codeai/envTypes/components + outPath: ./work/envTypes/components + - uses: copy + config: + inPath: ./meta/apps/codeai/kargo/templates/deploy + outPath: ./work/deploy - uses: yaml-update config: - path: ./gitops/apps/codeai/deployments/test/values.yaml + path: ./work/deploy/kustomization.yaml updates: - - key: image - value: ghcr.io/code-dot-org/code-dot-org:${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} + - key: namespace + value: ${{ outputs['deployment-meta'].namespace }} + - key: resources + value: + - ../source/base + - key: components + value: + - ../envTypes/${{ outputs['deployment-meta'].envType }} + - uses: kustomize-set-image + config: + path: ./work/deploy + images: + - image: code-dot-org + newName: ${{ vars.imageRepo }} + tag: ${{ outputs.freight.releaseId }} + - uses: kustomize-build + config: + path: ./work/deploy + outputFormat: kustomize + outPath: ./out/${{ vars.renderPath }} - uses: git-commit config: - path: ./gitops - message: | - Promote test to ${{ imageFrom("ghcr.io/code-dot-org/code-dot-org").Tag }} [skip ci] + path: ./out + message: Render ${{ vars.renderDeployment }} from ${{ outputs.freight.releaseId }} - uses: git-push config: - path: ./gitops + path: ./out + branch: ${{ vars.targetBranch }} diff --git a/apps/kargo-project-codeai/warehouse.yaml b/apps/kargo-project-codeai/warehouse.yaml index ff9ebe0..12deb86 100644 --- a/apps/kargo-project-codeai/warehouse.yaml +++ b/apps/kargo-project-codeai/warehouse.yaml @@ -1,13 +1,12 @@ apiVersion: kargo.akuity.io/v1alpha1 kind: Warehouse metadata: - name: kargo-project-codeai + name: codeai-freight namespace: kargo-project-codeai spec: subscriptions: - - image: - repoURL: ghcr.io/code-dot-org/code-dot-org - ignoreTagsRegexes: - # Ignore single-platform images when we have a multiplatform option - - '.*-amd64$' - - '.*-arm64$' + - git: + repoURL: https://github.com/code-dot-org/k8s-gitops.git + branch: main + includePaths: + - warehouses/codeai/freight diff --git a/warehouses/codeai/freight/.gitkeep b/warehouses/codeai/freight/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/warehouses/codeai/freight/.gitkeep @@ -0,0 +1 @@ + diff --git a/warehouses/codeai/legacy-gitflow/levelbuilder/merged/.gitkeep b/warehouses/codeai/legacy-gitflow/levelbuilder/merged/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/warehouses/codeai/legacy-gitflow/levelbuilder/merged/.gitkeep @@ -0,0 +1 @@ + diff --git a/warehouses/codeai/legacy-gitflow/production/merged/.gitkeep b/warehouses/codeai/legacy-gitflow/production/merged/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/warehouses/codeai/legacy-gitflow/production/merged/.gitkeep @@ -0,0 +1 @@ + diff --git a/warehouses/codeai/legacy-gitflow/staging/merged/.gitkeep b/warehouses/codeai/legacy-gitflow/staging/merged/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/warehouses/codeai/legacy-gitflow/staging/merged/.gitkeep @@ -0,0 +1 @@ + diff --git a/warehouses/codeai/legacy-gitflow/test/merged/.gitkeep b/warehouses/codeai/legacy-gitflow/test/merged/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/warehouses/codeai/legacy-gitflow/test/merged/.gitkeep @@ -0,0 +1 @@ +