Files
service-state/ci/url-shortener/start-prod.ps1
T

58 lines
2.3 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$StagingRun
)
$ErrorActionPreference = 'Stop'
$runJson = kubectl -n tekton-ci get pipelinerun $StagingRun -o json
if ($LASTEXITCODE -ne 0) { throw 'Could not read the staging PipelineRun.' }
$run = $runJson | ConvertFrom-Json
if ($run.spec.pipelineRef.name -ne 'url-shortener-staging' -or
-not ($run.status.conditions | Where-Object { $_.type -eq 'Succeeded' -and $_.status -eq 'True' })) {
throw 'Select a successful url-shortener-staging PipelineRun.'
}
$revision = ($run.spec.params | Where-Object name -eq 'git-revision').value
$digest = ($run.status.results | Where-Object name -eq 'image-digest').value
if ($revision -notmatch '^[0-9a-f]{40}$' -or $digest -notmatch '^sha256:[0-9a-f]{64}$') {
throw 'The staging run has no valid source revision or image digest.'
}
$pipelineRun = @{
apiVersion = 'tekton.dev/v1'
kind = 'PipelineRun'
metadata = @{
generateName = 'url-shortener-prod-'
namespace = 'tekton-ci'
labels = @{ 'app.kubernetes.io/name' = 'url-shortener'; 'app.kubernetes.io/part-of' = 'url-shortener-ci' }
annotations = @{ 'url-shortener.dahyeon.us/staging-run' = $StagingRun }
}
spec = @{
pipelineRef = @{ name = 'url-shortener-prod' }
params = @(
@{ name = 'git-revision'; value = $revision }
@{ name = 'image-digest'; value = $digest }
)
taskRunTemplate = @{
serviceAccountName = 'url-shortener-pipeline'
podTemplate = @{
nodeSelector = @{ 'kubernetes.io/arch' = 'amd64' }
securityContext = @{ fsGroup = 1000; fsGroupChangePolicy = 'OnRootMismatch' }
}
}
workspaces = @(
@{
name = 'source'
volumeClaimTemplate = @{ spec = @{
accessModes = @('ReadWriteOnce')
storageClassName = 'local-path'
resources = @{ requests = @{ storage = '5Gi' } }
} }
}
@{ name = 'gitea-credentials'; secret = @{ secretName = 'url-shortener-gitea' } }
)
timeouts = @{ pipeline = '30m'; tasks = '25m' }
}
}
$pipelineRun | ConvertTo-Json -Depth 12 | kubectl create -f -
if ($LASTEXITCODE -ne 0) { throw 'Could not create the production PipelineRun.' }