Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/_deploy-gated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
run: yarn build
env:
NODE_ENV: production
STAGE: ${{ inputs.stage }}
BRANCH: ${{ github.ref_name }}

- name: CDK-Dependencies installieren
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
run: yarn build
env:
NODE_ENV: production
STAGE: ${{ inputs.stage }}

# CDK-Projekt (npm). esbuild für das Lambda-Bundling wird aus dem
# Repo-Root (yarn) aufgelöst und muss dort nicht erneut installiert werden
Expand Down
4 changes: 3 additions & 1 deletion cdk/DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Im Zuge der App-Erneuerung wurde das Deployment im Mai 2026 vom Serverless Frame
| Stage | Domain | Projekt-Bucket |
|-------|--------|----------------|
| `dev` | `dev.maus.metahost.org` | `pmdm-projectbucket-dev-<account>` |
| `staging` | `staging.code4maus.wt.wdr.cloud` | `pmdm-projectbucket-staging-<account>` |
| `staging` | `staging.maus.metahost.org` | `pmdm-projectbucket-staging-<account>` |
| `prod` | `programmieren.wdrmaus.de` | `pmdm-projectbucket-prod-<account>` |

Die Domains stehen in `lib/stage-domains.json`. Der Frontend-Build liest sie ebenfalls, für die Seiten-URLs in den Meta-Tags; die Deploy-Workflows geben ihm dafür die Stage per `STAGE` mit.

Die aktive Stage wird über die Umgebungsvariable `STAGE` oder den CDK-Kontext-Parameter `--context stage=<stage>` gesetzt. Ohne Angabe wird `dev` verwendet.

## Infrastruktur-Komponenten
Expand Down
8 changes: 5 additions & 3 deletions cdk/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import STAGE_DOMAINS from './stage-domains.json'

export type StageName = 'prod' | 'staging' | 'dev'

export interface StageConfig {
Expand Down Expand Up @@ -44,15 +46,15 @@ const PLACEHOLDER_CERT_ARN =
// (`aws route53 list-hosted-zones`).
export const STAGES: Record<StageName, StageConfig> = {
prod: {
domain: 'programmieren.wdrmaus.de',
domain: STAGE_DOMAINS.prod,
certArn: PLACEHOLDER_CERT_ARN,
// hostedZoneId: 'TODO_PROD_HOSTED_ZONE_ID',
// hostedZoneName: 'wdrmaus.de.',
account: ACCOUNTS.prod,
region: DEFAULT_REGION,
},
staging: {
domain: 'staging.maus.metahost.org',
domain: STAGE_DOMAINS.staging,
certArn:
'arn:aws:acm:us-east-1:391322831368:certificate/c7376bf1-8253-42e3-9385-da8bfaa1ae18',
// hostedZoneId: 'TODO_STAGING_HOSTED_ZONE_ID',
Expand All @@ -61,7 +63,7 @@ export const STAGES: Record<StageName, StageConfig> = {
region: DEFAULT_REGION,
},
dev: {
domain: 'dev.maus.metahost.org',
domain: STAGE_DOMAINS.dev,
certArn:
'arn:aws:acm:us-east-1:391322831368:certificate/b2d1f159-5248-4f44-9bef-b94f9b69b260',
// hostedZoneId: 'TODO_DEV_HOSTED_ZONE_ID',
Expand Down
5 changes: 5 additions & 0 deletions cdk/lib/stage-domains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"prod": "programmieren.wdrmaus.de",
"staging": "staging.maus.metahost.org",
"dev": "dev.maus.metahost.org"
}
1 change: 1 addition & 0 deletions cdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"skipLibCheck": true,
"resolveJsonModule": true,
"typeRoots": [
"./node_modules/@types"
]
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"postcss-mixins": "^6.2.0",
"postcss-simple-vars": "^5.0.2",
"prettier": "^2.0.2",
"promise-timeout": "^1.3.0",
"prop-types": "^15.5.10",
"raf": "^3.4.0",
"raw-loader": "^2.0.0",
Expand Down
107 changes: 13 additions & 94 deletions scripts/env.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,20 @@
/* eslint-disable no-console */
const AWS = require('aws-sdk')
const { timeout } = require('promise-timeout')

const getHostedZoneForDomain = (domain) => {
const route53 = new AWS.Route53({
region: 'eu-central-1',
})
const splittedDomain = domain.split('.')
let foundId = null
return timeout(route53.listHostedZones({}).promise(), 5000)
.then((data) => {
return splittedDomain.every((_part, i) => {
const domain = splittedDomain.slice(i).join('.') + '.'
const result = data.HostedZones.find((zone) => zone.Name === domain)
if (result === undefined) {
return true
}
foundId = result.Id
return false // break
})
})
.then((notFound) => (!notFound ? foundId : null))
}

const getCertArnForDomain = (domain) => {
const acm = new AWS.ACM({
region: 'us-east-1',
})
const wildCardDomain = '*.' + domain.split('.').slice(1).join('.')
return timeout(acm.listCertificates({}).promise(), 5000)
.then((data) =>
data.CertificateSummaryList.find(
(cert) =>
cert.DomainName === domain || cert.DomainName === wildCardDomain
)
const stageDomains = require('../cdk/lib/stage-domains.json')

// Deploy workflows set STAGE; local and preview builds fall back to dev.
const stage = () => process.env.STAGE || 'dev'

const baseDomain = () => {
const domain = stageDomains[stage()]
if (!domain) {
throw new Error(
`Unknown stage: ${stage()}. Expected one of: ${Object.keys(
stageDomains
).join(', ')}.`
)
.then((cert) => cert && cert.CertificateArn)
}

const stageFromBranch = () => {
const branch = process.env.BRANCH || process.env.TRAVIS_BRANCH
if (branch === 'production') {
return 'prod'
}
if (branch === 'develop') {
return 'staging'
}
return false
}

const stage = () => process.env.SLS_STAGE || stageFromBranch() || 'dev'

const baseDomain = () =>
stage() === 'prod'
? 'programmieren.wdrmaus.de'
: `${stage()}.code4maus.wt.wdr.cloud`

const bucketSuffix = () => (stage() === 'prod' ? 'prod' : 'staging')

const hostedZone = () => {
const domain = baseDomain()
return getHostedZoneForDomain(domain)
.then((zone) => {
if (zone === null) {
return Promise.reject(
new Error(`Zone for domain "${domain}" not found.`)
)
}
return zone
})
.catch((error) => {
console.warn('WARNING: Request for HostedZone failed!', error.message)
return Promise.resolve('')
})
}

const certArn = () => {
const domain = baseDomain()
return getCertArnForDomain(domain)
.then((cert) => {
if (!cert) {
return Promise.reject(
new Error(`Cert for domain "${domain}" not found.`)
)
}
return cert
})
.catch((error) => {
console.warn('WARNING: Request for Certificate failed!', error.message)
return Promise.resolve('')
})
return domain
}

module.exports = {
baseDomain,
bucketSuffix,
certArn,
hostedZone,
stage,
}
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14677,11 +14677,6 @@ promise-queue@^2.2.5:
resolved "https://registry.yarnpkg.com/promise-queue/-/promise-queue-2.2.5.tgz#2f6f5f7c0f6d08109e967659c79b88a9ed5e93b4"
integrity sha512-p/iXrPSVfnqPft24ZdNNLECw/UrtLTpT3jpAAMzl/o5/rDsGCPo3/CQS2611flL6LkoEJ3oQZw7C8Q80ZISXRQ==

promise-timeout@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/promise-timeout/-/promise-timeout-1.3.0.tgz#d1c78dd50a607d5f0a5207410252a3a0914e1014"
integrity sha512-5yANTE0tmi5++POym6OgtFmwfDvOXABD9oj/jLQr5GPEyuNEb7jH4wbbANJceJid49jwhi1RddxnhnEAb/doqg==

promise.allsettled@^1.0.0:
version "1.0.7"
resolved "https://registry.yarnpkg.com/promise.allsettled/-/promise.allsettled-1.0.7.tgz#b9dd51e9cffe496243f5271515652c468865f2d8"
Expand Down
Loading