Skip to content

Commit

Permalink
Add ci/cd for infra
Browse files Browse the repository at this point in the history
  • Loading branch information
domdomegg committed Apr 18, 2024
1 parent 879e042 commit 22ad1b9
Show file tree
Hide file tree
Showing 13 changed files with 2,265 additions and 438 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/ci_cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: ci_cd

on: push

jobs:
ci:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout ${{ github.sha }}
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install NPM dependencies
run: npm ci
- name: Lint
run: npm run lint --if-present
- name: Build
run: npm run build --if-present
- name: Test
run: npm run test --if-present
- id: modified_paths_check
uses: fkirc/[email protected]
with:
paths_filter: |
backend:
paths:
- 'apps/backend/**'
bubble-proxy:
paths:
- 'apps/bubble-proxy/**'
frontend-example:
paths:
- 'apps/bubble-proxy/**'
infra:
paths:
- 'apps/infra/**'
paths:
- 'package-lock.json'
outputs:
should_skip: ${{ steps.modified_paths_check.outputs.should_skip }}
paths_result: ${{ steps.modified_paths_check.outputs.paths_result }}

cd_infra:
needs: ci
if: ${{ github.ref == 'refs/heads/master' && needs.ci.outputs.should_skip != 'true' || !fromJSON(needs.ci.outputs.paths_result).infra.should_skip }}
runs-on: ubuntu-latest
concurrency:
group: prevent-concurrent-jobs
timeout-minutes: 10
steps:
- name: Checkout ${{ github.sha }}
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install NPM dependencies
run: npm ci

- name: Configure for deployment
if: github.ref == 'refs/heads/master'
run: |
echo "$INFRA_PULUMI_PASSPHRASE" > apps/infra/passphrase.prod.txt
mkdir -p ~/.aws
echo "$INFRA_AWS_CREDENTIALS" > ~/.aws/credentials
env:
INFRA_PULUMI_PASSPHRASE: ${{ secrets.INFRA_PULUMI_PASSPHRASE }}
# See the infra README - these should actually have details for Vultr Object Storage
INFRA_AWS_CREDENTIALS: ${{ secrets.INFRA_AWS_CREDENTIALS }}
- name: Deploy
if: ${{ github.ref == 'refs/heads/master' }}
run: npm run deploy:prod
3 changes: 2 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"kanel": "tsup tools/kanel.ts --outDir dist_tools --external kanel --external kanel-kysely && NODE_ENV=development node dist_tools/kanel.js",
"resetdb": "dropdb --host=localhost --port=5432 --force postgres && createdb --host=localhost --port=5432 postgres",
"createLock": "tsup tools/createLock.ts --outDir dist_tools --external @npmcli/arborist && NODE_ENV=development node dist_tools/createLock.js",
"test": "vitest",
"test": "vitest --run",
"test:watch": "vitest",
"lint": "eslint ."
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/tools/kanel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { escapeIdentifier, escapeString, processDatabase } from 'kanel';
import { escapeIdentifier, processDatabase } from 'kanel';
import { makeKyselyHook } from 'kanel-kysely';
import { env } from '../src/env';
import { migrateDb } from '../src/db/migrations/migrator';
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"start": "next dev -p 8000",
"build": "next build",
"lint": "eslint .",
"test": "vitest --run",
"test:watch": "vitest",
"deploy:prod": "tools/deployDocker.sh"
},
"dependencies": {
Expand All @@ -23,14 +25,18 @@
"devDependencies": {
"@bluedot/eslint-config": "*",
"@bluedot/typescript-config": "*",
"@testing-library/react": "^15.0.2",
"@types/node": "^20.10.3",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"eslint": "^8.53.0",
"happy-dom": "^14.7.1",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.3.2",
"vitest": "^1.5.0",
"zod": "^3.22.4"
}
}
24 changes: 24 additions & 0 deletions apps/frontend-example/src/components/ErrorPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, test } from 'vitest';
import { ErrorPage } from './ErrorPage';

describe('ErrorPage', () => {
test('should render the error message correctly', () => {
const errorMessage = 'This is an error message';
render(<ErrorPage error={new Error(errorMessage)} />);

const heading = screen.getByRole('heading', { level: 1 });
expect(heading.textContent).toContain('Error');

const errorMessageElement = screen.getByText(errorMessage);
expect(errorMessageElement).toBeDefined();
});

test('should render a default error message when the error is not an instance of Error', () => {
const errorObject = { message: 'This is an error object' };
render(<ErrorPage error={errorObject} />);

const errorMessageElement = screen.getByText('{"message":"This is an error object"}');
expect(errorMessageElement).toBeDefined();
});
});
3 changes: 2 additions & 1 deletion apps/frontend-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"next.config.js",
"src/**/*",
".next/types/**/*.ts",
"tailwind.config.ts"
"tailwind.config.ts",
"vitest.config.ts",
],
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions apps/frontend-example/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';

export default defineConfig({
plugins: [react()],
test: {
environment: 'happy-dom',
},
});
1 change: 1 addition & 0 deletions apps/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"main": "src/index.ts",
"scripts": {
"postinstall": "command -v pulumi >/dev/null 2>&1 || curl -fsSL https://get.pulumi.com | sh",
"deploy:prod": "PULUMI_CONFIG_PASSPHRASE_FILE=passphrase.prod.txt pulumi up --stack prod --yes",
"config:secret": "PULUMI_CONFIG_PASSPHRASE_FILE=passphrase.prod.txt pulumi config set --secret",
"lint": "eslint ."
Expand Down
56 changes: 15 additions & 41 deletions apps/infra/src/k8s/serviceDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { core } from '@pulumi/kubernetes/types/input';
import * as pulumi from '@pulumi/pulumi';
import { dbPassword } from '../config';
import { containerRegistrySecret } from './containerRegistry';

// TODO: pin the external versions
Expand All @@ -16,45 +14,6 @@ export const services: ServiceDefinition[] = [
},
hosts: ['hello.k8s.bluedot.org'],
},
// {
// name: 'mathesar',
// targetPort: 8000,
// spec: {
// containers: [{
// name: 'mathesar',
// image: 'mathesar/mathesar-prod:latest',
// env: [{
// name: 'SECRET_KEY',
// value: mathesarSecretKey,
// }, {
// name: 'DJANGO_DATABASE_URL',
// value: pulumi.all([databaseInstance.publicIpAddress, cloudSqlPassword]).apply(([ip, password]) => `postgresql://postgres:${password}@${ip}/mathesar_django`),
// }, {
// name: 'MATHESAR_DATABASES',
// value: pulumi.all([databaseInstance.publicIpAddress, cloudSqlPassword]).apply(([ip, password]) => `(postgres|postgresql://postgres:${password}@${ip}:5432/postgres)`),
// }, {
// name: 'ALLOWED_HOSTS',
// value: '*',
// }],
// }],
// },
// hosts: ['mathesar.bluedot.org'],
// },
// {
// name: 'bluedot-backend',
// targetPort: 8001,
// spec: {
// containers: [{
// name: 'bluedot-backend',
// image: 'sjc.vultrcr.com/bluedot/bluedot-backend:latest',
// env: [{
// name: 'DATABASE_CONNECTION_STRING',
// value: pulumi.all([databaseInstance.publicIpAddress, cloudSqlPassword]).apply(([ip, password]) => `postgresql://postgres:${password}@${ip}:5432/postgres?sslmode=no-verify`),
// }],
// }],
// },
// hosts: ['backend.bluedot.org'],
// },
{
name: 'bluedot-frontend-example',
targetPort: 8080,
Expand Down Expand Up @@ -82,6 +41,21 @@ export const services: ServiceDefinition[] = [
// ],
// },
// {
// name: 'bluedot-backend',
// targetPort: 8001,
// spec: {
// containers: [{
// name: 'bluedot-backend',
// image: 'sjc.vultrcr.com/bluedot/bluedot-backend:latest',
// env: [{
// name: 'DATABASE_CONNECTION_STRING',
// value: pulumi.all([databaseInstance.publicIpAddress, cloudSqlPassword]).apply(([ip, password]) => `postgresql://postgres:${password}@${ip}:5432/postgres?sslmode=no-verify`),
// }],
// }],
// },
// hosts: ['backend.bluedot.org'],
// },
// {
// name: 'keycloak',
// targetPort: 8080,
// spec: {
Expand Down
Loading

0 comments on commit 22ad1b9

Please sign in to comment.