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

feat(agora): migrate Agora to spec-first development workflow #2767

Merged
Merged
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"onAutoForward": "silent"
},
"3333": {
"label": "agora-server",
"label": "agora-api",
"onAutoForward": "silent"
},
"4200": {
Expand Down
6 changes: 6 additions & 0 deletions apps/agora/apex/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
API_DOCS_HOST=agora-api-docs
API_DOCS_PORT=8010
API_HOST=agora-api
API_PORT=3333
APP_HOST=agora-app
APP_PORT=4200
14 changes: 14 additions & 0 deletions apps/agora/apex/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:80 {
handle_path /api-docs* {
reverse_proxy {env.API_DOCS_HOST}:{env.API_DOCS_PORT}
}

# Serve the API, stripping the /api prefix
handle_path /api/* {
reverse_proxy {env.API_HOST}:{env.API_PORT}
}

handle {
reverse_proxy {env.APP_HOST}:{env.APP_PORT}
}
}
1 change: 1 addition & 0 deletions apps/agora/apex/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM caddy:2.8.4
68 changes: 68 additions & 0 deletions apps/agora/apex/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "agora-apex",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"targets": {
"create-config": {
"executor": "nx:run-commands",
"options": {
"command": "cp -n .env.example .env",
"cwd": "{projectRoot}"
}
},
"serve-detach": {
"executor": "nx:run-commands",
"options": {
"command": "docker/agora/serve-detach.sh agora-apex"
}
},
"build-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": "apps/agora/apex",
"metadata": {
"images": [
"ghcr.io/sage-bionetworks/agora-apex"
],
"tags": [
"type=edge,branch=main",
"type=raw,value=local",
"type=sha"
]
},
"push": false
}
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": "apps/agora/apex",
"metadata": {
"images": [
"ghcr.io/sage-bionetworks/agora-apex"
],
"tags": [
"type=edge,branch=main",
"type=sha"
]
},
"push": true
},
"dependsOn": [
"build-image"
]
},
"scan-image": {
"executor": "nx:run-commands",
"options": {
"command": "trivy image ghcr.io/sage-bionetworks/agora-apex:local --quiet",
"color": true
}
}
},
"tags": [
"type:service",
"scope:backend"
],
"implicitDependencies": []
}
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions apps/agora/server/Dockerfile → apps/agora/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ ENV APP_DIR=/app
RUN apk add --no-cache curl jq su-exec

WORKDIR /
COPY apps/agora/server/docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh
COPY apps/agora/api/docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh

WORKDIR ${APP_DIR}
COPY dist/apps/agora/server ${APP_DIR}
COPY dist/apps/agora/api ${APP_DIR}
RUN npm install

HEALTHCHECK --interval=2s --timeout=3s --retries=20 --start-period=5s \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable */
export default {
displayName: 'agora-server',
displayName: 'agora-api',
preset: '../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/apps/agora/server',
coverageDirectory: '../../../coverage/apps/agora/api',
};
65 changes: 43 additions & 22 deletions apps/agora/server/project.json → apps/agora/api/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "agora-server",
"name": "agora-api",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/agora/server/src",
"sourceRoot": "apps/agora/api/src",
"projectType": "application",
"targets": {
"create-config": {
Expand All @@ -13,16 +13,20 @@
},
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"outputs": [
"{options.outputPath}"
],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/agora/server",
"main": "apps/agora/server/src/main.ts",
"tsConfig": "apps/agora/server/tsconfig.app.json",
"assets": ["apps/agora/server/src/assets"],
"webpackConfig": "apps/agora/server/webpack.config.js",
"outputPath": "dist/apps/agora/api",
"main": "apps/agora/api/src/main.ts",
"tsConfig": "apps/agora/api/tsconfig.app.json",
"assets": [
"apps/agora/api/src/assets"
],
"webpackConfig": "apps/agora/api/webpack.config.js",
"generatePackageJson": true
},
"configurations": {
Expand All @@ -34,21 +38,21 @@
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "agora-server:build"
"buildTarget": "agora-api:build"
},
"configurations": {
"development": {
"buildTarget": "agora-server:build:development"
"buildTarget": "agora-api:build:development"
},
"production": {
"buildTarget": "agora-server:build:production"
"buildTarget": "agora-api:build:production"
}
}
},
"serve-detach": {
"executor": "nx:run-commands",
"options": {
"command": "docker/agora/serve-detach.sh agora-server"
"command": "docker/agora/serve-detach.sh agora-api"
}
},
"lint": {
Expand All @@ -65,39 +69,56 @@
"options": {
"context": ".",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/agora-server"],
"tags": ["type=edge,branch=main", "type=raw,value=local", "type=sha"]
"images": [
"ghcr.io/sage-bionetworks/agora-api"
],
"tags": [
"type=edge,branch=main",
"type=raw,value=local",
"type=sha"
]
},
"push": false
},
"dependsOn": ["build"]
"dependsOn": [
"build"
]
},
"publish-image": {
"executor": "@nx-tools/nx-container:build",
"options": {
"context": ".",
"metadata": {
"images": ["ghcr.io/sage-bionetworks/agora-server"],
"tags": ["type=edge,branch=main", "type=sha"]
"images": [
"ghcr.io/sage-bionetworks/agora-api"
],
"tags": [
"type=edge,branch=main",
"type=sha"
]
},
"push": true
},
"dependsOn": ["build-image"]
"dependsOn": [
"build-image"
]
},
"scan-image": {
"executor": "nx:run-commands",
"options": {
"command": "trivy image ghcr.io/sage-bionetworks/agora-server:local --quiet",
"command": "trivy image ghcr.io/sage-bionetworks/agora-api:local --quiet",
"color": true
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}"
],
"options": {
"jestConfig": "apps/agora/server/jest.config.ts"
"jestConfig": "apps/agora/api/jest.config.ts"
}
}
},
"tags": []
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import api from './api';
const app = express();

app.use('/assets', express.static(path.join(__dirname, 'assets')));
app.use('/api', api);
app.use('/v1', api);

// Health endpoint used by the container
app.get('/health', (_req, res) => res.status(200).json({ status: 'UP' }));

const port = process.env.PORT ?? 3333;
const server = app.listen(port, () => {
console.log(`Listening at http://localhost:${port}/api`);
console.log(`Listening at http://localhost:${port}`);
});
server.on('error', console.error);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataVersion } from '@sagebionetworks/agora/api-client-angular';
import { Dataversion } from '@sagebionetworks/agora/api-client-angular';
import { Schema, model } from 'mongoose';

const DataVersionSchema = new Schema<DataVersion>(
const DataVersionSchema = new Schema<Dataversion>(
{
data_file: { type: String, required: true },
data_version: { type: String, required: true },
Expand All @@ -12,7 +12,7 @@ const DataVersionSchema = new Schema<DataVersion>(
},
);

export const DataVersionCollection = model<DataVersion>(
export const DataVersionCollection = model<Dataversion>(
'DataVersionCollection',
DataVersionSchema,
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"compilerOptions": {
"esModuleInterop": true
}
}
}
7 changes: 7 additions & 0 deletions apps/agora/app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
API_DOCS_URL="http://localhost:8000/api-docs"
APP_VERSION="1.0.0-alpha"
CSR_API_URL="http://localhost:8000/api/v1"
DATA_UPDATED_ON="2023-09-26"
ENVIRONMENT="production"
GOOGLE_TAG_MANAGER_ID=""
SSR_API_URL="http://agora-api:8000/api/v1"
4 changes: 2 additions & 2 deletions apps/agora/app/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"error",
{
"type": "attribute",
"prefix": "agora",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "agora",
"prefix": "app",
"style": "kebab-case"
}
]
Expand Down
4 changes: 2 additions & 2 deletions apps/agora/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ COPY dist/apps/agora/app/browser/server ${APP_DIR}
COPY dist/apps/agora/app/browser/browser ${APP_DIR}/dist/apps/agora/app/browser/browser

HEALTHCHECK --interval=2s --timeout=3s --retries=20 --start-period=5s \
CMD curl --fail --silent "localhost:5200/health" | jq '.status' | grep UP || exit 1
CMD curl --fail --silent "localhost:4200/health" | jq '.status' | grep UP || exit 1

EXPOSE 5200
EXPOSE 4200

ENTRYPOINT ["/docker-entrypoint.sh"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh

# cd "${APP_DIR}/dist/apps/agora/app/browser/browser/config"
# envsubst < config.json.template > config.json
cd "${APP_DIR}/dist/apps/agora/app/browser/browser/config"
envsubst < config.json.template > config.json
2 changes: 1 addition & 1 deletion apps/agora/app/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env sh
set -e

# /docker-entrypoint.d/10-envsubst-on-app-config-template.sh
/docker-entrypoint.d/10-envsubst-on-app-config-template.sh

if [ "$1" = 'node' ]; then
cd ${APP_DIR}
Expand Down
Loading
Loading