Skip to content
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

feat: støtte flere ingresser #234

Merged
merged 11 commits into from
Oct 18, 2024
19 changes: 6 additions & 13 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,16 @@ on:
jobs:
check-dist:
runs-on: ubuntu-latest

strategy:
matrix:
action:
- spa-setup-task

defaults:
run:
working-directory: actions/${{ matrix.action }}
working-directory: actions/spa-setup-task

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'
- run: yarn install
- run: yarn build
- run: yarn package

- name: Compare the expected and actual dist/ directories
Expand All @@ -48,8 +41,8 @@ jobs:
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: actions/${{ matrix.action }}/dist/
path: actions/spa-setup-task/dist/
10 changes: 10 additions & 0 deletions actions/spa-deploy/v2/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ inputs:
ingress:
description: 'Application ingress URL'
required: true
ingressClass:
description: 'Ingress class'
required: false
default: ''
cluster:
description: 'NAIS cluster name'
required: false
default: ''
project_id:
description: "Google Cloud project ID where buckets are hosted"
required: true
Expand All @@ -39,6 +47,8 @@ runs:
app-name: ${{ inputs.app }}
ingress: ${{ inputs.ingress }}
source: ${{ inputs.source }}
ingressClass: ${{ inputs.ingressClass }}
cluster: ${{ inputs.cluster }}
environment: ${{ inputs.environment }}

- id: cdn-upload
Expand Down
1,278 changes: 762 additions & 516 deletions actions/spa-setup-task/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion actions/spa-setup-task/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion actions/spa-setup-task/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@kubernetes/client-node": "^0.18.1",
"yaml": "^2.2.1"
"yaml": "^2.2.2"
},
"devDependencies": {
"@types/node": "^18.14.0",
Expand Down
12 changes: 11 additions & 1 deletion actions/spa-setup-task/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ function run(): void {
const appName: string = core.getInput('app-name')
// const source: string = core.getInput('source')
const ingresses: string[] = core.getInput('ingress').split(',')
const ingressClass: string = core.getInput('ingressClass')
const cluster: string = core.getInput('naisCluster')
const environment: string = core.getInput('environment')

const err = validateInputs(teamName, appName, ingresses, environment)
const err = validateInputs(
teamName,
appName,
ingresses,
ingressClass,
environment
)
if (err) {
core.setFailed(err.message)
return
Expand All @@ -18,6 +26,8 @@ function run(): void {
teamName,
appName,
ingresses,
ingressClass,
cluster,
environment
)

Expand Down
45 changes: 31 additions & 14 deletions actions/spa-setup-task/src/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,43 +136,54 @@ export function validateInputs(
team: string,
app: string,
ingress: string[],
ingressClass: string,
environment: string
): Error | null {
if (!isValidAppName(team)) {
return Error(
`Invalid team name: ${team}. Team name must match regex: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
`SPADEPLOY-001: Invalid team name: ${team}. Team name must match regex: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
)
}

if (!isValidAppName(app)) {
return Error(
`Invalid app name: ${app}. App name must match regex: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
`SPADEPLOY-002: Invalid app name: ${app}. App name must match regex: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
)
}

if (!isValidAppName(environment)) {
return Error(
`Invalid environment name: ${environment}. Environment name must match regex: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
`SPADEPLOY-003: Invalid environment name: ${environment}. Environment name must match regex: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
)
}

if (ingress.length === 0) {
return Error('No ingress specified')
return Error('SPADEPLOY-004: No ingress specified')
}

if (hasCustomIngressClass(ingressClass)) {
return null
}

if (!isValidIngress(ingress)) {
return Error(
`Invalid ingress: ${ingress}. Ingress must be a valid URL with a known domain on format https://<host>/<path>`
`SPADEPLOY-006: Invalid ingress: ${ingress}. Ingress must be a valid URL with a known domain on format https://<host>/<path>`
)
}

return null
}

export function hasCustomIngressClass(ingressClass: string): boolean {
return ingressClass !== ''
}

export function spaSetupTask(
team: string,
app: string,
urls: string[],
customIngressClass: string,
customNaisCluster: string,
env = ''
): {
cdnDest: string
Expand All @@ -183,18 +194,24 @@ export function spaSetupTask(

const ingresses: Ingress[] = []

for (const ingress of urls) {
const {hostname: ingressHost, pathname: ingressPath} = new URL(ingress)
const {naisCluster, ingressClass} = parseIngress(ingressHost)
if (hasCustomIngressClass(customIngressClass)) {
const {hostname: ingressHost, pathname: ingressPath} = new URL(urls[0])
ingresses.push({ingressHost, ingressPath, ingressClass: customIngressClass})
naisClusterFinal = customNaisCluster
} else {
for (const ingress of urls) {
const {hostname: ingressHost, pathname: ingressPath} = new URL(ingress)
const {naisCluster, ingressClass} = parseIngress(ingressHost)

ingresses.push({ingressHost, ingressPath, ingressClass})
ingresses.push({ingressHost, ingressPath, ingressClass})

naisClusterFinal = naisClusterFinal || naisCluster
naisClusterFinal = naisClusterFinal || naisCluster

if (naisClusterFinal !== naisCluster) {
throw Error(
`Ingresses must be on same cluster. Found ${naisClusterFinal} and ${naisCluster}`
)
if (naisClusterFinal !== naisCluster) {
throw Error(
`SPADEPLOY-005: Ingresses must be on same cluster. Found ${naisClusterFinal} and ${naisCluster}`
)
}
}
}

Expand Down
Loading
Loading