forked from tsai/budibase
19 changed files with 381 additions and 94 deletions
@ -0,0 +1,93 @@ |
|||
|
|||
# Budibase CI Pipelines |
|||
|
|||
Welcome to the budibase CI pipelines directory. This document details what each of the CI pipelines are for, and come common combinations. |
|||
|
|||
## All CI Pipelines |
|||
|
|||
### Note |
|||
- When running workflow dispatch jobs, ensure you always run them off the `master` branch. It defaults to `develop`, so double check before running any jobs. |
|||
|
|||
### Standard CI Build Job (budibase_ci.yml) |
|||
Triggers: |
|||
- PR or push to develop |
|||
- PR or push to master |
|||
|
|||
The standard CI Build job is what runs when you raise a PR to develop or master. |
|||
- Installs all dependencies, |
|||
- builds the project |
|||
- run the unit tests |
|||
- Generate test coverage metrics with codecov |
|||
- Run the cypress tests |
|||
|
|||
### Release Develop Job (release-develop.yml) |
|||
Triggers: |
|||
- Push to develop |
|||
|
|||
The job responsible for building, tagging and pushing docker images out to the test and staging environments. |
|||
- Installs all dependencies |
|||
- builds the project |
|||
- run the unit tests |
|||
- publish the budibase JS packages under a prerelease tag to NPM |
|||
- build, tag and push docker images under the `develop` tag to docker hub |
|||
|
|||
These images will then be pulled by the test and staging environments, updating the latest automatically. Discord notifications are sent to the #infra channel when this occurs. |
|||
|
|||
### Release Job (release.yml) |
|||
Triggers: |
|||
- Push to master |
|||
|
|||
This job is responsible for building and pushing the latest code to NPM and docker hub, so that it can be deployed. |
|||
- Installs all dependencies |
|||
- builds the project |
|||
- run the unit tests |
|||
- publish the budibase JS packages under a release tag to NPM (always incremented by patch versions) |
|||
- build, tag and push docker images under the `v.x.x.x` (the tag of the NPM release) tag to docker hub |
|||
|
|||
### Release Selfhost Job (release-selfhost.yml) |
|||
Triggers: |
|||
- Manual Workflow Dispatch Trigger |
|||
|
|||
This job is responsible for delivering the latest version of budibase to those that are self-hosting. |
|||
|
|||
This job relies on the release job to have run first, so the latest image is pushed to dockerhub. This job then will pull the latest version from `lerna.json` and try to find an image in dockerhub corresponding to that version. For example, if the version in `lerna.json` is `1.0.0`: |
|||
- Pull the images for all budibase services tagged `v1.0.0` from dockerhub |
|||
- Tag these images as `latest` |
|||
- Push them back to dockerhub. This now means anyone who pulls `latest` (self hosters using docker-compose) will get the latest version. |
|||
- Build and release the budibase helm chart for kubernetes users |
|||
- Perform a github release with the latest version. You can see previous releases here (https://github.com/Budibase/budibase/releases) |
|||
|
|||
|
|||
### Cloud Deploy (deploy-cloud.yml) |
|||
Triggers: |
|||
- Manual Workflow Dispatch Trigger |
|||
|
|||
This job is responsible for deploying to our production, cloud kubernetes environment. You must run the release job first, to ensure that the latest images have been built and pushed to docker hub. You can also manually enter a version number for this job, so you can perform rollbacks or upgrade to a specific version. After kicking off this job, the following will occur: |
|||
|
|||
- Checks out the master branch |
|||
- Pulls the latest `values.yaml` from budibase infra, a private repo containing budibases infrastructure configuration |
|||
- Gets the latest budibase version from `lerna.json`, if it hasn't been specified in the workflow when you kicked it off |
|||
- Configures AWS Credentials |
|||
- Deploys the helm chart in the budibase repo to our production EKS cluster, injecting the `values.yaml` we pulled from budibase-infra |
|||
- Fires off a discord webhook in the #infra channel to show that the deployment completely successfully. |
|||
|
|||
## Common Workflows |
|||
|
|||
### Deploy Changes to Production (Release) |
|||
- Merge `develop` into `master` |
|||
- Wait for budibase CI job and release job to run |
|||
- Run cloud deploy job |
|||
- Run release selfhost job |
|||
|
|||
### Deploy Changes to Production (Hotfix) |
|||
- Branch off `master` |
|||
- Perform your hotfix |
|||
- Merge back into `master` |
|||
- Wait for budibase CI job and release job to run |
|||
- Run cloud deploy job |
|||
- Run release selfhost job |
|||
|
|||
### Rollback A Bad Cloud Deployment |
|||
- Kick off cloud deploy job |
|||
- Ensure you are running off master |
|||
- Enter the version number of the last known good version of budibase. For example `1.0.0` |
|||
@ -0,0 +1,9 @@ |
|||
dependencies: |
|||
- name: couchdb |
|||
repository: https://apache.github.io/couchdb-helm |
|||
version: 3.3.4 |
|||
- name: ingress-nginx |
|||
repository: https://kubernetes.github.io/ingress-nginx |
|||
version: 4.0.13 |
|||
digest: sha256:20892705c2d8e64c98257d181063a514ac55013e2b43399a6e54868a97f97845 |
|||
generated: "2021-12-30T18:55:30.878411Z" |
|||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,161 @@ |
|||
const { processString } = require("@budibase/string-templates") |
|||
const CouchDB = require("../../db") |
|||
const { |
|||
generateQueryID, |
|||
getQueryParams, |
|||
isProdAppID, |
|||
} = require("../../db/utils") |
|||
const { BaseQueryVerbs } = require("../../constants") |
|||
const { Thread, ThreadType } = require("../../threads") |
|||
const env = require("../../environment") |
|||
|
|||
const Runner = new Thread(ThreadType.QUERY, { |
|||
timeoutMs: env.QUERY_THREAD_TIMEOUT || 10000, |
|||
}) |
|||
|
|||
// simple function to append "readable" to all read queries
|
|||
function enrichQueries(input) { |
|||
const wasArray = Array.isArray(input) |
|||
const queries = wasArray ? input : [input] |
|||
for (let query of queries) { |
|||
if (query.queryVerb === BaseQueryVerbs.READ) { |
|||
query.readable = true |
|||
} |
|||
} |
|||
return wasArray ? queries : queries[0] |
|||
} |
|||
|
|||
exports.fetch = async function (ctx) { |
|||
const db = new CouchDB(ctx.appId) |
|||
|
|||
const body = await db.allDocs( |
|||
getQueryParams(null, { |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
ctx.body = enrichQueries(body.rows.map(row => row.doc)) |
|||
} |
|||
|
|||
exports.save = async function (ctx) { |
|||
const db = new CouchDB(ctx.appId) |
|||
const query = ctx.request.body |
|||
|
|||
if (!query._id) { |
|||
query._id = generateQueryID(query.datasourceId) |
|||
} |
|||
|
|||
const response = await db.put(query) |
|||
query._rev = response.rev |
|||
|
|||
ctx.body = query |
|||
ctx.message = `Query ${query.name} saved successfully.` |
|||
} |
|||
|
|||
async function enrichQueryFields(fields, parameters = {}) { |
|||
const enrichedQuery = {} |
|||
|
|||
// enrich the fields with dynamic parameters
|
|||
for (let key of Object.keys(fields)) { |
|||
if (fields[key] == null) { |
|||
continue |
|||
} |
|||
if (typeof fields[key] === "object") { |
|||
// enrich nested fields object
|
|||
enrichedQuery[key] = await enrichQueryFields(fields[key], parameters) |
|||
} else if (typeof fields[key] === "string") { |
|||
// enrich string value as normal
|
|||
enrichedQuery[key] = await processString(fields[key], parameters, { |
|||
noHelpers: true, |
|||
}) |
|||
} else { |
|||
enrichedQuery[key] = fields[key] |
|||
} |
|||
} |
|||
|
|||
if ( |
|||
enrichedQuery.json || |
|||
enrichedQuery.customData || |
|||
enrichedQuery.requestBody |
|||
) { |
|||
try { |
|||
enrichedQuery.json = JSON.parse( |
|||
enrichedQuery.json || |
|||
enrichedQuery.customData || |
|||
enrichedQuery.requestBody |
|||
) |
|||
} catch (err) { |
|||
throw { message: `JSON Invalid - error: ${err}` } |
|||
} |
|||
delete enrichedQuery.customData |
|||
} |
|||
|
|||
return enrichedQuery |
|||
} |
|||
|
|||
exports.find = async function (ctx) { |
|||
const db = new CouchDB(ctx.appId) |
|||
const query = enrichQueries(await db.get(ctx.params.queryId)) |
|||
// remove properties that could be dangerous in real app
|
|||
if (isProdAppID(ctx.appId)) { |
|||
delete query.fields |
|||
delete query.parameters |
|||
} |
|||
ctx.body = query |
|||
} |
|||
|
|||
exports.preview = async function (ctx) { |
|||
const db = new CouchDB(ctx.appId) |
|||
|
|||
const datasource = await db.get(ctx.request.body.datasourceId) |
|||
|
|||
const { fields, parameters, queryVerb, transformer } = ctx.request.body |
|||
const enrichedQuery = await enrichQueryFields(fields, parameters) |
|||
|
|||
try { |
|||
const { rows, keys } = await Runner.run({ |
|||
datasource, |
|||
queryVerb, |
|||
query: enrichedQuery, |
|||
transformer, |
|||
}) |
|||
|
|||
ctx.body = { |
|||
rows, |
|||
schemaFields: [...new Set(keys)], |
|||
} |
|||
} catch (err) { |
|||
ctx.throw(400, err) |
|||
} |
|||
} |
|||
|
|||
exports.execute = async function (ctx) { |
|||
const db = new CouchDB(ctx.appId) |
|||
|
|||
const query = await db.get(ctx.params.queryId) |
|||
const datasource = await db.get(query.datasourceId) |
|||
|
|||
const enrichedQuery = await enrichQueryFields( |
|||
query.fields, |
|||
ctx.request.body.parameters |
|||
) |
|||
|
|||
// call the relevant CRUD method on the integration class
|
|||
try { |
|||
const { rows } = await Runner.run({ |
|||
datasource, |
|||
queryVerb: query.queryVerb, |
|||
query: enrichedQuery, |
|||
transformer: query.transformer, |
|||
}) |
|||
ctx.body = rows |
|||
} catch (err) { |
|||
ctx.throw(400, err) |
|||
} |
|||
} |
|||
|
|||
exports.destroy = async function (ctx) { |
|||
const db = new CouchDB(ctx.appId) |
|||
await db.remove(ctx.params.queryId, ctx.params.revId) |
|||
ctx.message = `Query deleted.` |
|||
ctx.status = 200 |
|||
} |
|||
Loading…
Reference in new issue