Skip to content

Commit

Permalink
Merge pull request #1 from TogetherCrew/project-config
Browse files Browse the repository at this point in the history
Project config
  • Loading branch information
cyri113 authored May 20, 2023
2 parents df49524 + b03ff8c commit d0f5157
Show file tree
Hide file tree
Showing 18 changed files with 7,710 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github/
coverage/
dist/
node_modules/

.env
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": ["standard-with-typescript", "prettier"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {},
"ignorePatterns": ["coverage", "dist"]
}
9 changes: 9 additions & 0 deletions .github/workflows/start.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Staging CI

on: pull_request

jobs:
ci:
uses: TogetherCrew/operations/.github/workflows/ci.yml@main
secrets:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage/
dist/
node_modules/

.env
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
coverage
node_modules
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:18-alpine AS base
WORKDIR /project
COPY . .
RUN npm ci

FROM base AS test
CMD [ "npx", "jest", "--coverage" ]

FROM base AS build
RUN npm run build

FROM build AS prod
RUN npm ci --omit=dev
CMD ["npm", "run", "start"]
EXPOSE 3000
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# typescript-service
The starting point template repository for developing typescript microservices. It provides a well-defined structure for building TypeScript-based applications and integrates into the organisations CI/CD workflows.

The starting point template repository for developing TypeScript microservices. It provides a well-defined structure for building TypeScript-based applications and integrates into the organisations CI/CD workflows.

[![Maintainability](https://api.codeclimate.com/v1/badges/7f1efd504c8530d6d5b7/maintainability)](https://codeclimate.com/github/TogetherCrew/typescript-service/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/7f1efd504c8530d6d5b7/test_coverage)](https://codeclimate.com/github/TogetherCrew/typescript-service/test_coverage)

## Features

### Linter

The CI Pipeline uses [super-linter](https://github.com/super-linter/super-linter). You can run it locally with the following command:

```bash
docker run -e RUN_LOCAL=true -e TYPESCRIPT_DEFAULT_STYLE=prettier -e VALIDATE_DOCKERFILE_HADOLINT=false -v $(pwd):/tmp/lint github/super-linter:slim-latest
```

Note: We have disabled HADOLINT for now as we are getting an error: `qemu: uncaught target signal 11 (Segmentation fault) - core dumped`.

### Tests

The CI Pipeline uses the `test` target from the Dockerfile to run the tests. You can run it locally with the following command:

```bash
docker compose -f docker-compose.test.yml up --exit-code-from app
```

Note: This will create a /coverage folder where you can review the coverage details.
10 changes: 10 additions & 0 deletions __test__/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import request from "supertest";
import app from "../src/app";

describe("GET /", () => {
it("should respond with 'Express + TypeScript Server'", async () => {
const response = await request(app).get("/");
expect(response.status).toBe(200);
expect(response.text).toBe("Express + TypeScript Server");
});
});
32 changes: 32 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.9"

services:
app:
build:
context: .
target: test
dockerfile: Dockerfile
environment:
- PORT=3000
- MONGODB_HOST=mongo
- MONGODB_PORT=27017
- MONGODB_USER=root
- MONGODB_PASS=pass
- REDIS_QUEUE_HOST=localhost
- REDIS_QUEUE_PORT=6379
volumes:
- ./coverage:/project/coverage
depends_on:
- redis
- mongo
redis:
image: "redis:alpine"
ports:
- 6379:6379
mongo:
image: "mongo"
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=pass
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
};
Loading

0 comments on commit d0f5157

Please sign in to comment.