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

[RELEASE] Utltimate Ulmus #32

Merged
merged 75 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
820c578
[TM-1494] Only beef up the research service in staging and prod.
roguenet Nov 27, 2024
ee97093
[TM-1536] add total_content and proccessed_content field to delayedJo…
LimberHope Dec 2, 2024
e6a0643
Merge branch 'staging' into TM-1536_delayed_job_progress
LimberHope Dec 2, 2024
4203aeb
[TM-1536] add proccess message field
LimberHope Dec 2, 2024
8efb6d9
changes
LimberHope Dec 2, 2024
5371fac
[TM-1536] add import to delayed job
LimberHope Dec 2, 2024
8024d34
[TM-1536] add column type
LimberHope Dec 2, 2024
1ef94ed
fix test
LimberHope Dec 2, 2024
c09f01a
test
LimberHope Dec 2, 2024
210ab14
fix
LimberHope Dec 2, 2024
d24ee38
Merge pull request #20 from wri/TM-1536_delayed_job_progress
LimberHope Dec 2, 2024
a842f21
Merge pull request #19 from wri/task/TM-1494-gateway-internal-ec2
roguenet Dec 2, 2024
f52c0bd
[TM-1536] remove constructor
LimberHope Dec 2, 2024
e89f1cf
Merge pull request #21 from wri/TM-1536_delayed_job_progress
roguenet Dec 2, 2024
178857a
Merge pull request #22 from wri/main
roguenet Dec 2, 2024
1ecf67c
[TM-1519] Enable a pattern to control which services are deployed in …
roguenet Dec 2, 2024
dc657d9
[TM-1519] Only try to proxy the services that are enabled in this env.
roguenet Dec 2, 2024
f8cce3c
[TM-1519] Set up the new unified database service skeleton
roguenet Dec 2, 2024
0100296
[TM-1519] POC connecting to Redis with BullMQ
roguenet Dec 3, 2024
3fa39e2
[TM-1519] Set up processing of queue jobs.
roguenet Dec 3, 2024
abb5f3f
[TM-1519] POC updating a single record in Airtable.
roguenet Dec 3, 2024
016507b
[TM-1519] Restructure a bit to make this column mapping a bit more sane.
roguenet Dec 3, 2024
794c045
[TM-1519] Flesh out the project entity record.
roguenet Dec 3, 2024
e1968ff
[TM-1519] POC project updates ready for review.
roguenet Dec 4, 2024
bc459b5
Merge pull request #23 from wri/feat/TM-1519-unified-database-service
roguenet Dec 4, 2024
ed64464
[TM-1401] Set up new entity service.
roguenet Dec 4, 2024
db6956d
[TM-1401] Set up the tree species research table.
roguenet Dec 4, 2024
7d898ac
[TM-1401] Create the scientific names search endpoint.
roguenet Dec 4, 2024
5ea4ea2
[TM-1401] Regenerate package-lock.json
roguenet Dec 4, 2024
b7bd679
[TM-1401] Small cleanup pass
roguenet Dec 5, 2024
acd04e8
[TM-1401] Don't pretend this is returning the full tree species model.
roguenet Dec 5, 2024
e4ae654
[TM-1401] Specs for the entity service.
roguenet Dec 5, 2024
fe93eed
[TM-1401] Ensure the data object in this endpoint is always an array.
roguenet Dec 5, 2024
5a2404d
[TM-1401] Move this factory to the index.
roguenet Dec 5, 2024
47360f9
[TM-1531] add id to attributes in user me
egrojMonroy Dec 6, 2024
f9fb6ca
[TM-1531] add get running jobs
egrojMonroy Dec 6, 2024
aa75793
Merge pull request #24 from wri/feat/TM-1401-cleaned-tree-species
roguenet Dec 6, 2024
7662f54
[TM-1531] remove name of index point
egrojMonroy Dec 6, 2024
1146d16
[TM-1531] update properties for delayed jobs table
cesarLima1 Dec 6, 2024
e274138
Merge branch 'feat/TM-1531-delayed-job-with-data' of https://github.c…
cesarLima1 Dec 6, 2024
c5005ff
[TM-1531] change attribute name to progress message
cesarLima1 Dec 6, 2024
529c4cd
[TM-1531] improve spelling
cesarLima1 Dec 9, 2024
3974e3c
[TM-1531] add unit tests for getRunningJobs functionality
cesarLima1 Dec 9, 2024
389299d
[TM-1531] remove useless code, id in user, and rollback comment
egrojMonroy Dec 9, 2024
d9ba351
[TM-1531] add clear endpoint
egrojMonroy Dec 9, 2024
2632170
[TM-1531] fix unit test
egrojMonroy Dec 9, 2024
2a1a911
[TM-1531] change to isAcknowledged
egrojMonroy Dec 10, 2024
ed8a7ff
[TM-1531] update attrib to delayed job, change tests and update jobs …
egrojMonroy Dec 10, 2024
b2a2f95
[TM-1402] Update the tree_species_research table.
roguenet Dec 10, 2024
f898f22
[TM-1531] some changes for dtos
egrojMonroy Dec 11, 2024
0b83383
[TM-1531] more unit tests
egrojMonroy Dec 11, 2024
0385b02
[TM-1531] removing useless code and test
egrojMonroy Dec 11, 2024
5274082
[TM-1531] cover all code in tes
egrojMonroy Dec 11, 2024
e68e41f
[TM-1402] Initial POC of getting entity establishment trees.
roguenet Dec 11, 2024
7d817c3
[TM-1402] Support nursery reports in establishment tree species.
roguenet Dec 12, 2024
0b5c03c
[TM-1402] Full support for establishment species.
roguenet Dec 12, 2024
50f7ede
[TM-1531] rename to bulk update
egrojMonroy Dec 12, 2024
a9ed70a
[TM-1531] add lint and reduce queries
egrojMonroy Dec 12, 2024
611ff8d
Merge pull request #25 from wri/feat/TM-1531-delayed-job-with-data
egrojMonroy Dec 12, 2024
8d59c53
[TM-1402] Implemented previous planting counts.
roguenet Dec 12, 2024
a5ba2ee
[TM-1402] Avoid constraints on polymorphic association.
roguenet Dec 12, 2024
a694b17
[TM-1402] tree controller coverage complete.
roguenet Dec 12, 2024
715ab5f
[TM-1402] tree service coverage complete.
roguenet Dec 13, 2024
49123e2
Merge pull request #26 from wri/feat/TM-1402-tree-species-design-inte…
roguenet Dec 13, 2024
d16ce65
[TM-1398] Merge remote-tracking branch 'origin/staging' into epic/TM-…
roguenet Dec 13, 2024
531c13e
Merge pull request #27 from wri/epic/TM-1398-tree-species
roguenet Dec 13, 2024
0bee62d
[TM-1526] Integrate Sentry reporting.
roguenet Dec 13, 2024
88bb5b5
[TM-1531] add uuid to delayed dto
egrojMonroy Dec 16, 2024
88b9de9
[TM-1402] Include taxonId in the previous planting count payload.
roguenet Dec 16, 2024
85705f2
[TM-1402] Fix reference name.
roguenet Dec 16, 2024
56253c7
Merge pull request #29 from wri/feat/TM-1531-add-uuid-to-delayed-dto
egrojMonroy Dec 17, 2024
a413afb
Merge pull request #30 from wri/feat/TM-1402-prepopulate-tree-rows
roguenet Dec 17, 2024
75566cc
Merge pull request #28 from wri/feat/TM-1526-sentry
roguenet Dec 17, 2024
595fda1
[TM-1581] Make tree related endpoints collection aware.
roguenet Dec 19, 2024
0c89622
Merge pull request #33 from wri/fix/TM-1581-tree-collections
roguenet Dec 19, 2024
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
8 changes: 8 additions & 0 deletions .env.local.sample
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
USER_SERVICE_PORT=4010
JOB_SERVICE_PORT=4020
RESEARCH_SERVICE_PORT=4030
UNIFIED_DATABASE_SERVICE_PORT=4040
ENTITY_SERVICE_PORT=4050

DB_HOST=localhost
DB_PORT=3360
DB_DATABASE=wri_restoration_marketplace_api
DB_USERNAME=wri
DB_PASSWORD=wri

REDIS_HOST=localhost
REDIS_PORT=6379

JWT_SECRET=qu3sep4GKdbg6PiVPCKLKljHukXALorq6nLHDBOCSwvs6BrgE6zb8gPmZfrNspKt

# Only needed for the unified database service. Most developers should not have this defined.
AIRTABLE_API_KEY
1 change: 1 addition & 0 deletions .github/workflows/deploy-api-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ env:
AWS_ROLE_TO_ASSUME: arn:aws:iam::603634817705:role/terramatch-microservices-github-actions
AWS_ROLE_SESSION_NAME: terramatch-microservices-cicd-api-gateway
PHP_PROXY_TARGET: ${{ vars.PHP_PROXY_TARGET }}
ENABLED_SERVICES: ${{ vars.ENABLED_SERVICES }}

jobs:
deploy-api-gateway:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/deploy-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ on:
required: true
options:
- job-service
- research-service
- user-service
- entity-service
- research-service
- unified-database-service
env:
description: 'Deployment target environment'
type: choice
Expand Down Expand Up @@ -69,7 +71,7 @@ jobs:
: # Don't build the base image with NODE_ENV because it'll limit the packages that are installed
docker build -t terramatch-microservices-base:nx-base .
SERVICE_IMAGE=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker build --build-arg NODE_ENV=production --build-arg BUILD_FLAG=--prod -f apps/${{ inputs.service }}/Dockerfile -t $SERVICE_IMAGE .
docker build --build-arg NODE_ENV=production --build-arg BUILD_FLAG='--prod --verbose' -f apps/${{ inputs.service }}/Dockerfile -t $SERVICE_IMAGE .
docker push $SERVICE_IMAGE
echo "image=$SERVICE_IMAGE"

Expand Down
42 changes: 41 additions & 1 deletion .github/workflows/deploy-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,65 @@ permissions:
contents: read

jobs:
check-services:
runs-on: ubuntu-latest
environment: ${{ inputs.env }}
outputs:
job-service-enabled: ${{ steps.check-services.outputs.job }}
user-service-enabled: ${{ steps.check-services.outputs.user }}
entity-service-enabled: ${{ steps.check-services.outputs.entity }}
research-service-enabled: ${{ steps.check-services.outputs.research }}
unified-database-service-enabled: ${{ steps.check-services.outputs.unified-database }}
steps:
- id: check-services
run: |
echo "job=${{ vars.ENABLED_SERVICES == '' || contains(vars.ENABLED_SERVICES, 'job-service') }}" >> "$GITHUB_OUTPUT"
echo "user=${{ vars.ENABLED_SERVICES == '' || contains(vars.ENABLED_SERVICES, 'user-service') }}" >> "$GITHUB_OUTPUT"
echo "entity=${{ vars.ENABLED_SERVICES == '' || contains(vars.ENABLED_SERVICES, 'entity-service') }}" >> "$GITHUB_OUTPUT"
echo "research=${{ vars.ENABLED_SERVICES == '' || contains(vars.ENABLED_SERVICES, 'research-service') }}" >> "$GITHUB_OUTPUT"
echo "unified-database=${{ vars.ENABLED_SERVICES == '' || contains(vars.ENABLED_SERVICES, 'unified-database-service') }}" >> "$GITHUB_OUTPUT"

job-service:
needs: check-services
if: needs.check-services.outputs.job-service-enabled == 'true'
uses: ./.github/workflows/deploy-service.yml
with:
env: ${{ inputs.env }}
service: job-service
secrets: inherit

user-service:
needs: check-services
if: needs.check-services.outputs.user-service-enabled == 'true'
uses: ./.github/workflows/deploy-service.yml
with:
env: ${{ inputs.env }}
service: user-service
secrets: inherit

entity-service:
needs: check-services
if: needs.check-services.outputs.entity-service-enabled == 'true'
uses: ./.github/workflows/deploy-service.yml
with:
env: ${{ inputs.env }}
service: entity-service
secrets: inherit

research-service:
needs: check-services
if: needs.check-services.outputs.research-service-enabled == 'true'
uses: ./.github/workflows/deploy-service.yml
with:
env: ${{ inputs.env }}
service: research-service
secrets: inherit


unified-database-service:
needs: check-services
if: needs.check-services.outputs.unified-database-service-enabled == 'true'
uses: ./.github/workflows/deploy-service.yml
with:
env: ${{ inputs.env }}
service: unified-database-service
secrets: inherit
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ and main branches.
* Set up the new `main.ts` similarly to existing services.
* Make sure swagger docs and the `/health` endpoint are implemented
* Pick a default local port that is unique from other services
* Make sure the top of `main.ts` has these two lines:
```
// eslint-disable-next-line @nx/enforce-module-boundaries
import "../../../instrument-sentry";
```
* Add the `SentryModule` and `SentryGlobalFilter` to your main `app.module.ts`. See an existing service for an example.
* In your `.env` and `.env.local.sample`, add `_PORT` for the new service
* In `api-gateway-stack.ts`, add the new service and namespace to `V3_SERVICES`
* In your local web repo, follow directions in `README.md` for setting up a new service.
* This step can be skipped for services that will not be used by the FE website.
* For deployment to AWS:
* Add a Dockerfile in the new app directory. A simple copy and modify from user-service is sufficient
* Add the new service name to the "service" workflow input options in `deploy-service.yml`
* Add a new job to `deploy-services.yml` to include the new services in the "all" service deployment workflow.
* Make sure to update the `check-services` step and follow the pattern for the `if` conditions on the individual service deploy jobs.
* In AWS:
* Add ECR repositories for each env (follow the naming scheme from user-service, e.g. `terramatch-microservices/foo-service-staging`, etc)
* Set the repo to Immutable
Expand Down
18 changes: 18 additions & 0 deletions apps/entity-service-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
19 changes: 19 additions & 0 deletions apps/entity-service-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */
export default {
displayName: "entity-service-e2e",
preset: "../../jest.preset.js",
globalSetup: "<rootDir>/src/support/global-setup.ts",
globalTeardown: "<rootDir>/src/support/global-teardown.ts",
setupFiles: ["<rootDir>/src/support/test-setup.ts"],
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": [
"ts-jest",
{
tsconfig: "<rootDir>/tsconfig.spec.json"
}
]
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/entity-service-e2e"
};
17 changes: 17 additions & 0 deletions apps/entity-service-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "entity-service-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": ["entity-service"],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"jestConfig": "apps/entity-service-e2e/jest.config.ts",
"passWithNoTests": true
},
"dependsOn": ["entity-service:build"]
}
}
}
10 changes: 10 additions & 0 deletions apps/entity-service-e2e/src/entity-service/entity-service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from "axios";

describe("GET /api", () => {
it("should return a message", async () => {
const res = await axios.get(`/api`);

expect(res.status).toBe(200);
expect(res.data).toEqual({ message: "Hello API" });
});
});
10 changes: 10 additions & 0 deletions apps/entity-service-e2e/src/support/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
var __TEARDOWN_MESSAGE__: string;

module.exports = async function () {
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
console.log("\nSetting up...\n");

// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = "\nTearing down...\n";
};
7 changes: 7 additions & 0 deletions apps/entity-service-e2e/src/support/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */

module.exports = async function () {
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
// Hint: `globalThis` is shared between setup and teardown.
console.log(globalThis.__TEARDOWN_MESSAGE__);
};
10 changes: 10 additions & 0 deletions apps/entity-service-e2e/src/support/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */

import axios from "axios";

module.exports = async function () {
// Configure axios for tests to use.
const host = process.env.HOST ?? "localhost";
const port = process.env.PORT ?? "3000";
axios.defaults.baseURL = `http://${host}:${port}`;
};
13 changes: 13 additions & 0 deletions apps/entity-service-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions apps/entity-service-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
18 changes: 18 additions & 0 deletions apps/entity-service/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
15 changes: 15 additions & 0 deletions apps/entity-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM terramatch-microservices-base:nx-base AS builder

ARG BUILD_FLAG
WORKDIR /app/builder
COPY . .
RUN npx nx build entity-service ${BUILD_FLAG}

FROM terramatch-microservices-base:nx-base

ARG NODE_ENV
WORKDIR /app
COPY --from=builder /app/builder ./
ENV NODE_ENV=${NODE_ENV}

CMD ["node", "./dist/apps/entity-service/main.js"]
11 changes: 11 additions & 0 deletions apps/entity-service/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: "entity-service",
preset: "../../jest.preset.js",
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }]
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/apps/entity-service"
};
26 changes: 26 additions & 0 deletions apps/entity-service/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "entity-service",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/entity-service/src",
"projectType": "application",
"tags": [],
"targets": {
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"dependsOn": ["build"],
"options": {
"buildTarget": "entity-service:build",
"runBuildTargetDependencies": false
},
"configurations": {
"development": {
"buildTarget": "entity-service:build:development"
},
"production": {
"buildTarget": "entity-service:build:production"
}
}
}
}
}
21 changes: 21 additions & 0 deletions apps/entity-service/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Module } from "@nestjs/common";
import { DatabaseModule } from "@terramatch-microservices/database";
import { CommonModule } from "@terramatch-microservices/common";
import { HealthModule } from "./health/health.module";
import { TreesController } from "./trees/trees.controller";
import { TreeService } from "./trees/tree.service";
import { SentryGlobalFilter, SentryModule } from "@sentry/nestjs/setup";
import { APP_FILTER } from "@nestjs/core";

@Module({
imports: [SentryModule.forRoot(), DatabaseModule, CommonModule, HealthModule],
controllers: [TreesController],
providers: [
{
provide: APP_FILTER,
useClass: SentryGlobalFilter
},
TreeService
]
})
export class AppModule {}
Empty file.
28 changes: 28 additions & 0 deletions apps/entity-service/src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Controller, Get } from '@nestjs/common';
import { HealthCheck, HealthCheckService, SequelizeHealthIndicator } from '@nestjs/terminus';
import { NoBearerAuth } from '@terramatch-microservices/common/guards';
import { ApiExcludeController } from '@nestjs/swagger';
import { User } from '@terramatch-microservices/database/entities';

@Controller('health')
@ApiExcludeController()
export class HealthController {
constructor(
private readonly health: HealthCheckService,
private readonly db: SequelizeHealthIndicator
) {}

@Get()
@HealthCheck()
@NoBearerAuth
async check() {
const connection = await User.sequelize.connectionManager.getConnection({ type: 'read' });
try {
return this.health.check([
() => this.db.pingCheck('database', { connection })
]);
} finally {
User.sequelize.connectionManager.releaseConnection(connection);
}
}
}
9 changes: 9 additions & 0 deletions apps/entity-service/src/health/health.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus';
import { HealthController } from './health.controller';

@Module({
imports: [TerminusModule],
controllers: [HealthController],
})
export class HealthModule {}
Loading
Loading