Simplify project setup (#3)
* Simplify project setup * Setup docker * Add seed * Feature/migrate links to router link (#2) * Migrate links to RouterLink * Add i18n * Simplify project setup * Setup docker * Add seed
This commit is contained in:
parent
a8c65cf3c2
commit
e5d7df3e7b
@ -3,7 +3,7 @@ COMPOSE_PROJECT_NAME=ghostfolio-development
|
|||||||
# CACHE
|
# CACHE
|
||||||
CACHE_TTL=1
|
CACHE_TTL=1
|
||||||
MAX_ITEM_IN_CACHE=9999
|
MAX_ITEM_IN_CACHE=9999
|
||||||
REDIS_HOST=redis
|
REDIS_HOST=localhost
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
|
||||||
# POSTGRES
|
# POSTGRES
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -40,8 +40,3 @@ testem.log
|
|||||||
# System Files
|
# System Files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Local
|
|
||||||
/backups
|
|
||||||
.env
|
|
||||||
ec2-nano-ssh.pem
|
|
||||||
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Changed the routing to `routerLink` for an improved navigation experience
|
- Changed the routing to `routerLink` for an improved navigation experience
|
||||||
|
- Simplified the initial project setup
|
||||||
|
|
||||||
## 0.85.0 - 12.04.2021
|
## 0.85.0 - 12.04.2021
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
FROM node:14
|
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
EXPOSE 3333
|
|
||||||
CMD [ "npm", "run", "start:prod" ]
|
|
13
README.md
13
README.md
@ -23,18 +23,19 @@
|
|||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
1. Run `yarn install`
|
1. Run `yarn install`
|
||||||
2. Run `yarn docker:dockerize`
|
2. Run `cd docker`
|
||||||
3. Copy `.env.sample` to `docker/.env`
|
3. Run `docker compose build`
|
||||||
4. Run `cd docker/<version>`
|
4. Run `docker compose up -d`
|
||||||
5. Run `docker-compose build`
|
5. Run `yarn setup:database`
|
||||||
6. Run `docker-compose up -d`
|
6. Start server and client (see _Development_)
|
||||||
|
7. Login as _Admin_ with the `Security Token`: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9`
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Start server
|
### Start server
|
||||||
|
|
||||||
- Serve: Run `yarn start:server`
|
|
||||||
- Debug: Run `yarn watch:server` and click "Launch Program" in _Visual Studio Code_
|
- Debug: Run `yarn watch:server` and click "Launch Program" in _Visual Studio Code_
|
||||||
|
- Serve: Run `yarn start:server`
|
||||||
|
|
||||||
### Start client
|
### Start client
|
||||||
|
|
||||||
|
@ -1,20 +1,5 @@
|
|||||||
version: '3.7'
|
version: '3.7'
|
||||||
services:
|
services:
|
||||||
ghostfolio:
|
|
||||||
container_name: ghostfolio
|
|
||||||
image: ghostfolio:{{VERSION}}
|
|
||||||
restart: unless-stopped
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
- redis
|
|
||||||
env_file:
|
|
||||||
- ../.env
|
|
||||||
environment:
|
|
||||||
- NODE_ENV=production
|
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:12
|
image: postgres:12
|
||||||
container_name: postgres
|
container_name: postgres
|
||||||
@ -34,6 +19,4 @@ services:
|
|||||||
- 6379:6379
|
- 6379:6379
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
portainer_data:
|
|
||||||
postgres:
|
postgres:
|
||||||
name: ghostfolio-db
|
|
@ -13,6 +13,8 @@
|
|||||||
"angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng",
|
"angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng",
|
||||||
"build:all": "ng build --prod api && ng build --prod client && yarn run replace-placeholders-in-build",
|
"build:all": "ng build --prod api && ng build --prod client && yarn run replace-placeholders-in-build",
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
|
"database:push": "yarn prisma db push --preview-feature",
|
||||||
|
"database:seed": "prisma db seed --preview-feature",
|
||||||
"dep-graph": "nx dep-graph",
|
"dep-graph": "nx dep-graph",
|
||||||
"docker:build": "cd docker/1.0.1 && docker-compose build",
|
"docker:build": "cd docker/1.0.1 && docker-compose build",
|
||||||
"docker:dockerize": "./node_modules/.bin/ts-node ./scripts/dockerize.ts",
|
"docker:dockerize": "./node_modules/.bin/ts-node ./scripts/dockerize.ts",
|
||||||
@ -29,11 +31,13 @@
|
|||||||
"nx": "nx",
|
"nx": "nx",
|
||||||
"postinstall": "yarn prisma generate",
|
"postinstall": "yarn prisma generate",
|
||||||
"replace-placeholders-in-build": "node ./replace.build.js",
|
"replace-placeholders-in-build": "node ./replace.build.js",
|
||||||
|
"setup:database": "yarn database:push && yarn database:seed",
|
||||||
"start": "node dist/apps/api/main",
|
"start": "node dist/apps/api/main",
|
||||||
"start:client": "ng serve client --hmr -o",
|
"start:client": "ng serve client --hmr -o",
|
||||||
"start:prod": "node apps/api/main",
|
"start:prod": "node apps/api/main",
|
||||||
"start:server": "yarn run nx serve api",
|
"start:server": "yarn run nx serve api",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
|
"ts-node": "ts-node --compiler-options '{\"module\":\"CommonJS\"}'",
|
||||||
"update": "nx migrate latest",
|
"update": "nx migrate latest",
|
||||||
"watch:server": "yarn run nx build api --watch",
|
"watch:server": "yarn run nx build api --watch",
|
||||||
"workspace-generator": "nx workspace-generator"
|
"workspace-generator": "nx workspace-generator"
|
||||||
|
53
prisma/seed.ts
Normal file
53
prisma/seed.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { Currency, PrismaClient, Role, Type } from '@prisma/client';
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const admin = await prisma.user.upsert({
|
||||||
|
create: {
|
||||||
|
accessToken:
|
||||||
|
'c689bcc894e4a420cb609ee34271f3e07f200594f7d199c50d75add7102889eb60061a04cd2792ebc853c54e37308271271e7bf588657c9e0c37faacbc28c3c6',
|
||||||
|
alias: 'Admin',
|
||||||
|
id: '4e1af723-95f6-44f8-92a7-464df17f6ec3',
|
||||||
|
role: Role.ADMIN
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
where: { id: '4e1af723-95f6-44f8-92a7-464df17f6ec3' }
|
||||||
|
});
|
||||||
|
|
||||||
|
const demo = await prisma.user.upsert({
|
||||||
|
create: {
|
||||||
|
accessToken:
|
||||||
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjliMTEyYjRkLTNiN2QtNGJhZC05YmRkLTNiMGY3YjRkYWMyZiIsImlhdCI6MTYxODUxMjAxNCwiZXhwIjoxNjIxMTA0MDE0fQ.l3WUxpI0hxuQtdPrD0kd7sem6S2kx_7CrdNvkmlKuWw',
|
||||||
|
alias: 'Demo',
|
||||||
|
id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f',
|
||||||
|
role: Role.DEMO,
|
||||||
|
Order: {
|
||||||
|
create: [
|
||||||
|
{
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),
|
||||||
|
fee: 30,
|
||||||
|
id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',
|
||||||
|
quantity: 50,
|
||||||
|
symbol: 'TSLA',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 42.97
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
where: { id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f' }
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log({ admin, demo });
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
})
|
||||||
|
.finally(async () => {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
});
|
@ -1,89 +0,0 @@
|
|||||||
import * as dotenv from 'dotenv';
|
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
const replace = require('replace-in-file');
|
|
||||||
const version = require(path.resolve(__dirname, '..', 'package.json')).version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a docker image
|
|
||||||
*/
|
|
||||||
class Dockerizer {
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
constructor() {
|
|
||||||
dotenv.config({
|
|
||||||
path: path.resolve(__dirname, '..', '.env')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async dockerize(aVersion: string) {
|
|
||||||
console.log('Dockerizing...');
|
|
||||||
|
|
||||||
console.log('Version:', aVersion);
|
|
||||||
|
|
||||||
await this.executeShellCommand('rm -rf ./dist');
|
|
||||||
|
|
||||||
console.log(`Building source...`);
|
|
||||||
|
|
||||||
await this.executeShellCommand('ng build --prod api');
|
|
||||||
|
|
||||||
await this.executeShellCommand('ng build --prod client');
|
|
||||||
|
|
||||||
await this.executeShellCommand('yarn run replace-placeholders-in-build');
|
|
||||||
|
|
||||||
console.log(`Copying files...`);
|
|
||||||
|
|
||||||
await this.executeShellCommand(`mkdir -p ./docker/${aVersion}`);
|
|
||||||
await this.executeShellCommand(`cp -r ./dist/ ./docker/${aVersion}`);
|
|
||||||
|
|
||||||
await this.executeShellCommand(`mkdir ./docker/${aVersion}/prisma`);
|
|
||||||
await this.executeShellCommand(
|
|
||||||
`cp -r ./prisma/schema.prisma ./docker/${aVersion}/prisma/schema.prisma`
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.executeShellCommand(
|
|
||||||
`cp ./docker-compose.yml ./docker/${aVersion}`
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
replace.sync({
|
|
||||||
allowEmptyPaths: false,
|
|
||||||
files: `./docker/${aVersion}/docker-compose.yml`,
|
|
||||||
from: /{{VERSION}}/g,
|
|
||||||
to: aVersion
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while replacing docker-compose.yml:', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.executeShellCommand(`cp ./Dockerfile ./docker/${aVersion}`);
|
|
||||||
await this.executeShellCommand(`cp ./package.json ./docker/${aVersion}`);
|
|
||||||
await this.executeShellCommand(`cp ./yarn.lock ./docker/${aVersion}`);
|
|
||||||
|
|
||||||
await this.executeShellCommand(
|
|
||||||
`cd docker/${aVersion} && yarn install --production`
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('Dockerizing has been completed successfully.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes a shell command and return it as a promise
|
|
||||||
*/
|
|
||||||
private executeShellCommand(cmd: string) {
|
|
||||||
const exec = require('child_process').exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
// Maximum buffer size increased to 1000 * 1000KB
|
|
||||||
exec(cmd, { maxBuffer: 1000 * 1024 * 1000 }, (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.warn(error);
|
|
||||||
}
|
|
||||||
resolve(stdout ? stdout : stderr);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const dockerizer = new Dockerizer();
|
|
||||||
dockerizer.dockerize(version);
|
|
Loading…
x
Reference in New Issue
Block a user