-
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
0 parents
commit bae3557
Showing
25 changed files
with
958 additions
and
0 deletions.
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,19 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
indent_size = 2 | ||
tab_width = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.{md,yml,yaml,json,graphql}] | ||
indent_style = space | ||
|
||
[*.{md,yml,yaml}] | ||
trim_trailing_whitespace = false | ||
|
||
[.registry-*] | ||
insert_final_newline = 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,7 @@ | ||
# * text=auto | ||
* text eol=lf | ||
|
||
*.png binary | ||
*.jpg binary | ||
|
||
/.yarn/** linguist-vendored |
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,35 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [20] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install pnpm | ||
run: npm i -g pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Run test | ||
run: npm test | ||
|
||
- name: Coveralls | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
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,21 @@ | ||
# Dir | ||
.vite | ||
coverage/** | ||
dist | ||
logs | ||
node_modules | ||
resource | ||
|
||
# File | ||
*-lock.* | ||
*.lock | ||
*.log | ||
*.log* | ||
.conf/local.sh | ||
.registry-* | ||
_cleanup | ||
_init | ||
vite.config.js.timestamp-* | ||
|
||
# Keep | ||
!coverage/lcov.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,28 @@ | ||
variables: | ||
KUBE_NAMESPACE: boilerplate | ||
HELM_RELEASE_NAME: gql-yoga | ||
|
||
include: | ||
- project: 'inovacao/devops/template-cicd' | ||
file: 'sonar-js.yaml' | ||
- project: 'inovacao/devops/template-cicd' | ||
file: 'test-nodejs.yaml' | ||
- project: 'inovacao/devops/template-cicd' | ||
file: 'build-nodejs.yaml' | ||
- project: 'inovacao/devops/template-cicd' | ||
file: 'deploy.yaml' | ||
|
||
test: | ||
extends: .test | ||
|
||
sonar: | ||
extends: .sonar_js | ||
|
||
build: | ||
extends: .build | ||
|
||
stages: | ||
- test | ||
- sonar | ||
- build | ||
- deploy |
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,3 @@ | ||
engine-strict=true | ||
resolution-mode=highest | ||
auto-install-peers=true |
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,23 @@ | ||
# Dir | ||
.conf | ||
.github | ||
.vite | ||
bin | ||
coverage | ||
dist | ||
logs | ||
node_modules | ||
resource | ||
test/snapshots | ||
|
||
# File | ||
*.css | ||
*.html | ||
*-lock.* | ||
*.lock | ||
*.log | ||
*.log* | ||
.registry-* | ||
_cleanup | ||
_init | ||
vite.config.js.timestamp-* |
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,31 @@ | ||
arrowParens: avoid | ||
bracketSameLine: false | ||
bracketSpacing: false | ||
# embeddedLanguageFormatting: auto | ||
insertPragma: false | ||
htmlWhitespaceSensitivity: css | ||
printWidth: 720 | ||
proseWrap: preserve | ||
quoteProps: as-needed | ||
requirePragma: false | ||
semi: false | ||
singleAttributePerLine: true | ||
singleQuote: true | ||
trailingComma: all | ||
tabWidth: 4 | ||
useTabs: true | ||
|
||
overrides: | ||
- files: '*.svelte' | ||
options: | ||
parser: svelte | ||
plugins: | ||
- prettier-plugin-svelte | ||
# svelteSortOrder: options-scripts-markup-styles | ||
# svelteStrictMode: false | ||
svelteAllowShorthand: true | ||
svelteIndentScriptAndStyle: false | ||
- files: ['*.md', '*.yaml', '*.yml', '*.json', '*.graphql'] | ||
options: | ||
useTabs: false | ||
tabWidth: 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,154 @@ | ||
# Boilerplate GraphQL Yoga | ||
|
||
[![Build Status][ci-img]][ci] | ||
[![Coverage Status][coveralls-img]][coveralls] | ||
|
||
[ci-img]: https://github.com/lagden/boilerplate-gql-yoga/actions/workflows/nodejs.yml/badge.svg | ||
[ci]: https://github.com/lagden/boilerplate-gql-yoga/actions/workflows/nodejs.yml | ||
[coveralls-img]: https://coveralls.io/repos/github/lagden/boilerplate-gql-yoga/badge.svg?branch=main | ||
[coveralls]: https://coveralls.io/github/lagden/boilerplate-gql-yoga?branch=main | ||
|
||
Boilerplate para desenvolvimento de uma aplicação. | ||
|
||
- [Instalação](#instalação) | ||
- [Como utilizar](#como-utilizar) | ||
- [watch](#watch) | ||
- [teste](#teste) | ||
- [Imagem](#imagem) | ||
- [Deploy](#deploy) | ||
- [Exemplo](#exemplo) | ||
- [Middlewares](#middlewares) | ||
- [License](#license) | ||
|
||
## Instalação | ||
|
||
Utilize `@tadashi/boilerplate-create` para iniciar o projeto. | ||
|
||
``` | ||
npm i -g @tadashi/boilerplate-create | ||
boilerplate-create | ||
``` | ||
|
||
ou | ||
|
||
``` | ||
npx --yes @tadashi/boilerplate-create | ||
``` | ||
|
||
E siga as instruções do prompt. | ||
|
||
## Como utilizar | ||
|
||
Após finalizado o `scaffolding` do projeto, instale os pacotes. | ||
|
||
```shell | ||
bin/node/pkg.js | ||
bin/node/zera -m npm | ||
``` | ||
|
||
Feito isso, o projeto está pronto para funcionar. | ||
|
||
Para rodar **local**, utilize: | ||
|
||
```shell | ||
bin/local/start | ||
``` | ||
|
||
E via **docker**, utilize: | ||
|
||
```shell | ||
bin/docker/start | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> No **docker**, caso seja instalado um novo pacote, é necessário fazer o `build` da imagem novamente. | ||
Pare o container (`bin/docker/stop` ou `control + c`) e rode novamente passando o parâmetro `-b`: | ||
|
||
```shell | ||
bin/docker/start -b | ||
``` | ||
|
||
### watch | ||
|
||
O **watch** reinicia a aplicação caso ocorra alguma alteração. | ||
Rodando via **docker** isso ocorre por padrão, mas **local** é necessário fazer algumas instalações e configurações. | ||
|
||
```shell | ||
bin/local/start -w | ||
``` | ||
|
||
### teste | ||
|
||
Para executar os testes. | ||
|
||
**local:** | ||
|
||
```shell | ||
bin/local/test | ||
``` | ||
|
||
**docker:** | ||
|
||
```shell | ||
bin/docker/test | ||
``` | ||
|
||
## Imagem | ||
|
||
Crie os arquivos de usuário e senha do **registry** que serão utilizados para fazer o `push` da imagem. | ||
|
||
```shell | ||
echo 'username' > .registry-user | ||
echo 'password' > .registry-passwd | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> Verifique as suas variáveis de ambiente `.conf/*.sh`. | ||
E para fazer o `push` da imagem de sua aplicação, execute: | ||
|
||
```shell | ||
bin/docker/image -e production | ||
``` | ||
|
||
## Deploy | ||
|
||
Para executar o **deploy** é necessário alguns binários instalados: | ||
|
||
- **envsubst** by Bruno Haible | ||
- **rsync** by Andrew Tridgell, Wayne Davison and others | ||
|
||
O fluxo do sistema de **deploy** é simples: | ||
|
||
1. Carrega as variáveis de ambiente (`staging` ou `production`) | ||
2. Executa o script `bin/docker/image` (se passado o parâmetro `-i` esse processo é ignorado) | ||
3. Cria o arquivo `docker-compose-{VERSION}.yml` utilizando o **envsubst** | ||
4. Envia os arquivos para o servidor via **rsync** | ||
5. Executa o `docker stack deploy` no servidor | ||
|
||
```shell | ||
bin/docker/deploy -e production | ||
``` | ||
|
||
## Exemplo | ||
|
||
Chamada de exemplo da API via **curl**. | ||
|
||
```shell | ||
curl 'http://127.0.0.1:5001/gql' \ | ||
-H 'content-type: application/json' \ | ||
-d '{ | ||
"source": "query Hello($name: String!) { hello(name: $name) }", | ||
"variableValues": {"name": "Sabrina"}, | ||
"operationName": "Hello" | ||
}' | ||
``` | ||
|
||
## Buy me a coffee | ||
|
||
BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4 | ||
|
||
## License | ||
|
||
MIT © [Thiago Lagden](https://github.com/lagden) |
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,28 @@ | ||
import process from 'node:process' | ||
import {createServer} from 'node:http' | ||
import la from '@tadashi/local-access' | ||
import * as debug from '@tadashi/debug' | ||
import yoga from '../server/yoga.js' | ||
|
||
// prettier-ignore | ||
const { | ||
PORT: port = 5001, | ||
HOSTNAME_CUSTOM: hostname = '127.0.0.1', | ||
VERSION = 'dev', | ||
} = process.env | ||
|
||
// prettier-ignore | ||
const { | ||
local, | ||
network, | ||
} = la({port, hostname}) | ||
|
||
const app = createServer(yoga) | ||
app.listen(port, () => { | ||
debug.info('Server listening') | ||
debug.info('----------------') | ||
debug.info(`Local: ${local}`) | ||
debug.info(`Network: ${network}`) | ||
debug.info('----------------') | ||
debug.info(`Version: ${VERSION}`) | ||
}) |
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,14 @@ | ||
import process from 'node:process' | ||
import * as debug from '@tadashi/debug' | ||
|
||
// prettier-ignore | ||
const { | ||
APP_ENV, | ||
GITLAB_ENVIRONMENT_NAME, | ||
} = process.env | ||
|
||
/* c8 ignore start */ | ||
process.env.APP_ENV = APP_ENV ?? GITLAB_ENVIRONMENT_NAME ?? 'production' | ||
/* c8 ignore stop */ | ||
|
||
debug.info('reset.js | process.env', process.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,4 @@ | ||
#!/usr/bin/env node | ||
|
||
await import('./reset.js') | ||
await import('./listen.js') |
Oops, something went wrong.