Skip to content

Commit

Permalink
RNET-1097 Move CI to BaaSaas (#3525)
Browse files Browse the repository at this point in the history
* Added various things

* Small fixes

* Fixed running baasaas locally

* Various improvements

* Clean up

* Small fixes

* Fix

* Docs fix

* Small fix

* Removed unity pragma

* Added extraction

* Small fix

* Unification

* Corrections

* Added wait for baas to be up

* First step at CI workflows

* Removed unused

* Small fix

* Removed unused

* Corrected deploy apps

* Fixed naming

* Improvements

* Fix

* Removed unused

* Small renaming
  • Loading branch information
papafe authored Feb 21, 2024
1 parent b434a43 commit ff31f4a
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 426 deletions.
44 changes: 8 additions & 36 deletions .github/templates/build.lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@

#@ ignoreSkippedJobsCondition = "always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')"

#! These secrets will run against cloud-dev on PRs or cloud-qa on merges to main. They're commented out
#! because it appears cloud-dev is quite unstable at this point (Aug 2022).
#! realm_BaseUrl = "${{ (" + isRelease + " && secrets.REALM_QA_BASE_URL) || secrets.REALM_BASE_URL }}"
#! atlas_BaseUrl = "${{ (" + isRelease + " && secrets.ATLAS_QA_BASE_URL) || secrets.ATLAS_BASE_URL }}"
#! secret_AtlasPublicKey = "${{ (" + isRelease + " && secrets.ATLAS_QA_PUBLIC_API_KEY) || secrets.ATLAS_PUBLIC_API_KEY }}"
#! secret_AtlasPrivateKey = "${{ (" + isRelease + " && secrets.ATLAS_QA_PRIVATE_API_KEY) || secrets.ATLAS_PRIVATE_API_KEY }}"
#! secret_AtlasProjectId = "${{ (" + isRelease + " && secrets.ATLAS_QA_PROJECT_ID) || secrets.ATLAS_PROJECT_ID }}"

#@ realm_BaseUrl = "https://realm-qa.mongodb.com"
#@ atlas_BaseUrl = "https://cloud-qa.mongodb.com"
#@ secret_AtlasPublicKey = "${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}"
#@ secret_AtlasPrivateKey = "${{ secrets.ATLAS_QA_PRIVATE_API_KEY }}"
#@ secret_AtlasProjectId = "${{ secrets.ATLAS_QA_PROJECT_ID }}"
#@ secret_BaaSaasApiKey = "${{ secrets.BAASAAS_API_KEY }}"

#@ def getJobName(prefix, name):
#@ if (prefix != ""):
Expand All @@ -31,43 +19,34 @@
#@ for target in targets:
#@ differentiators.append('"' + getJobName("", target) + '"')
#@ end
deploy-cluster:
deploy-baas:
uses: ./.github/workflows/deploy-baas.yml
with:
differentiators: #@ '[' + ", ".join(differentiators) + ']'
BaseUrl: #@ realm_BaseUrl
AtlasBaseUrl: #@ atlas_BaseUrl
secrets:
AtlasProjectId: #@ secret_AtlasProjectId
AtlasPublicKey: #@ secret_AtlasPublicKey
AtlasPrivateKey: #@ secret_AtlasPrivateKey
BaaSaasApiKey: #@ secret_BaaSaasApiKey
#@ end

#! We need to have two input arrays because there is not a 1-to-1 correspondence between dependencies
#! and targets, for example for macOS.
#@ def cleanupBaas(dependencies = [], targets = []):
#@ needs = ["deploy-cluster"]
#@ needs = ["deploy-baas"]
#@ differentiators = []
#@ for dependency in dependencies:
#@ needs.append(getJobName("test", dependency))
#@ end
#@ for target in targets:
#@ differentiators.append('"' + getJobName("", target) + '"')
#@ end
cleanup-cluster:
cleanup-baas:
uses: ./.github/workflows/cleanup-baas.yml
if: always()
name: Cleanup
needs: #@ needs
with:
differentiators: #@ '[' + ", ".join(differentiators) + ']'
clusterName: ${{ needs.deploy-cluster.outputs.clusterName }}
BaseUrl: #@ realm_BaseUrl
AtlasBaseUrl: #@ atlas_BaseUrl
secrets:
AtlasProjectId: #@ secret_AtlasProjectId
AtlasPublicKey: #@ secret_AtlasPublicKey
AtlasPrivateKey: #@ secret_AtlasPrivateKey
BaaSaasApiKey: #@ secret_BaaSaasApiKey
#@ end

#@ def runTests(name, runSyncTests = True, additionalSecrets = []):
Expand All @@ -79,20 +58,13 @@ cleanup-cluster:
needs:
- build-packages
#@ if runSyncTests:
- deploy-cluster
- deploy-baas
#@ end
with:
version: ${{ needs.build-packages.outputs.package_version }}
#@ if runSyncTests:
clusterName: ${{ needs.deploy-cluster.outputs.clusterName }}
realmUrl: #@ realm_BaseUrl
atlasUrl: #@ atlas_BaseUrl
#@ end
secrets:
#@ if runSyncTests:
AtlasProjectId: #@ secret_AtlasProjectId
AtlasPublicKey: #@ secret_AtlasPublicKey
AtlasPrivateKey: #@ secret_AtlasPrivateKey
BaaSaasApiKey: #@ secret_BaaSaasApiKey
#@ end
#@ for secret in additionalSecrets:
#@yaml/text-templated-strings
Expand Down
37 changes: 10 additions & 27 deletions .github/templates/test.lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#@ load("common.lib.yml", "actionDownloadArtifact", "msbuild", "dotnetPublish", "fetchWrapperBinaries", "checkoutCode", "fetchPackageArtifacts")

#@ def baasTestArgs(differentiator):
#@ return " --baasurl=${{ inputs.realmUrl }} --baascluster=${{ inputs.clusterName }}-"+ differentiator +" --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=" + differentiator
#@ return " --baasaas-api-key=${{ secrets.BaaSaasApiKey}} --baas-differentiator=" + differentiator
#@ end
---
#@ def publishTestsResults(files, test_title):
Expand All @@ -26,27 +26,14 @@ with:
version:
required: true
type: string
clusterName:
required: false
type: string
realmUrl:
required: false
type: string
atlasUrl:
required: false
type: string
#@ for input in additionalInputs:
#@yaml/text-templated-strings
(@= input @):
required: true
type: string
#@ end
secrets:
AtlasProjectId:
required: false
AtlasPublicKey:
required: false
AtlasPrivateKey:
BaaSaasApiKey:
required: false
#@ for secret in additionalSecrets:
#@yaml/text-templated-strings
Expand Down Expand Up @@ -93,17 +80,13 @@ env:
- #@ template.replace(fetchPackageArtifacts())
#@ end
#@ if (differentiator != ""):
#! The following is used in case we need to re-run the action and the main deploy cluster job is not re-run too (because successful)
- uses: realm/ci-actions/mdb-realm/deploy@fa20eb972b9f018654fdb4e2c7afb52b0532f907
name: Deploy Cluster (alternative)
if: ${{ inputs.realmUrl }}
with:
projectId: ${{ secrets.AtlasProjectId}}
realmUrl: ${{ inputs.realmUrl }}
atlasUrl: ${{ inputs.atlasUrl}}
apiKey: ${{ secrets.AtlasPublicKey}}
privateApiKey: ${{ secrets.AtlasPrivateKey }}
clusterName: #@ "${{ inputs.clusterName }}-" + differentiator
clusterSize: M10
#! The following is used in case we need to re-run the action and the main deploy baas job is not re-run too (because successful)
- name: Deploy Baas (alternative)
#! Secrets cannot be used directly in if
env:
apiKey: ${{ secrets.BaaSaasApiKey }}
if: ${{ env.apiKey }}
run: #@ "dotnet run deploy-apps --baasaas-api-key=${{ secrets.BaaSaasApiKey }} --baas-differentiator=" + differentiator
working-directory: Tools/DeployApps
#@ end
#@ end
29 changes: 7 additions & 22 deletions .github/workflows/cleanup-baas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@ name: cleanup-baas
differentiators:
required: true
type: string
clusterName:
required: true
type: string
BaseUrl:
required: true
type: string
AtlasBaseUrl:
required: true
type: string
secrets:
AtlasProjectId:
required: true
AtlasPublicKey:
required: true
AtlasPrivateKey:
BaaSaasApiKey:
required: true
env:
REALM_DISABLE_ANALYTICS: true
DOTNET_NOLOGO: true
jobs:
cleanup-baas:
name: Cleanup Cluster
name: Cleanup Baas
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -38,11 +25,9 @@ jobs:
with:
submodules: false
ref: ${{ github.event.pull_request.head.sha }}
- uses: realm/ci-actions/mdb-realm/cleanup@fa20eb972b9f018654fdb4e2c7afb52b0532f907
- uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a
with:
projectId: ${{ secrets.AtlasProjectId}}
realmUrl: ${{ inputs.BaseUrl }}
atlasUrl: ${{ inputs.AtlasBaseUrl}}
apiKey: ${{ secrets.AtlasPublicKey}}
privateApiKey: ${{ secrets.AtlasPrivateKey }}
clusterName: ${{ inputs.clusterName }}-${{ matrix.differentiator }}
dotnet-version: 6.0.x
- name: Terminate Baas
run: dotnet run terminate-baas --baasaas-api-key=${{ secrets.BaaSaasApiKey }} --baas-differentiator=${{ matrix.differentiator }}
working-directory: Tools/DeployApps
50 changes: 3 additions & 47 deletions .github/workflows/deploy-baas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,15 @@ name: deploy-baas
differentiators:
required: true
type: string
BaseUrl:
required: true
type: string
AtlasBaseUrl:
required: true
type: string
outputs:
clusterName:
value: ${{ jobs.deploy-baas.outputs.clusterName }}
secrets:
AtlasProjectId:
required: true
AtlasPublicKey:
required: true
AtlasPrivateKey:
BaaSaasApiKey:
required: true
env:
REALM_DISABLE_ANALYTICS: true
DOTNET_NOLOGO: true
jobs:
deploy-baas:
name: Deploy Cluster
runs-on: ubuntu-latest
strategy:
matrix:
differentiator: ${{ fromJson(inputs.differentiators) }}
outputs:
clusterName: ${{ steps.generate-cluster-name.outputs.clusterName }}
timeout-minutes: 20
steps:
- name: Generate cluster name
id: generate-cluster-name
run: |
name=$( echo ${{ github.run_id }}-${{ github.run_attempt }} | md5sum | cut -c1-7)
echo "clusterName=$name" >> "$GITHUB_OUTPUT"
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: false
ref: ${{ github.event.pull_request.head.sha }}
- uses: realm/ci-actions/mdb-realm/deploy@fa20eb972b9f018654fdb4e2c7afb52b0532f907
id: deploy-cluster
with:
projectId: ${{ secrets.AtlasProjectId}}
realmUrl: ${{ inputs.BaseUrl }}
atlasUrl: ${{ inputs.AtlasBaseUrl}}
apiKey: ${{ secrets.AtlasPublicKey}}
privateApiKey: ${{ secrets.AtlasPrivateKey }}
clusterName: ${{ steps.generate-cluster-name.outputs.clusterName }}-${{ matrix.differentiator }}
clusterSize: M5
deploy-apps:
name: Deploy Apps
needs: deploy-baas
name: Deploy Baas
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -73,5 +29,5 @@ jobs:
with:
dotnet-version: 6.0.x
- name: Deploy Apps
run: dotnet run . --baasurl=${{ inputs.BaseUrl }} --baascluster=${{ needs.deploy-baas.outputs.clusterName }}-${{ matrix.differentiator }} --baasapikey=${{ secrets.AtlasPublicKey }} --baasprivateapikey=${{ secrets.AtlasPrivateKey }} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=${{ matrix.differentiator }}
run: dotnet run deploy-apps --baasaas-api-key=${{ secrets.BaaSaasApiKey }} --baas-differentiator=${{ matrix.differentiator }}
working-directory: Tools/DeployApps
Loading

0 comments on commit ff31f4a

Please sign in to comment.