Skip to content

Commit 309d14d

Browse files
committed
chore: add ci/cd
1 parent bea5528 commit 309d14d

File tree

14 files changed

+183
-102
lines changed

14 files changed

+183
-102
lines changed

.github/workflows/deploy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- 'Quality Check'
7+
branches:
8+
- main
9+
types:
10+
- completed
11+
workflow_dispatch:
12+
13+
jobs:
14+
deploy:
15+
name: Deploy
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
22+
- name: Install Node v16
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: 16
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v1
29+
30+
- name: Login to DockerHub
31+
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
- name: Build the images
34+
run: docker build -t chatsift/modmail:latest -f ./Dockerfile .
35+
36+
- name: Push to DockerHub
37+
run: docker push --all-tags chatsift/modmail

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ jobs:
44
quality:
55
name: Quality Check
66
runs-on: ubuntu-latest
7+
env:
8+
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
9+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
710
steps:
811
- name: Checkout repository
912
uses: actions/checkout@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ coverage/*
1111
!.yarn/sdks
1212
!.yarn/versions
1313
.pnp.*
14+
logs
1415

1516
.turbo

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/*
22
coverage/*
33
**/dist/*
44
.yarn/*
5+
.turbo

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM node:16-alpine
2+
LABEL name "modmail"
3+
4+
WORKDIR /usr/modmail
5+
6+
RUN apk add --update \
7+
&& apk add --no-cache ca-certificates \
8+
&& apk add --no-cache --virtual .build-deps curl git python3 alpine-sdk
9+
10+
COPY turbo.json package.json tsconfig.json yarn.lock .yarnrc.yml ./
11+
COPY .yarn ./.yarn
12+
13+
COPY packages/api/package.json ./packages/api/package.json
14+
COPY packages/bot/package.json ./packages/bot/package.json
15+
16+
RUN yarn --immutable
17+
18+
COPY prisma ./prisma
19+
RUN yarn prisma generate
20+
21+
COPY packages/api ./packages/api
22+
COPY packages/bot ./packages/bot
23+
24+
RUN yarn turbo run build
25+
26+
RUN yarn workspaces focus --all --production

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and if you plan on exposing it to the internet you'll also need an instance of t
1313
base ChatSift API, which can be found in the [dashboard repo](https://github.com/chatsift/dashboard).
1414
It only offers CRUD over configuration and basic data as it's mostly intended for our dashboard.
1515

16-
Our Docker images are pushed to DockerHub under the ChatSift org with the format `projectname_microservice`, e.g. `chatsift/modmail_bot`.
16+
A Docker image that can be used for running anything in this monorepo is available on DockerHub under `chatsift/modmail`.
1717

1818
---
1919

docker-compose.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@ services:
1818
timeout: 5s
1919

2020
bot:
21-
image: chatsift/modmail_bot
21+
image: chatsift/modmail
2222
build:
2323
context: ./
24-
dockerfile: ./packages/bot/Dockerfile
24+
dockerfile: ./Dockerfile
2525
env_file:
2626
- ./.env
2727
environment:
2828
DATABASE_URL: 'postgresql://modmail:admin@postgres:5432/modmail'
2929
restart: unless-stopped
30+
volumes:
31+
- ./logs:/usr/modmail/logs
3032
depends_on:
3133
- postgres
34+
command:
35+
[
36+
'node',
37+
'--es-module-specifier-resolution=node',
38+
'--enable-source-maps',
39+
'--no-warnings',
40+
'./packages/bot/dist/index.js',
41+
]
3242

3343
volumes:
3444
postgres-data:

packages/api/Dockerfile

Lines changed: 0 additions & 39 deletions
This file was deleted.

packages/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"typescript": "^4.7.4"
2323
},
2424
"dependencies": {
25+
"@chatsift/pino-rotate-file": "^0.1.2",
2526
"@chatsift/readdir": "^0.2.0",
2627
"@chatsift/rest-utils": "^0.6.0",
2728
"@hapi/boom": "^10.0.0",

packages/api/src/util/logger.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
1-
import createLogger from 'pino';
1+
import { join } from 'node:path';
2+
import type { PinoRotateFileOptions } from '@chatsift/pino-rotate-file';
3+
import createLogger, { multistream, transport } from 'pino';
4+
import type { PrettyOptions } from 'pino-pretty';
25

3-
export const logger = createLogger({
4-
transport: {
5-
target: 'pino-pretty',
6-
options: {
7-
colorize: true,
8-
levelFirst: true,
9-
translateTime: true,
10-
},
6+
const pinoPrettyOptions: PrettyOptions = {
7+
colorize: true,
8+
levelFirst: true,
9+
translateTime: true,
10+
};
11+
12+
const pinoRotateFileOptions: PinoRotateFileOptions = {
13+
dir: join(process.cwd(), 'logs', 'bot'),
14+
mkdir: true,
15+
maxAgeDays: 14,
16+
prettyOptions: {
17+
...pinoPrettyOptions,
18+
colorize: false,
19+
},
20+
};
21+
22+
export const logger = createLogger(
23+
{
24+
name: 'API',
25+
level: 'trace',
1126
},
12-
});
27+
multistream([
28+
{
29+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
30+
stream: transport({
31+
target: 'pino-pretty',
32+
options: pinoPrettyOptions,
33+
}),
34+
level: 'trace',
35+
},
36+
{
37+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
38+
stream: transport({
39+
target: '@chatsift/pino-rotate-file',
40+
options: pinoRotateFileOptions,
41+
}),
42+
level: 'trace',
43+
},
44+
]),
45+
);

0 commit comments

Comments
 (0)