Skip to content

Commit

Permalink
chore: Improve readme (#73)
Browse files Browse the repository at this point in the history
* feat: Improve README

* feat: Improve configs storing

* feat: Update CI for secrets
  • Loading branch information
letehaha authored Jul 16, 2023
1 parent 5efaf3c commit cdf52ad
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 76 deletions.
11 changes: 11 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# used in migrations to fetch actual currencies rates
API_LAYER_API_KEY=

APPLICATION_HOST=
APPLICATION_PORT=
APPLICATION_JWT_SECRET=
APPLICATION_DB_HOST=
APPLICATION_DB_USERNAME=
APPLICATION_DB_PASSWORD=
APPLICATION_DB_DATABASE=
APPLICATION_DB_PORT=
APPLICATION_DB_DIALECT=
APPLICATION_REDIS_HOST=
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/seeders/**/*.js
src/migrations/**/*.js
.eslintrc.js
config/db/config.js
config/**
32 changes: 32 additions & 0 deletions .github/workflows/check-source-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
name: Unit and e2e testing
needs: prepare-dependencies
runs-on: ubuntu-latest
environment: test
services:
postgres:
image: postgres:11.12-stretch
Expand All @@ -54,14 +55,45 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/prepare-local-env
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_APPLICATION_HOST: ${{ secrets.APPLICATION_HOST }}
envkey_APPLICATION_PORT: ${{ secrets.APPLICATION_PORT }}
envkey_APPLICATION_JWT_SECRET: ${{ secrets.APPLICATION_JWT_SECRET }}
envkey_APPLICATION_DB_HOST: ${{ secrets.APPLICATION_DB_HOST }}
envkey_APPLICATION_DB_USERNAME: ${{ secrets.APPLICATION_DB_USERNAME }}
envkey_APPLICATION_DB_PASSWORD: ${{ secrets.APPLICATION_DB_PASSWORD }}
envkey_APPLICATION_DB_DATABASE: ${{ secrets.APPLICATION_DB_DATABASE }}
envkey_APPLICATION_DB_PORT: ${{ secrets.APPLICATION_DB_PORT }}
envkey_APPLICATION_DB_DIALECT: ${{ secrets.APPLICATION_DB_DIALECT }}
envkey_APPLICATION_REDIS_HOST: ${{ secrets.APPLICATION_REDIS_HOST }}
directory: ./
file_name: .env.test
- name: Unit and e2e testing
run: npm run test

docker-build:
name: Build source code using Docker
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v2
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_APPLICATION_HOST: ${{ secrets.APPLICATION_HOST }}
envkey_APPLICATION_PORT: ${{ secrets.APPLICATION_PORT }}
envkey_APPLICATION_JWT_SECRET: ${{ secrets.APPLICATION_JWT_SECRET }}
envkey_APPLICATION_DB_HOST: ${{ secrets.APPLICATION_DB_HOST }}
envkey_APPLICATION_DB_USERNAME: ${{ secrets.APPLICATION_DB_USERNAME }}
envkey_APPLICATION_DB_PASSWORD: ${{ secrets.APPLICATION_DB_PASSWORD }}
envkey_APPLICATION_DB_DATABASE: ${{ secrets.APPLICATION_DB_DATABASE }}
envkey_APPLICATION_DB_PORT: ${{ secrets.APPLICATION_DB_PORT }}
envkey_APPLICATION_DB_DIALECT: ${{ secrets.APPLICATION_DB_DIALECT }}
envkey_APPLICATION_REDIS_HOST: ${{ secrets.APPLICATION_REDIS_HOST }}
directory: ./
file_name: .env.production
- uses: ./.github/actions/docker-build
with:
docker-hub-username: ${{ secrets.DOCKER_HUB_USERNAME }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ typings/
# dotenv environment variables file
.env
.env.test
.env.development
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
2 changes: 1 addition & 1 deletion .sequelizerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
require('dotenv').config();
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` })

module.exports = {
"config": path.resolve('./config/db', 'config.js'),
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ npm run dev
2. Run `nvm use`
3. That's it!

### Guide to setup postgres DB and Redis from scratch

If you can access your user and you know how to create a DB, **you can ignore that section**.

If you don't know how to access your postgres user or DB:
1. Install Postgres.app for all existing postgres version [here](https://postgresapp.com/downloads.html) (it will install all needed Posgres versions).
2. Open the app, in the interface click on the "+" on the bottom left and add a new V11 server.
3. Click "Initialize" button from the interface.
4. If you have error "Post already in use", try to close apps that are using that port. Otherwise click on the server V11 in the interface and change port to 5433
5. Connect to default DB user using "psql -h localhost -p 5432 -U postgres -d postgres". If you changed port on the previos step, update the port
6. Now run following commands to setup a user (update dumb values with you own):
- "CREATE USER `myuser` WITH PASSWORD `'secretpassword'`;"
- ALTER ROLE `myuser` SUPERUSER;
- CREATE DATABASE `db-name`; (db-name will be used for the app)
- \d (to close the connection)
- psql -h localhost -p 5432 -U `myuser` -d `db-name`
7. That's it.

To install Redis (if you don't have one):
1. Install Redis via `brew install redis`
2. Then `brew services start redis`
3. You're done :)

### Current DB schema

![budget-tracker-schema](https://user-images.githubusercontent.com/12257282/147393125-de1c8815-023e-49d4-b337-20cfaea06552.png)
1 change: 1 addition & 0 deletions config/db/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` });
const config = require('config').get('db');

const options = {
Expand Down
26 changes: 26 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Default file that being merged with others env-related files

module.exports = {
name: 'budget-tracker-be',
host: process.env.APPLICATION_HOST,
port: process.env.APPLICATION_PORT,
apiPrefix: '/api/v1',
jwtSecret: process.env.APPLICATION_JWT_SECRET,
db: {
host: process.env.APPLICATION_DB_HOST,
username: process.env.APPLICATION_DB_USERNAME,
password: process.env.APPLICATION_DB_PASSWORD,
database: process.env.APPLICATION_DB_DATABASE,
port: process.env.APPLICATION_DB_PORT,
dialect: process.env.APPLICATION_DB_DIALECT,
logging: true,
},
redis: {
host: process.env.APPLICATION_REDIS_HOST,
},
bankIntegrations: {
monobank: {
apiEndpoint: 'https://api.monobank.ua'
}
},
}
8 changes: 0 additions & 8 deletions config/default.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: 'development',
envShort: 'dev',
hostWebhooksCallback: 'http://d8d75e719def.ngrok.io',
}
21 changes: 0 additions & 21 deletions config/development.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: 'production',
envShort: 'prod',
hostWebhooksCallback: 'http://d8d75e719def.ngrok.io',
}
21 changes: 0 additions & 21 deletions config/production.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: 'test',
envShort: 'test',
hostWebhooksCallback: 'http://d8d75e719def.ngrok.io',
}
21 changes: 0 additions & 21 deletions config/test.json

This file was deleted.

2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test|e2e).[jt]s?(x)'],
testMatch: ['**/?(*.)+(unit|spec|e2e).[jt]s?(x)'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json',
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from "dotenv";
import 'module-alias/register';

dotenv.config();
dotenv.config({ path: `.env.${process.env.NODE_ENV}` });
import config from 'config';
import express, { Request } from 'express';
import cors from 'cors';
Expand Down
2 changes: 1 addition & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const sequelize = new Sequelize({
models: [__dirname + '/**/*.model.ts'],
});

if (process.env.NODE_ENV === 'development') {
if (['development', 'test'].includes(process.env.NODE_ENV)) {
console.log('DBConfig', DBConfig);
}

Expand Down

0 comments on commit cdf52ad

Please sign in to comment.