Skip to content

Commit

Permalink
Fix any Docker related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLoneRonin committed Feb 8, 2021
1 parent 3b8797c commit 76d5d05
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Include Essential Gateway Files
!/bin
!/.env
!/types.graphql
!/codegen.yml
!/knexfile.ts
!/yarn.lock
!/package.json
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@typescript-eslint"
],
"rules": {
"quotes": [2, "single", { "avoidEscape": true }],
"require-jsdoc": 0,
"max-len": 0,
"camelcase": 0
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ services:
image: postgres:12
volumes:
- database:/var/lib/postgresql/data
expose:
- ${DATABASE_PORT}
ports:
- 5432:5432
- ${DATABASE_PORT}:${DATABASE_PORT}
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
command: -p ${DATABASE_PORT}
# Gateway Configuration
server:
build:
Expand Down
8 changes: 5 additions & 3 deletions docker/gateway.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ WORKDIR /app

COPY bin/wait.sh bin/wait.sh
COPY .env .env
COPY types.graphql types.graphql
COPY codegen.yml codegen.yml
COPY knexfile.ts knexfile.ts
COPY package.json package.json
COPY tsconfig.json tsconfig.json
COPY src src
COPY migrations migrations

RUN chmod +x bin/wait.sh
RUN npm install
RUN npm run dev:build
RUN yarn
RUN yarn dev:build

CMD ["./bin/wait.sh", "postgres:5432", "--", "npm", "start"]
CMD ["./bin/wait.sh", "$DATABASE_HOST:$DATABASE_PORT", "--", "yarn", "start"]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"license": "MIT",
"scripts": {
"dev:lint": "eslint src/**/*.ts migrations/*.ts knexfile.ts",
"dev:gql": "graphql-codegen --config codegen.yml",
"dev:build": "tsc && npm run dev:gql",
"dev:gql": "npx graphql-codegen --config codegen.yml",
"dev:build": "npm run dev:gql && tsc",
"dev:start": "npm run dev:build && node dist/src/Gateway.js",
"dev:restart": "npm run migrate:down && npm run migrate:latest && npm run dev:start",
"migrate:latest": "knex migrate:latest",
"migrate:up": "knex migrate:up",
"migrate:down": "knex migrate:down",
"docker:start": "docker-compose up --build -d",
"docker:stop": "docker-compose down -v",
"start": "npm run migrate:latest && node dist/gateway/app.js"
"start": "npm run migrate:latest && node dist/src/Gateway.js"
},
"dependencies": {
"apollo-server-express": "^2.19.2",
Expand Down
8 changes: 8 additions & 0 deletions src/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {log} from './utility/log.utility';
import {graphServer} from './graphql/server.graphql';
import {proxyRoute} from './route/proxy.route';
import {dataRouteRegex, dataRoute} from './route/data.route';
import {transactionOptionsRoute, transactionRoute} from './route/transaction.route';
import {chunkOptionsRoute, chunkRoute} from './route/chunk.route';
import {startSync} from './database/sync.database';

config();
Expand All @@ -23,6 +25,12 @@ export function start() {
app.get(dataRouteRegex, dataRoute);
app.all('*', proxyRoute);

app.options('/tx', transactionOptionsRoute);
app.post('/tx', transactionRoute);

app.options('/chunk', chunkOptionsRoute);
app.post('/chunk', chunkRoute);

app.listen(process.env.PORT || 3000, () => {
log.info(`[app] started on http://localhost:${process.env.PORT || 3000}`);
startSync();
Expand Down
2 changes: 1 addition & 1 deletion src/database/batch.database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {formatTransaction, DatabaseTag, ANSTransaction, formatAnsTransaction} fr
import {utf8DecodeTag} from '../utility/encoding.utility';
import {ansBundles} from '../utility/ans.utility';

export function createBatchItem(batchScope: Transaction, table: string, data: object, conflictKey: string = `id`): QueryBuilder {
export function createBatchItem(batchScope: Transaction, table: string, data: object, conflictKey: string = 'id'): QueryBuilder {
return batchScope
.insert(data)
.into(table)
Expand Down
8 changes: 4 additions & 4 deletions src/database/sync.database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function startSync() {
}

bar = new ProgressBar(
`:current/:total blocks synced [:bar] :percent :etas`,
':current/:total blocks synced [:bar] :percent :etas',
{
complete: '|',
incomplete: ' ',
Expand All @@ -56,11 +56,11 @@ export async function startSync() {
}

process.on('SIGINT', () => {
log.info(`[database] ensuring all blocks are stored before exit, you may see some extra output in console`);
log.info('[database] ensuring all blocks are stored before exit, you may see some extra output in console');
SIGKILL = true;
setInterval(() => {
if (SIGINT === false) {
log.info(`[database] block sync state preserved, now exiting`);
log.info('[database] block sync state preserved, now exiting');
process.exit();
}
}, 100);
Expand All @@ -87,7 +87,7 @@ export async function parallelize(height: number) {
parallelize(height - 8);
}
} else {
log.info(`[database] sync complete`);
log.info('[database] sync complete');
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/middleware/log.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export function logConfigurationMiddleware(req: Request, res: Response, next: Ne
const trace = id.generate();

req.id = trace;
res.header(`X-Trace`, trace);
res.header('X-Trace', trace);

return next();
}

morgan.token(`trace`, (req: Request) => {
return req.id || `UNKNOWN`;
morgan.token('trace', (req: Request) => {
return req.id || 'UNKNOWN';
});

export const logMiddleware = morgan('[http] :remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms ":referrer" ":user-agent" [trace=:trace]');
9 changes: 9 additions & 0 deletions src/route/chunk.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Request, Response} from 'express';

export async function chunkOptionsRoute(req: Request, res: Response) {
return res.send('OK').end();
}

export async function chunkRoute(req: Request, res: Response) {

}
9 changes: 9 additions & 0 deletions src/route/transaction.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Request, Response} from 'express';

export async function transactionOptionsRoute(req: Request, res: Response) {
return res.send('OK').end();
}

export async function transactionRoute(req: Request, res: Response) {

}

0 comments on commit 76d5d05

Please sign in to comment.