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 seedpull/4/head
parent
a8c65cf3c2
commit
e5d7df3e7b
@ -1,9 +0,0 @@
|
||||
FROM node:14
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3333
|
||||
CMD [ "npm", "run", "start:prod" ]
|
@ -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…
Reference in new issue