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: remove template stuff and db connection #5

Merged
merged 12 commits into from
Apr 5, 2024
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
6 changes: 0 additions & 6 deletions .env

This file was deleted.

8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test/
dist/
*.js
*.d.ts
*.json
src/index.ts

src/proto
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@dcl/eslint-config/sdk",
"parserOptions": {
"project": ["tsconfig.json"]
},
"rules": {
"prettier/prettier": [
"error",
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"tabWidth": 2
}
]
}
}
21 changes: 16 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: npm
directory: '/'
schedule:
interval: weekly
day: monday
time: '10:00'
timezone: 'America/Buenos_Aires'
allow:
- dependency-name: '@dcl/*'
- dependency-name: '@catalyst/*'
- dependency-name: '@well-known-components/*'
- dependency-name: 'dcl-*'
- dependency-name: 'eth-connect'
versioning-strategy: auto
commit-message:
prefix: 'chore: '
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: build

on:
push:

jobs:
build:
uses: decentraland/platform-actions/.github/workflows/apps-with-db-build.yml@main
15 changes: 15 additions & 0 deletions .github/workflows/docker-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI/CD on main branch

on:
push:
branches:
- 'main'

jobs:
social-service-ea-deployment:
uses: decentraland/platform-actions/.github/workflows/apps-docker-next.yml@main
with:
service-name: social-service-ea
image-name: social-service-ea
deployment-environment: dev
secrets: inherit
15 changes: 15 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Publish 'latest' image

on:
release:
types:
- 'created'

jobs:
social-service-ea-deployment:
uses: decentraland/platform-actions/.github/workflows/apps-docker-release.yml@main
with:
service-name: social-service-ea
image-name: social-service-ea
deployment-environment: prd
secrets: inherit
57 changes: 0 additions & 57 deletions .github/workflows/docker.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/manual-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy

on:
workflow_dispatch:
inputs:
deployment-environment:
required: true
type: choice
options:
- dev
- prd
default: prd
description: Environment
tag:
required: true
default: 'latest'
type: string
description: 'Docker tag (quay.io)'

jobs:
deployment:
if: ${{ inputs.deployment-environment }}
name: 'Deploy to: ${{ inputs.deployment-environment }}'
runs-on: ubuntu-latest
environment: ${{ inputs.deployment-environment }}
steps:
- name: Trigger Quests Server deployment
id: deploy-server
uses: decentraland/dcl-deploy-action@main
with:
dockerImage: 'quay.io/decentraland/social-service-ea:${{ inputs.tag }}'
serviceName: 'social-service-ea'
env: ${{ inputs.deployment-environment }}
token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 0 additions & 21 deletions .github/workflows/node.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CI/CD on PR

on:
pull_request:

jobs:
pr:
uses: decentraland/platform-actions/.github/workflows/apps-pr.yml@main
with:
service-name: social-service-ea
secrets: inherit
9 changes: 9 additions & 0 deletions .github/workflows/validate-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: validate-pr-title

on:
pull_request:
types: [edited, opened, reopened, synchronize]

jobs:
title-matches-convention:
uses: decentraland/actions/.github/workflows/validate-pr-title.yml@main
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
node_modules/
**/.DS_Store
coverage
coverage
.env
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"name": "template-server",
"name": "social-service-ea",
"license": "Apache-2.0",
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node --trace-warnings --abort-on-uncaught-exception --unhandled-rejections=strict dist/index.js",
"test": "jest --forceExit --detectOpenHandles --coverage --verbose"
"test": "jest --forceExit --detectOpenHandles --coverage --verbose",
"migrate": "node-pg-migrate --database-url-var PG_COMPONENT_PSQL_CONNECTION_STRING --envPath .env -j ts --tsconfig tsconfig.json -m ./src/migrations",
"lint:check": "eslint '**/*.{js,ts}'",
"lint:fix": "eslint '**/*.{js,ts}' --fix"
},
"devDependencies": {
"@dcl/eslint-config": "^2.0.0",
"@types/node": "^20.11.28",
"@well-known-components/test-helpers": "^1.5.6",
"ts-node": "^10.9.2",
"typescript": "^5.4.2"
},
"prettier": {
Expand All @@ -22,6 +28,8 @@
"@well-known-components/http-server": "^2.1.0",
"@well-known-components/interfaces": "^1.4.3",
"@well-known-components/logger": "^3.1.3",
"@well-known-components/metrics": "^2.1.0"
"@well-known-components/metrics": "^2.1.0",
"@well-known-components/pg-component": "^0.2.2",
"@well-known-components/uws-http-server": "^0.0.1-20240314125425.commit-711dd8f"
}
}
1 change: 0 additions & 1 deletion src/adapters/README.md

This file was deleted.

7 changes: 7 additions & 0 deletions src/adapters/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AppComponents } from '../types'

export interface IDatabaseComponent {}

export function createDBComponent(_components: Pick<AppComponents, 'pg' | 'logs'>): IDatabaseComponent {
return {}
}
32 changes: 31 additions & 1 deletion src/components.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { resolve } from 'path'
import { createDotEnvConfigComponent } from '@well-known-components/env-config-provider'
import {
createServerComponent,
Expand All @@ -8,6 +9,8 @@ import { createLogComponent } from '@well-known-components/logger'
import { createMetricsComponent } from '@well-known-components/metrics'
import { AppComponents, GlobalContext } from './types'
import { metricDeclarations } from './metrics'
import { createPgComponent } from '@well-known-components/pg-component'
import { createDBComponent } from './adapters/db'

// Initialize all the components of the app
export async function initComponents(): Promise<AppComponents> {
Expand All @@ -17,13 +20,40 @@ export async function initComponents(): Promise<AppComponents> {
const server = await createServerComponent<GlobalContext>({ config, logs }, {})
const statusChecks = await createStatusCheckComponent({ server, config })

let databaseUrl: string | undefined = await config.getString('PG_COMPONENT_PSQL_CONNECTION_STRING')
if (!databaseUrl) {
const dbUser = await config.requireString('PG_COMPONENT_PSQL_USER')
const dbDatabaseName = await config.requireString('PG_COMPONENT_PSQL_DATABASE')
const dbPort = await config.requireString('PG_COMPONENT_PSQL_PORT')
const dbHost = await config.requireString('PG_COMPONENT_PSQL_HOST')
const dbPassword = await config.requireString('PG_COMPONENT_PSQL_PASSWORD')
databaseUrl = `postgres://${dbUser}:${dbPassword}@${dbHost}:${dbPort}/${dbDatabaseName}`
}

const pg = await createPgComponent(
{ logs, config, metrics },
{
migration: {
databaseUrl,
dir: resolve(__dirname, 'migrations'),
migrationsTable: 'pgmigrations',
ignorePattern: '.*\\.map',
direction: 'up'
}
}
)

const db = createDBComponent({ pg, logs })

await instrumentHttpServerWithPromClientRegistry({ metrics, server, config, registry: metrics.registry! })

return {
config,
logs,
server,
statusChecks,
metrics
metrics,
pg,
db
}
}
17 changes: 0 additions & 17 deletions src/controllers/handlers/ping-handler.ts

This file was deleted.

7 changes: 2 additions & 5 deletions src/controllers/routes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Router } from "@well-known-components/http-server"
import { GlobalContext } from "../types"
import { pingHandler } from "./handlers/ping-handler"
import { Router } from '@well-known-components/http-server'
import { GlobalContext } from '../types'

// We return the entire router because it will be easier to test than a whole server
export async function setupRouter(globalContext: GlobalContext): Promise<Router<GlobalContext>> {

Check warning on line 5 in src/controllers/routes.ts

View workflow job for this annotation

GitHub Actions / build / validations

'globalContext' is defined but never used. Allowed unused args must match /^_/u
const router = new Router<GlobalContext>()

router.get("/ping", pingHandler)

return router
}
1 change: 0 additions & 1 deletion src/logic/README.md

This file was deleted.

8 changes: 1 addition & 7 deletions src/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { IMetricsComponent } from '@well-known-components/interfaces'
import { validateMetricsDeclaration } from '@well-known-components/metrics'
import { getDefaultHttpMetrics } from '@well-known-components/http-server'
import { metricDeclarations as logsMetricsDeclarations } from '@well-known-components/logger'

export const metricDeclarations = {
...getDefaultHttpMetrics(),
...logsMetricsDeclarations,
test_ping_counter: {
help: 'Count calls to ping',
type: IMetricsComponent.CounterType,
labelNames: ['pathname']
}
...logsMetricsDeclarations
}

// type assertions
Expand Down
Loading
Loading