-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73ae101
commit 9241baf
Showing
35 changed files
with
5,615 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules | ||
.github/ | ||
.git/ | ||
.gitignore | ||
Dockerfile | ||
Makefile | ||
README* | ||
*.code-workspace | ||
.gitlab-ci.yml | ||
ops/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NODE_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.git | ||
.editorconfig | ||
.idea | ||
.npmrc | ||
*.crt | ||
*.key | ||
*.pem | ||
npm-debug.log | ||
.env | ||
backup/* | ||
coverage | ||
dist/* | ||
devops/version/ | ||
!dist/.gitkeep | ||
logs/* | ||
node_modules/ | ||
devops/version/ | ||
tmp | ||
|
||
cdktf.out | ||
cdktf.log | ||
*terraform.*.tfstate* | ||
.gen | ||
.terraform | ||
tsconfig.tsbuildinfo | ||
!jest.config.js | ||
!setup.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v22.3 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
arrowParens: 'avoid', | ||
bracketSpacing: true, | ||
plugins: [ | ||
'prettier-plugin-organize-imports', | ||
], | ||
printWidth: 90, | ||
singleQuote: true, | ||
semi: true, | ||
tabWidth: 2, | ||
trailingComma: 'all', | ||
useTabs: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.sortImports": "explicit", | ||
"source.fixAll": "explicit" | ||
}, | ||
"eslint.enable": true, | ||
"eslint.format.enable": true, | ||
"eslint.options": { | ||
"overrideConfigFile": "./eslint.config.js" | ||
}, | ||
"eslint.run": "onType", | ||
"eslint.useFlatConfig": true, | ||
"eslint.validate": ["typescript"], | ||
"prettier.configPath": "./.prettierrc.js", | ||
"prettier.requireConfig": true, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#--- BASE --- | ||
FROM tuiteraz/jaba-node:22.3-0 AS base | ||
# default workdir = /usr/src/app | ||
ENV TZ=Europe/Madrid | ||
COPY ./scripts/entrypoint.sh /usr/local/bin/entrypoint.sh | ||
RUN chmod +x /usr/local/bin/entrypoint.sh | ||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] | ||
CMD ["node", "--enable-source-maps", "dist/src/index.js"] | ||
|
||
#--- BUILD --- | ||
FROM tuiteraz/jaba-build:22.3-0 AS build | ||
WORKDIR /tmp | ||
|
||
COPY . . | ||
RUN corepack enable pnpm && corepack install -g pnpm | ||
RUN pnpm install | ||
RUN pnpm build | ||
|
||
#--- FINAL--- | ||
FROM base AS final | ||
ARG IMAGE_VERSION | ||
ARG IMAGE_NAME | ||
ENV IMAGE_VERSION=$IMAGE_VERSION | ||
ENV IMAGE_NAME=$IMAGE_NAME | ||
|
||
COPY --from=build /tmp/dist ./dist | ||
RUN corepack enable pnpm && corepack install -g pnpm | ||
COPY package.json . | ||
COPY pnpm-lock.yaml . | ||
RUN pnpm i --prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
SHELL=/bin/bash | ||
RED=\033[0;31m | ||
GREEN=\033[0;32m | ||
BG_GREY=\033[48;5;237m | ||
YELLOW=\033[38;5;202m | ||
BOLD_ON=\033[1m | ||
BOLD_OFF=\033[21m | ||
NC=\033[0m # No Color | ||
|
||
ifneq (,$(wildcard ./.env)) | ||
include ./.env | ||
endif | ||
|
||
IMAGE_VERSION := $(shell jq -r '.version' package.json) | ||
IMAGE_NAME := $(shell jq -r '.name' package.json) | ||
|
||
.PHONY: help | ||
|
||
help: | ||
@echo Automation commands: | ||
@echo | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
check-node-env: | ||
ifndef NODE_ENV | ||
@printf "${YELLOW}NODE_ENV not provided. Using ${BOLD_ON}'NODE_ENV=development'${BOLD_OFF} as default${NC}\n" | ||
export NODE_ENV = development | ||
endif | ||
|
||
docker-build: check-node-env ## build docker image | ||
docker build --load -f ./Dockerfile --build-arg IMAGE_VERSION=$(IMAGE_VERSION) --build-arg IMAGE_NAME=$(IMAGE_NAME) -t $(IMAGE_NAME):$(IMAGE_VERSION) . | ||
|
||
docker-run: check-node-env ## build docker image | ||
docker run --rm -p 9000:9000 $(IMAGE_NAME):$(IMAGE_VERSION) | ||
|
||
logs-restart: ## restart logs stack | ||
@docker compose -f ./ops/grafana-logs/docker-compose.logs.yaml down | ||
@docker compose -f ./ops/grafana-logs/docker-compose.logs.yaml up -d | ||
|
||
logs-stop: ## stop logs stack | ||
@docker compose -f ./ops/grafana-logs/docker-compose.logs.yaml down | ||
|
||
logs-logs: ## display logs from logs stack | ||
@docker compose -f ./ops/grafana-logs/docker-compose.logs.yaml logs -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# fastify-tmpl | ||
# fastify-tmpl | ||
|
||
Fastify API service barebone template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"runtime": { | ||
"environment": "NODE_ENV" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"deployment": { | ||
"containerName": "fastify-tmpl", | ||
"imageName": "tuiteraz/fastify-tmpl" | ||
}, | ||
"runtime": { | ||
"environment": "development", | ||
"logLevel": "debug", | ||
"port": 9000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"runtime": { | ||
"logLevel": "info" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"runtime": { | ||
"logLevel": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const globals = require('globals'); | ||
const eslint = require('@eslint/js'); | ||
const tseslint = require('typescript-eslint'); | ||
const eslintPrettier = require('eslint-plugin-prettier'); | ||
|
||
module.exports = tseslint.config( | ||
{ | ||
ignores: [ | ||
'**/dist/**', | ||
'**/node_modules/**', | ||
'**/coverage/**', | ||
'.prettierrc.js', | ||
'eslint.config.js', | ||
], | ||
}, | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommended, | ||
...tseslint.configs.stylistic, | ||
require('eslint-config-prettier'), | ||
{ | ||
plugins: { | ||
'typescript-eslint': | ||
tseslint.plugin, | ||
prettier: eslintPrettier, | ||
}, | ||
languageOptions: { | ||
ecmaVersion: 'latest', | ||
parser: tseslint.parser, | ||
parserOptions: { | ||
project: true, | ||
}, | ||
sourceType: 'module', | ||
globals: { | ||
...globals.node, | ||
...globals.jest, | ||
}, | ||
}, | ||
rules: { | ||
'prettier/prettier': 'error', | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.md'], | ||
plugins: { | ||
markdown: require('eslint-plugin-markdown'), | ||
}, | ||
processor: 'markdown/markdown', | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"ignore": [ | ||
".git", | ||
"node_modules", | ||
"test" | ||
], | ||
"verbose": true, | ||
"execMap": { | ||
"ts": "node -r ts-node/register -r tsconfig-paths/register" | ||
}, | ||
"ext": "js json ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Package logs exploring using local Grafana+Loki+Promtail stack | ||
|
||
## Motivation | ||
|
||
When developing locally, API logs are either too lengthy when using pino-pretty or too hard to visually parse when in JSON format. To make multiple log steps easier to read, one can utilise local Grafana+Loki+Promtail stack. It also allows one to collapse and expand log lines. | ||
|
||
## How to use | ||
|
||
1. Start environment using `pnpm dev:json-logs`. This command will pipe all the logs to the `./logs/fastify.log` file | ||
2. Navigate to Grafana `http://locahost:3000` | ||
3. Check dashboard "Loki: Logs/App" | ||
|
||
Notes: | ||
|
||
- Use default `admin:admin` to log into Grafana for customization. | ||
|
||
<image src="./assets/log-in.jpg" width=400/> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
version: '3' | ||
|
||
services: | ||
loki: | ||
image: grafana/loki:latest | ||
container_name: loki | ||
ports: | ||
- '3100:3100' | ||
volumes: | ||
- loki_storage:/loki | ||
networks: | ||
- monitoring | ||
|
||
promtail: | ||
image: grafana/promtail:latest | ||
container_name: promtail | ||
volumes: | ||
- ./promtail-config.yaml:/etc/promtail/config.yaml | ||
- ../../logs:/var/log/fastify | ||
command: -config.file=/etc/promtail/config.yaml | ||
networks: | ||
- monitoring | ||
|
||
grafana: | ||
image: grafana/grafana:latest | ||
container_name: grafana | ||
ports: | ||
- '3000:3000' | ||
volumes: | ||
- grafana-storage:/var/lib/grafana | ||
- ./provisioning/:/etc/grafana/provisioning | ||
environment: | ||
- GF_USERS_DEFAULT_THEME=light | ||
- GF_AUTH_ANONYMOUS_ENABLED=true | ||
networks: | ||
- monitoring | ||
|
||
volumes: | ||
grafana-storage: | ||
loki_storage: | ||
|
||
networks: | ||
monitoring: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
server: | ||
http_listen_port: 9080 | ||
grpc_listen_port: 0 | ||
|
||
positions: | ||
filename: /tmp/positions.yaml | ||
|
||
clients: | ||
- url: http://loki:3100/loki/api/v1/push | ||
|
||
scrape_configs: | ||
- job_name: system | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: fastify-logs | ||
__path__: /var/log/fastify/*.log | ||
pipeline_stages: | ||
- json: | ||
expressions: | ||
name: name | ||
severity: severity | ||
- labels: | ||
name: | ||
severity: | ||
message: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: 1 | ||
providers: | ||
- name: 'default' | ||
orgId: 1 | ||
folder: '' | ||
type: file | ||
disableDeletion: false | ||
editable: true | ||
options: | ||
path: /etc/grafana/provisioning/dashboards |
Oops, something went wrong.