diff --git a/.github/jsonnet/GIT_VERSION b/.github/jsonnet/GIT_VERSION index 74afd3c..1f41476 100644 --- a/.github/jsonnet/GIT_VERSION +++ b/.github/jsonnet/GIT_VERSION @@ -1 +1 @@ -447a8f6c677d3c799678319ea08734ed4b41196f +895bfcd95c9c362b48b721ca51ad705ef0e81d9d diff --git a/.github/jsonnet/base.jsonnet b/.github/jsonnet/base.jsonnet index 5f7ef5c..2b4875e 100644 --- a/.github/jsonnet/base.jsonnet +++ b/.github/jsonnet/base.jsonnet @@ -24,11 +24,12 @@ permissions=null, concurrency=null, continueOnError=null, + env=null, ):: { [name]: { 'timeout-minutes': timeoutMinutes, - 'runs-on': (if runsOn == null then ['self-hosted', 'runner-2'] else runsOn), + 'runs-on': (if runsOn == null then 'arc-runner-2' else runsOn), } + ( if image == null then {} else @@ -47,7 +48,8 @@ (if services != null then { services: services } else {}) + (if permissions == null then {} else { permissions: permissions }) + (if concurrency == null then {} else { concurrency: concurrency }) + - (if continueOnError == null then {} else { 'continue-on-error': continueOnError }), + (if continueOnError == null then {} else { 'continue-on-error': continueOnError }) + + (if env == null then {} else { env: env }) }, ghExternalJob( diff --git a/.github/jsonnet/databases.jsonnet b/.github/jsonnet/databases.jsonnet index d8af183..baa7755 100644 --- a/.github/jsonnet/databases.jsonnet +++ b/.github/jsonnet/databases.jsonnet @@ -31,6 +31,7 @@ server: 'eu-w4-metrics-production', region: 'europe-west4', project: 'unicorn-985', + lifecycle: 'deprecated', }, 'gynzy-test': { type: 'mysql', @@ -45,12 +46,6 @@ region: 'europe-west4', project: 'gynzy-1090', }, - 'accounts-production': { - type: 'mysql', - server: 'eu-w4-accounts-production', - region: 'europe-west4', - project: 'unicorn-985', - }, 'eu-w4-licenses-v8': { type: 'mysql', server: 'eu-w4-licenses-v8', @@ -75,7 +70,24 @@ region: 'europe-west4', project: 'unicorn-985', }, - + 'eu-w4-accounts-v8': { + type: 'mysql', + server: 'eu-w4-accounts-v8', + region: 'europe-west4', + project: 'unicorn-985', + }, + 'eu-w4-metrics-v8': { + type: 'mysql', + server: 'eu-w4-metrics-v8', + region: 'europe-west4', + project: 'unicorn-985', + }, + 'eu-w4-groups-v8': { + type: 'mysql', + server: 'eu-w4-groups-v8', + region: 'europe-west4', + project: 'unicorn-985', + }, }, copyDatabase(mysqlActionOptions):: diff --git a/.github/jsonnet/deployment.jsonnet b/.github/jsonnet/deployment.jsonnet index a9d7158..60de82c 100644 --- a/.github/jsonnet/deployment.jsonnet +++ b/.github/jsonnet/deployment.jsonnet @@ -24,30 +24,53 @@ ), ], - masterMergeDeploymentEventHook(deployToTest=false, prodBranch=null, testBranch=null):: + /* + * Creates a production deployment event on pr-close if the following conditions are met: + * - the pr is merged + * - the pr is not merged by the virko user + * - the pr is merged into the default branch + * - the merge sha is the latest commit on the default branch. + * this prevents a deployment from beeing created in a specific edge case: + * - PR A is merged into PR B + * - PR B is merged into the default branch + * - now github closes both PRs and without this additional sanity check, both would create a deploy event + * + * params: + * deployToTest {boolean} - if true, a deployment event is also created for the test environment + * prodBranch {string|null} - the branch to deploy to production. defaults to the default branch of the repository. but can be set to a differring release branch + * testBranch {string|null} - the branch to deploy to test. defaults to the default branch of the repository. but can be set to a differring test branch + * extraDeployTargets {string[]} - deploy targets to create deployment events for. defaults to ['production']. these targets will triger based on the configured prodBranch + * runsOn {string|null} - the name of the runner to run this job on. defaults to null, which will later on means the default self hosted runner will be used + */ + masterMergeDeploymentEventHook(deployToTest=false, prodBranch=null, testBranch=null, deployTargets=['production'], runsOn=null):: $.pipeline( 'create-merge-deployment', [ $.ghJob( 'create-merge-deployment-prod', useCredentials=false, + runsOn=runsOn, permissions={ deployments: 'write', contents: 'read' }, ifClause="${{ github.actor != 'gynzy-virko' && github.event.pull_request.merged == true}}", steps=$._assertMergeShaIsLatestCommit(branch=(if prodBranch != null then prodBranch else '${{ github.event.pull_request.base.repo.default_branch }}')) + + std.map( + function(deploymentTarget) + $.action( + 'publish-deploy-' + deploymentTarget + '-event', + 'chrnorm/deployment-action@v2', + ifClause='${{ github.event.pull_request.base.ref == ' + (if prodBranch != null then "'" + prodBranch + "'" else 'github.event.pull_request.base.repo.default_branch') + " && steps.assert-merge-sha-is-latest-commit.outputs.CREATE_DEPLOY_EVENT == 'true' }}", + with={ + token: $.secret('VIRKO_GITHUB_TOKEN'), + environment: deploymentTarget, + 'auto-merge': 'false', + ref: '${{ github.event.pull_request.head.sha }}', + description: 'Auto deploy ' + deploymentTarget + ' on PR merge. pr: ${{ github.event.number }} ref: ${{ github.event.pull_request.head.sha }}', + payload: '{ "pr" : ${{ github.event.number }}, "branch": "${{ github.head_ref }}", "base_ref": "${{ github.event.pull_request.base.sha }}", "head_ref": "${{ github.event.pull_request.head.sha }}" }', + } + ), + deployTargets, + ) + [ - $.action( - 'publish-deploy-prod-event', - 'chrnorm/deployment-action@v2', - ifClause='${{ github.event.pull_request.base.ref == ' + (if prodBranch != null then "'" + prodBranch + "'" else 'github.event.pull_request.base.repo.default_branch') + " && steps.assert-merge-sha-is-latest-commit.outputs.CREATE_DEPLOY_EVENT == 'true' }}", - with={ - token: $.secret('VIRKO_GITHUB_TOKEN'), - environment: 'production', - 'auto-merge': 'false', - ref: '${{ github.event.pull_request.head.sha }}', - description: 'Auto deploy production on PR merge. pr: ${{ github.event.number }} ref: ${{ github.event.pull_request.head.sha }}', - payload: '{ "pr" : ${{ github.event.number }}, "branch": "${{ github.head_ref }}", "base_ref": "${{ github.event.pull_request.base.sha }}", "head_ref": "${{ github.event.pull_request.head.sha }}" }', - } - ), $.sendSlackMessage( message='Deploy to prod of pr: ${{ github.event.number }} with title: ${{ github.event.pull_request.title }} branch: ${{ github.head_ref }} started!', ifClause='${{ github.event.pull_request.base.ref == ' + (if prodBranch != null then "'" + prodBranch + "'" else 'github.event.pull_request.base.repo.default_branch') + " && steps.assert-merge-sha-is-latest-commit.outputs.CREATE_DEPLOY_EVENT == 'true' }}", @@ -55,7 +78,7 @@ ], ), ] + - (if deployToTest == true then + (if deployToTest == true && std.member(deployTargets, 'test') == false then [ $.ghJob( 'create-merge-deployment-test',