Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soon snapshot #2880

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 20 additions & 76 deletions .github/workflows/action_deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,37 @@
name: Action | Deploy to Production

on:
release:
types: [published]
on: pull_request

jobs:
deploy_search:
roll-firestore:
runs-on: ubuntu-latest
environment: production
timeout-minutes: 30
timeout-minutes: 360
defaults:
run:
working-directory: packages/functions
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.SERVICE_ACCOUNT }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: Set env vars
working-directory: packages/search
run: echo "$ENV_VARS" > .env
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
- name: Build image
run: |
cp packages/search/Dockerfile .
gcloud builds submit --tag gcr.io/$GOOGLE_CLOUD_PROJECT/search
- name: Deploy
run: |
gcloud run deploy search \
--image gcr.io/$GOOGLE_CLOUD_PROJECT/search \
--min-instances=3 \
--memory=1Gi \
--cpu=1 \
--concurrency=1000 \
--allow-unauthenticated \
--timeout=600 \
--ingress=internal-and-cloud-load-balancing \
--add-cloudsql-instances $GOOGLE_CLOUD_PROJECT:us-central1:buildcore \
--region=us-central1 \

deploy_functions:
runs-on: ubuntu-latest
environment: production
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.SERVICE_ACCOUNT }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: Set env vars
working-directory: packages/functions
run: echo "$ENV_VARS" > .env
echo "$ENV_VARS" > .env
sed -i 's/DB_HOST=".*/DB_HOST=127.0.0.1/' .env
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
- name: Build and deploy
run: |
npm run build:functions
npm run create-deploy-script
chmod 777 ./deploy.sh
./deploy.sh

deploy_to_npm:
runs-on: ubuntu-latest
environment: production
timeout-minutes: 30
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_TOKEN}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Create serviceAccountKey.json
run: echo "$SERVICE_ACCOUNT" > scripts/serviceAccountKey.json
env:
SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
- uses: mattes/gce-cloudsql-proxy-action@v1
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Init
run: |
npm version ${{ github.event.release.tag_name }} --workspace packages/interfaces
npm version ${{ github.event.release.tag_name }} --workspace packages/sdk
npm run build:sdk
- name: Deploy to npm
creds: '${{ secrets.SERVICE_ACCOUNT }}'
instance: buildcore-prod:us-central1:buildcore
- name: Install dependencies
run: |
npm publish --workspace packages/interfaces
cd packages/sdk/lib && npm publish
npm i -g ts-node
cd ../../ && npm run build:functions
- name: Roll firestore
run: cd scripts && ts-node db.upgrade.ts
40 changes: 40 additions & 0 deletions .github/workflows/functions_tangle-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3547,3 +3547,43 @@ jobs:
npm run start &
npm run notifier &
npm run test -- --findRelatedTests --forceExit ./test-tangle/minted-token-trade/minted-token-trade_15.only.spec.ts
chunk_84:
needs: npm-install
runs-on: ubuntu-latest
timeout-minutes: 20

services:
postgres:
image: postgres
env:
POSTGRES_DB: buildcore
POSTGRES_PASSWORD: postgres
POSTGRES_MAX_CONNECTIONS: 400
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: actions/cache@v4
with:
path: |
node_modules
packages/functions/node_modules
packages/interfaces/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }}
- name: Init
run: npm run build:functions
- name: Test
working-directory: packages/functions
run: |
npm run start &
npm run notifier &
npm run test -- --findRelatedTests --forceExit ./test-tangle/soon.snapshot.only.spec.ts
3 changes: 3 additions & 0 deletions packages/database/src/pg/interfaces/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class ICollection<T, Q extends BaseRecord, U extends Update> {
value: Q[F] | undefined | null,
) => this.createQuery().where(fieldPath, operator, value);

whereIn = <F extends keyof Q>(fieldPath: F, value: Q[F][]): IQuery<T, Q> =>
this.createQuery().whereIn(fieldPath, value);

update = async <F extends keyof Q>(data: U, where: Record<F, Q[F]>) => {
await this.con(this.table).update(undefinedToNull(data)).where(where);
};
Expand Down
31 changes: 5 additions & 26 deletions packages/functions/scripts/db.upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import { FirebaseApp } from '@buildcore/database';
import { COL } from '@buildcore/interfaces';
import crypto from 'crypto';
import { database } from '@buildcore/database';
import dotenv from 'dotenv';
import admin from 'firebase-admin';
import { getFirestore } from 'firebase-admin/firestore';
import fs from 'fs';
import { glob } from 'glob';
import serviceAccount from './serviceAccountKey.json';
const glob = require('glob');

dotenv.config({ path: '../.env' });

const app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount as any),
});
process.env.FIREBASE_CONFIG = JSON.stringify({ projectId: serviceAccount.project_id });

const execute = async () => {
const db = getFirestore(app);
const files = glob.sync(`./dbUpgrades/**/*.ts`);
for (const file of files.sort()) {
const content = fs.readFileSync(file);
const hash = crypto.createHash('sha1').update(content).digest('hex');

const docRef = db.doc(`${COL.DB_ROLL_FILES}/${hash}`);
const doc = await docRef.get();
if (doc.exists) {
console.warn(`${file} script was already ran`);
continue;
}

console.log(`Running ${file}`);
const func = await import(pathToImportFileName(file));
await func.roll(new FirebaseApp(app));
await docRef.create({});
await func.roll();
}

await database().destroy();
};

const pathToImportFileName = (path: string) => './' + path.replace('.ts', '');
Expand Down
Loading
Loading