-
Notifications
You must be signed in to change notification settings - Fork 12
Draft: switch AWS deployment from Serverless to CDK #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
2db73b0
a5d374b
05597ca
f10d031
542ec9c
807ea0b
374658d
479d725
4370d83
436dbb3
e98ae6f
37ac4f0
e9c2833
35a89c8
284ac39
b83603c
66136f3
cd2d911
6ea9d55
58bf37c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| S3_BUCKET_PREFIX=hackingstudio-code4maus-projects | ||
| S3_BUCKET_PREFIX=pmdm-projectbucket | ||
| AWS_REGION=eu-central-1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # Deployment-Workflow mit Bestätigung, angedacht für staging und prod | ||
| # Job "plan": führt `cdk synth` aus und schreibt die Ánderungen bzw. das Diff in den Job-Output. | ||
| # cdk.out wird als Artefakt gespeichert | ||
| # Job "apply": lädt das neue Template (bzw. cdk.out) herunter und deployt es | ||
|
|
||
| name: deploy (gated) | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| stage: | ||
| description: CDK-Stage (staging | prod) | ||
| required: true | ||
| type: string | ||
| environment: | ||
| description: Github-Environment (Approval-Gate + Secrets) | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| AWS_REGION: eu-central-1 | ||
| NODE_OPTIONS: --max-old-space-size=4096 | ||
|
|
||
| jobs: | ||
| # ---- Plan: synth + diff, ohne etwas zu verändern ------------------------- | ||
| plan: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Node 24 einrichten | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
| cache: yarn | ||
|
|
||
| - name: AWS-Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_2026 }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_2026 }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
|
|
||
| - name: Frontend-Dependencies installieren | ||
| run: yarn install --frozen-lockfile --ignore-optional | ||
|
|
||
| - name: Frontend bauen | ||
| run: yarn build | ||
| env: | ||
| NODE_ENV: production | ||
|
|
||
| - name: CDK-Dependencies installieren | ||
| run: npm ci | ||
| working-directory: cdk | ||
|
|
||
| - name: CDK synth | ||
| run: npx cdk synth --context stage=${{ inputs.stage }} | ||
| working-directory: cdk | ||
|
|
||
| # diff gegen den deployten Stack (change-set-basiert = autoritativ) in die | ||
| # Run-Summary schreiben, damit Reviewer:innen es VOR der Freigabe sehen. | ||
| - name: CDK diff → Summary | ||
| working-directory: cdk | ||
| run: | | ||
| npx cdk diff --app cdk.out "MausApp-${{ inputs.stage }}" 2>&1 | tee diff.txt | ||
| { | ||
| echo "## CDK diff (${{ inputs.stage }})" | ||
| echo '```' | ||
| cat diff.txt | ||
| echo '```' | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Cloud Assembly sichern | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cloud-assembly-${{ inputs.stage }} | ||
| path: cdk/cdk.out | ||
| retention-days: 5 | ||
|
|
||
| # ---- Apply: deployt exakt das geplante Assembly, nach Approval ------------ | ||
| apply: | ||
| needs: plan | ||
| runs-on: ubuntu-latest | ||
| # Das Environment ist das Gate: hat es einen Required Reviewer (prod), | ||
| # pausiert der Run hier, bis freigegeben wird. | ||
| environment: ${{ inputs.environment }} | ||
| concurrency: | ||
| group: deploy-${{ inputs.stage }} | ||
| cancel-in-progress: false | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Node 24 einrichten | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
| cache: yarn | ||
|
|
||
| - name: AWS-Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_2026 }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_2026 }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
|
|
||
| # Nur die CDK-CLI wird gebraucht; nicht neu bauen/synthen. | ||
| - name: CDK-Dependencies installieren | ||
| run: npm ci | ||
| working-directory: cdk | ||
|
|
||
| - name: Cloud Assembly laden | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: cloud-assembly-${{ inputs.stage }} | ||
| path: cdk/cdk.out | ||
|
|
||
| - name: CDK deploy (exakt das reviewte Assembly) | ||
| working-directory: cdk | ||
| run: npx cdk deploy --app cdk.out "MausApp-${{ inputs.stage }}" --require-approval never | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Baut Assets und `cdk deploy`t direkt, ohne Bestätigung | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lohnt es sich, das als separaten Workflow zu pflegen? Also wenn ich das richtig verstehe, wird ja über so ein konfiguriertes Environment enforced, dass jemand abnicken muss. Aber wenn wir ein Environment für dev konfigurieren, wo kein Review erforderlich ist, würde er auch mit dem |
||
| # intendiert für dev | ||
| name: deploy | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| stage: | ||
| description: CDK-Stage (dev / staging / prod) | ||
| required: true | ||
| type: string | ||
| environment: | ||
| description: GitHub-Environment | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-26.04 # noch in Test -> latest lieber vermeiden | ||
| #runs-on: ubuntu-latest | ||
| environment: ${{ inputs.environment }} | ||
| # verhindert überlappende Deploys auf dieselbe Stage | ||
| concurrency: | ||
| group: deploy-${{ inputs.stage }} | ||
| cancel-in-progress: false | ||
| env: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wir hatten vorher die Environment-Variable |
||
| AWS_REGION: eu-central-1 | ||
| NODE_OPTIONS: --max-old-space-size=4096 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Node 24 einrichten | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
| cache: yarn | ||
|
|
||
| - name: AWS-Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_2026 }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_2026 }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
|
|
||
| # Frontend-Projekt (yarn). --ignore-optional überspringt native | ||
| # optional-deps (printer/snappy), die für den Build nicht gebraucht werden | ||
| - name: Frontend-Dependencies installieren | ||
| run: yarn install --frozen-lockfile --ignore-optional | ||
|
|
||
| - name: Frontend bauen | ||
| run: yarn build | ||
| env: | ||
| NODE_ENV: production | ||
|
|
||
| # CDK-Projekt (npm). esbuild für das Lambda-Bundling wird aus dem | ||
| # Repo-Root (yarn) aufgelöst und muss dort nicht erneut installiert werden | ||
| - name: CDK-Dependencies installieren | ||
| run: npm ci | ||
| working-directory: cdk | ||
|
|
||
| # Loggt das diff -> keine Bestätigung nötig | ||
| - name: CDK diff | ||
| run: npx cdk diff --context stage=${{ inputs.stage }} | ||
| working-directory: cdk | ||
|
|
||
| - name: CDK deploy | ||
| run: npx cdk deploy --context stage=${{ inputs.stage }} --require-approval never | ||
| working-directory: cdk | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Push auf develop -> Deploy auf Stage dev. Zusätzlich manuell per | ||
| # workflow_dispatch (praktisch, um einen Feature-Branch gegen dev zu testen). | ||
| name: Deploy dev | ||
|
|
||
| on: | ||
| push: | ||
| branches: [develop] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| deploy: | ||
| uses: ./.github/workflows/_deploy.yml | ||
| with: | ||
| stage: dev | ||
| environment: dev | ||
| secrets: inherit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Push auf production -> Plan/Approve/Apply auf Stage prod. | ||
| # Das GitHub-Environment "prod" braucht einen Required Reviewer, damit der | ||
| # Apply-Job erst nach manueller Freigabe läuft. | ||
| name: Deploy production | ||
|
|
||
| on: | ||
| push: | ||
| branches: [production] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| deploy: | ||
| uses: ./.github/workflows/_deploy-gated.yml | ||
| with: | ||
| stage: prod | ||
| environment: prod | ||
| secrets: inherit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Push auf staging -> Plan/Approve/Apply auf Stage staging. | ||
| name: Deploy staging | ||
|
|
||
| on: | ||
| push: | ||
| branches: [staging] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| deploy: | ||
| uses: ./.github/workflows/_deploy-gated.yml | ||
| with: | ||
| stage: staging | ||
| environment: staging | ||
| secrets: inherit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Validierung für Pull Requests gegen develop/staging/production – OHNE Deploy und ohne | ||
| # AWS-Credentials. Baut das Frontend und synthetisiert den CDK-Stack, um Bundling-, | ||
| # Config- und Template-Fehler vor dem Merge zu fangen. | ||
| name: PR checks | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [develop, staging, production] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| validate: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| NODE_OPTIONS: --max-old-space-size=4096 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Node 24 einrichten | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
| cache: yarn | ||
|
|
||
| - name: Frontend-Dependencies installieren | ||
| run: yarn install --frozen-lockfile --ignore-optional | ||
|
|
||
| - name: Frontend bauen | ||
| run: yarn build | ||
| env: | ||
| NODE_ENV: production | ||
|
|
||
| - name: CDK-Dependencies installieren | ||
| run: npm ci | ||
| working-directory: cdk | ||
|
|
||
| # synth braucht keine AWS-Credentials (keine fromLookup-Aufrufe im Stack). | ||
| # dev ist vollständig konfiguriert und dient hier als Validierungs-Stage. | ||
| - name: CDK synth | ||
| run: npx cdk synth --context stage=dev | ||
| working-directory: cdk |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| *.js | ||
| !jest.config.js | ||
| *.d.ts | ||
| node_modules | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| *.ts | ||
| !*.d.ts | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wenn der
cdk difffailed verschluckt die Pipe den exit code und der Step bleibt grün. Einset -o pipefailwürde hier Abhilfe schaffen, alternativ wohl auch einshell: bashauf dem Step.