Skip to content

Commit a9a62e6

Browse files
Merge pull request #803 from sparrowapp-dev/development
Merge development into release v2
2 parents 88e4c8a + 7e3751f commit a9a62e6

File tree

56 files changed

+6063
-2800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+6063
-2800
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
PORT=9000 # Port on which the application server will run
88
APP_ENV=DEV # Runtime environment (DEV|STAGE|PROD)
99
APP_URL=http://localhost # Base URL where the application is hosted
10+
APP_EDITION=MANAGED # Edition of the application (MANAGED|SELFHOSTED)
1011

1112
# [AUTHENTICATION SERVICE]
1213
# Endpoint for authentication services
@@ -123,3 +124,7 @@ STRIPE_SECRET_KEY= # Stripe secret key (backend - KEEP SECURE!)
123124
SPARROW_ADMIN_KEY= # Sparrow admin key for privileged operations specific to Sparrow team
124125
ADMIN_BASE_URL= # Base URL for Sparrow admin operations
125126
STAKEHOLDERS_EMAIL_LIST= # Comma-separated list of sparrow admin emails
127+
128+
# [Self Host]
129+
SELF_HOST_ADMIN_EMAIL=
130+
SELF_HOST_ADMIN_PASSWORD=
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Self-host Docker Image
2+
on:
3+
push:
4+
branches:
5+
- release-v2
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
environment: self-host
15+
16+
env:
17+
DOCKER_IMAGE_NAME: sparrowapi/sparrow-api
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Read version from package.json
24+
id: version
25+
run: |
26+
if ! command -v jq >/dev/null 2>&1; then
27+
echo "jq not found"; exit 1
28+
fi
29+
V=$(jq -r '.version' package.json)
30+
if [ -z "$V" ] || [ "$V" = "null" ]; then
31+
echo "Version not found in package.json"; exit 1
32+
fi
33+
if ! [[ "$V" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
34+
echo "Version $V is not valid semver (expected X.Y.Z)"; exit 1
35+
fi
36+
echo "full=$V" >> "$GITHUB_OUTPUT"
37+
38+
39+
- name: Set up QEMU
40+
uses: docker/setup-qemu-action@v3
41+
42+
- name: Set up Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Log in to Docker Hub
46+
uses: docker/login-action@v3
47+
with:
48+
username: ${{ secrets.SPARROW_DOCKERHUB_USERNAME }}
49+
password: ${{ secrets.SPARROW_DOCKERHUB_PASSWORD }}
50+
51+
- name: Build and push (multi-arch)
52+
run: |
53+
set -euo pipefail
54+
VERSION='${{ steps.version.outputs.full }}'
55+
echo "Building image tag: $VERSION"
56+
docker buildx build \
57+
--platform linux/amd64,linux/arm64 \
58+
--build-arg GITHUB_TOKEN=${{ secrets.SPARROW_GITHUB_TOKEN }} \
59+
-t $DOCKER_IMAGE_NAME:$VERSION \
60+
-t $DOCKER_IMAGE_NAME:latest \
61+
--push .

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN apk update && apk add --no-cache python3 py3-pip build-base gcc
1818
# Install dependencies with the preferred package manager
1919
RUN npm i -g pnpm@latest
2020
RUN pnpm install --frozen-lockfile
21-
RUN pnpm add @sparrowapp-dev/stripe-billing@1.0.0
21+
RUN pnpm add @sparrowapp-dev/stripe-billing@1.3.1
2222
# RUN corepack enable pnpm && pnpm i --frozen-lockfile
2323

2424
FROM node:18-alpine AS builder

deploymentManifests/deployment.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ spec:
386386
secretKeyRef:
387387
name: sparrow-api-secret
388388
key: STAKEHOLDERS_EMAIL_LIST
389+
- name: APP_EDITION
390+
valueFrom:
391+
secretKeyRef:
392+
name: sparrow-api-secret
393+
key: APP_EDITION
394+
- name: SELF_HOST_ADMIN_EMAIL
395+
valueFrom:
396+
secretKeyRef:
397+
name: sparrow-api-secret
398+
key: SELF_HOST_ADMIN_EMAIL
399+
- name: SELF_HOST_ADMIN_PASSWORD
400+
valueFrom:
401+
secretKeyRef:
402+
name: sparrow-api-secret
403+
key: SELF_HOST_ADMIN_PASSWORD
389404

390405
---
391406
apiVersion: v1

deploymentManifests/release-v2.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,21 @@ spec:
355355
secretKeyRef:
356356
name: release-api-v2-secret
357357
key: STAKEHOLDERS_EMAIL_LIST
358+
- name: APP_EDITION
359+
valueFrom:
360+
secretKeyRef:
361+
name: release-api-v2-secret
362+
key: APP_EDITION
363+
- name: SELF_HOST_ADMIN_EMAIL
364+
valueFrom:
365+
secretKeyRef:
366+
name: release-api-v2-secret
367+
key: SELF_HOST_ADMIN_EMAIL
368+
- name: SELF_HOST_ADMIN_PASSWORD
369+
valueFrom:
370+
secretKeyRef:
371+
name: release-api-v2-secret
372+
key: SELF_HOST_ADMIN_PASSWORD
358373

359374
---
360375
apiVersion: v1
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
import { Injectable, OnModuleInit, Inject } from "@nestjs/common";
3+
import { Collections } from "@src/modules/common/enum/database.collection.enum";
4+
import { Db } from "mongodb";
5+
import { ItemTypeEnum } from "@src/modules/common/models/collection.model";
6+
7+
8+
@Injectable()
9+
export class AddTestsToRootRequestItemsMigration implements OnModuleInit {
10+
private hasRun = false;
11+
constructor(@Inject("DATABASE_CONNECTION") private db: Db) {}
12+
13+
async onModuleInit(): Promise<void> {
14+
if (this.hasRun) return;
15+
try {
16+
console.log("[Nest] Starting AddTestsToRootRequestItemsMigration...");
17+
const collectionCollection = this.db.collection(Collections.COLLECTION);
18+
const collections = await collectionCollection.find().toArray();
19+
let updatedCount = 0;
20+
for (const collection of collections) {
21+
let updated = false;
22+
23+
24+
function addFieldsToRequestItems(items: any[]): void {
25+
if (!Array.isArray(items)) return;
26+
for (const item of items) {
27+
if (item.type === ItemTypeEnum.REQUEST && item.request) {
28+
// Add tests if missing
29+
if (!item?.request?.tests) {
30+
item.request.tests = {
31+
testCaseMode: "no-code",
32+
noCode: [
33+
{
34+
id: "case-1",
35+
name: "New Test",
36+
condition: "",
37+
expectedResult: "",
38+
testPath: "",
39+
testTarget: "",
40+
},
41+
],
42+
script: "",
43+
};
44+
updated = true;
45+
}
46+
// Add selectedRequestAuthProfileId if missing
47+
if (!item?.request?.selectedRequestAuthProfileId) {
48+
item.request.selectedRequestAuthProfileId = "";
49+
updated = true;
50+
}
51+
}
52+
if (Array.isArray(item.items)) {
53+
addFieldsToRequestItems(item.items);
54+
}
55+
}
56+
}
57+
58+
addFieldsToRequestItems(collection.items);
59+
60+
if (updated) {
61+
await collectionCollection.updateOne(
62+
{ _id: collection._id },
63+
{ $set: { items: collection.items } }
64+
);
65+
updatedCount++;
66+
}
67+
}
68+
console.log(`[Nest] Migration completed: ${updatedCount} collections updated with tests object.`);
69+
this.hasRun = true;
70+
} catch (error) {
71+
console.error("[Nest] Error during AddTestsToRootRequestItemsMigration:", error);
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)