From a4eef3daab61fae3c311d931d64bc7479347dc4c Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 1 Jun 2022 14:10:00 +0100 Subject: [PATCH] Add awareness of deployment environment --- charts/budibase/templates/app-service-deployment.yaml | 2 ++ charts/budibase/templates/worker-service-deployment.yaml | 2 ++ hosting/single/Dockerfile | 1 + packages/backend-core/src/environment.ts | 4 +++- packages/backend-core/src/events/backfill.ts | 5 ++--- .../backend-core/src/events/processors/PosthogProcessor.ts | 1 + packages/server/Dockerfile | 1 + packages/server/scripts/dev/manage.js | 2 ++ packages/types/src/events/event.ts | 1 + packages/worker/Dockerfile | 2 ++ packages/worker/scripts/dev/manage.js | 2 ++ 11 files changed, 19 insertions(+), 4 deletions(-) diff --git a/charts/budibase/templates/app-service-deployment.yaml b/charts/budibase/templates/app-service-deployment.yaml index 98a949418c..8797edf42b 100644 --- a/charts/budibase/templates/app-service-deployment.yaml +++ b/charts/budibase/templates/app-service-deployment.yaml @@ -28,6 +28,8 @@ spec: - env: - name: BUDIBASE_ENVIRONMENT value: {{ .Values.globals.budibaseEnv }} + - name: DEPLOYMENT_ENVIRONMENT + value: "kubernetes" - name: COUCH_DB_URL {{ if .Values.services.couchdb.url }} value: {{ .Values.services.couchdb.url }} diff --git a/charts/budibase/templates/worker-service-deployment.yaml b/charts/budibase/templates/worker-service-deployment.yaml index 15ff05e214..8c3c878bec 100644 --- a/charts/budibase/templates/worker-service-deployment.yaml +++ b/charts/budibase/templates/worker-service-deployment.yaml @@ -27,6 +27,8 @@ spec: spec: containers: - env: + - name: DEPLOYMENT_ENVIRONMENT + value: "kubernetes" - name: CLUSTER_PORT value: {{ .Values.services.worker.port | quote }} {{ if .Values.services.couchdb.enabled }} diff --git a/hosting/single/Dockerfile b/hosting/single/Dockerfile index 2123d237b5..88e7b1fb68 100644 --- a/hosting/single/Dockerfile +++ b/hosting/single/Dockerfile @@ -1,5 +1,6 @@ FROM couchdb +ENV DEPLOYMENT_ENVIRONMENT=docker ENV COUCHDB_PASSWORD=budibase ENV COUCHDB_USER=budibase ENV COUCH_DB_URL=http://budibase:budibase@localhost:5984 diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts index 1576c4487d..1d9febc6f9 100644 --- a/packages/backend-core/src/environment.ts +++ b/packages/backend-core/src/environment.ts @@ -52,8 +52,10 @@ const env: any = { process.env.GLOBAL_CLOUD_BUCKET_NAME || "prod-budi-tenant-uploads", USE_COUCH: process.env.USE_COUCH || true, DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE, - SERVICE: process.env.SERVICE || "budibase", DEFAULT_LICENSE: process.env.DEFAULT_LICENSE, + SERVICE: process.env.SERVICE || "budibase", + DEPLOYMENT_ENVIRONMENT: + process.env.DEPLOYMENT_ENVIRONMENT || "docker-compose", _set(key: any, value: any) { process.env[key] = value module.exports[key] = value diff --git a/packages/backend-core/src/events/backfill.ts b/packages/backend-core/src/events/backfill.ts index b4b7d826bf..7b73cc4f82 100644 --- a/packages/backend-core/src/events/backfill.ts +++ b/packages/backend-core/src/events/backfill.ts @@ -1,4 +1,3 @@ -import { UserPermissionAssignedEvent } from "./../../../types/src/events/user" import { Event, BackfillMetadata, @@ -18,7 +17,7 @@ import { AppPublishedEvent, UserCreatedEvent, RoleAssignedEvent, - RowsCreatedEvent, + UserPermissionAssignedEvent, } from "@budibase/types" import * as context from "../context" import { CacheKeys } from "../cache/generic" @@ -173,7 +172,7 @@ const getEventKey = (event?: Event, properties?: any) => { const custom = CUSTOM_PROPERTY_SUFFIX[event] const suffix = custom ? custom(properties) : undefined if (suffix) { - eventKey = `${event}:${suffix}` + eventKey = `${eventKey}:${suffix}` } } else { eventKey = `${CacheKeys.EVENTS}:${tenantId}:*` diff --git a/packages/backend-core/src/events/processors/PosthogProcessor.ts b/packages/backend-core/src/events/processors/PosthogProcessor.ts index efe4ed26c2..5b6a267569 100644 --- a/packages/backend-core/src/events/processors/PosthogProcessor.ts +++ b/packages/backend-core/src/events/processors/PosthogProcessor.ts @@ -23,6 +23,7 @@ export default class PosthogProcessor implements EventProcessor { ): Promise { properties.version = pkg.version properties.service = env.SERVICE + properties.environment = env.DEPLOYMENT_ENVIRONMENT const appId = context.getAppId() if (appId) { diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index f70fdbca95..54468abdee 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -10,6 +10,7 @@ WORKDIR /app ENV PORT=4001 ENV COUCH_DB_URL=https://couchdb.budi.live:5984 ENV BUDIBASE_ENVIRONMENT=PRODUCTION +ENV SERVICE=app-service # copy files and install dependencies COPY . ./ diff --git a/packages/server/scripts/dev/manage.js b/packages/server/scripts/dev/manage.js index 9c1f0eb775..b5cce1c58b 100644 --- a/packages/server/scripts/dev/manage.js +++ b/packages/server/scripts/dev/manage.js @@ -54,6 +54,8 @@ async function init() { DISABLE_ACCOUNT_PORTAL: "", MULTI_TENANCY: "", DISABLE_THREADING: 1, + SERVICE: "app-service", + DEPLOYMENT_ENVIRONMENT: "development", } let envFile = "" Object.keys(envFileJson).forEach(key => { diff --git a/packages/types/src/events/event.ts b/packages/types/src/events/event.ts index 5f61174b88..6c1a37e264 100644 --- a/packages/types/src/events/event.ts +++ b/packages/types/src/events/event.ts @@ -153,6 +153,7 @@ export enum Event { export interface BaseEvent { version?: string service?: string + environment?: string appId?: string installationId?: string tenantId?: string diff --git a/packages/worker/Dockerfile b/packages/worker/Dockerfile index 8d6abc6ad1..086c69fddc 100644 --- a/packages/worker/Dockerfile +++ b/packages/worker/Dockerfile @@ -21,4 +21,6 @@ EXPOSE 4001 # which are actually needed to get this environment up and running ENV NODE_ENV=production ENV CLUSTER_MODE=${CLUSTER_MODE} +ENV SERVICE=worker-service + CMD ["./docker_run.sh"] diff --git a/packages/worker/scripts/dev/manage.js b/packages/worker/scripts/dev/manage.js index bb7e41ce87..96f5c29af4 100644 --- a/packages/worker/scripts/dev/manage.js +++ b/packages/worker/scripts/dev/manage.js @@ -26,6 +26,8 @@ async function init() { ACCOUNT_PORTAL_API_KEY: "budibase", PLATFORM_URL: "http://localhost:10000", APPS_URL: "http://localhost:4001", + SERVICE: "worker-service", + DEPLOYMENT_ENVIRONMENT: "development", } let envFile = "" Object.keys(envFileJson).forEach(key => {