Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: change migration directory and migration flow, prune docker image #18

Merged
merged 12 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ jobs:
- run:
name: Migrate DB
command: |
npm -s run migrate
docker run --network mojaloop-net \
-e ALS_CO_DATABASE_HOST='mysql' \
-e ALS_CO_DATABASE_PORT='3306' \
--rm mojaloop/als-consent-oracle:local \
sh -c 'npm run migrate'
- run:
name: Execute integration tests
command: |
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ RUN apk add --no-cache -t build-dependencies git make gcc g++ python3 libtool au
COPY package.json package-lock.json* /opt/app/
RUN npm ci

# check in .dockerignore what is skipped during copy
# Check in .dockerignore what is skipped during copy
COPY /. /opt/app/

RUN npm run build
RUN rm -rf src

# cleanup
# Cleanup
RUN apk del build-dependencies

FROM node:16.15.0-alpine
Expand All @@ -31,7 +30,10 @@ RUN ln -sf /dev/stdout ./logs/combined.log
RUN adduser -D app-user
USER app-user

COPY --chown=app-user --from=builder /opt/app/ .
# Copy only essential files for running service
COPY --chown=app-user --from=builder /opt/app/node_modules ./node_modules
COPY --chown=app-user --from=builder /opt/app/package*.json ./
COPY --chown=app-user --from=builder /opt/app/dist ./dist

RUN npm prune --production

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ npm run docker:run

To check the als-consent-oracle health visit [http://als-consent-oracle.local:3000/health](http://als-consent-oracle.local:3000/health)

### File structure of docker image
```
dist
└───config (Mount your default.json config file here)
└───migrations
└───seeds
└───src
└───package.json
logs
node_modules
package-lock.json
package.json (Run package commands with root package.json)
```

### Run locally with database in `docker-compose`

```bash
Expand Down
25 changes: 15 additions & 10 deletions audit-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@
},
"1068155|shins>markdown-it>sanitize-html": {
"decision": "ignore",
"madeAt": 1653439533126,
"expiresAt": 1656031521129
"madeAt": 1656116986893,
"expiresAt": 1658708983116
},
"1070260|shins>markdown-it>sanitize-html": {
"decision": "ignore",
"madeAt": 1653439533923,
"expiresAt": 1656031521129
"madeAt": 1656116988260,
"expiresAt": 1658708983116
},
"1067553|swagger2openapi>better-ajv-errors>jsonpointer": {
"decision": "ignore",
"madeAt": 1653439534691,
"expiresAt": 1656031521129
"madeAt": 1656084267006,
"expiresAt": 1658676263354
},
"1067946|swagger2openapi>better-ajv-errors>jsonpointer>oas-validator>ajv": {
"decision": "ignore",
"madeAt": 1653439535475,
"expiresAt": 1656031521129
"madeAt": 1656084267784,
"expiresAt": 1658676263354
},
"1070030|@mojaloop/central-services-shared>shins>markdown-it": {
"decision": "ignore",
Expand All @@ -118,8 +118,8 @@
},
"1068310|widdershins>markdown-it>yargs>yargs-parser": {
"decision": "ignore",
"madeAt": 1653439994276,
"expiresAt": 1656031986813
"madeAt": 1656084269396,
"expiresAt": 1658676263354
},
"1070483|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs": {
"decision": "ignore",
Expand Down Expand Up @@ -160,6 +160,11 @@
"decision": "ignore",
"madeAt": 1654855516529,
"expiresAt": 1657447511240
},
"1070905|undici": {
"decision": "ignore",
"madeAt": 1656084268560,
"expiresAt": 1658676263354
}
},
"rules": {},
Expand Down
41 changes: 20 additions & 21 deletions config/convictFileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ import Convict from 'convict'
const ENV_PREFIX = 'ALS_CO_'

export interface FileConfig {
PORT: number,
HOST: string,
PORT: number
HOST: string
INSPECT: {
DEPTH: number,
SHOW_HIDDEN: boolean,
DEPTH: number
SHOW_HIDDEN: boolean
COLOR: boolean
},
}
DATABASE: {
DIALECT: string;
HOST: string;
PORT: number;
USER: string;
PASSWORD: string;
DATABASE: string;
POOL_MIN_SIZE: number;
POOL_MAX_SIZE: number;
ACQUIRE_TIMEOUT_MILLIS: number;
CREATE_TIMEOUT_MILLIS: number;
DESTROY_TIMEOUT_MILLIS: number;
IDLE_TIMEOUT_MILLIS: number;
REAP_INTERVAL_MILLIS: number;
CREATE_RETRY_INTERVAL_MILLIS: number;
USE_NULL_AS_DEFAULT?: boolean;
DIALECT: string
HOST: string
PORT: number
USER: string
PASSWORD: string
DATABASE: string
POOL_MIN_SIZE: number
POOL_MAX_SIZE: number
ACQUIRE_TIMEOUT_MILLIS: number
CREATE_TIMEOUT_MILLIS: number
DESTROY_TIMEOUT_MILLIS: number
IDLE_TIMEOUT_MILLIS: number
REAP_INTERVAL_MILLIS: number
CREATE_RETRY_INTERVAL_MILLIS: number
USE_NULL_AS_DEFAULT?: boolean
}
}

Expand Down Expand Up @@ -170,6 +170,5 @@ const ConvictFileConfig = Convict<FileConfig>({
const ConfigFile = path.join(__dirname, 'default.json')
ConvictFileConfig.loadFile(ConfigFile)
ConvictFileConfig.validate({ allowed: 'strict' })

export default ConvictFileConfig
module.exports = ConvictFileConfig
56 changes: 28 additions & 28 deletions config/knexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,41 @@ const migrationsDirectory = path.join(__dirname, '../migrations')
const seedsDirectory = path.join(__dirname, '../seeds')

export interface DbConnection {
host: string;
port: number;
user: string;
password: string;
database: string;
host: string
port: number
user: string
password: string
database: string
}

export interface DbPool {
min: number;
max: number;
acquireTimeoutMillis: number;
createTimeoutMillis: number;
destroyTimeoutMillis: number;
idleTimeoutMillis: number;
reapIntervalMillis: number;
createRetryIntervalMillis: number;
min: number
max: number
acquireTimeoutMillis: number
createTimeoutMillis: number
destroyTimeoutMillis: number
idleTimeoutMillis: number
reapIntervalMillis: number
createRetryIntervalMillis: number
}

export interface DatabaseConfig {
client: string;
version?: string;
useNullAsDefault?: boolean;
connection: DbConnection | string;
pool?: DbPool;
client: string
version?: string
useNullAsDefault?: boolean
connection: DbConnection | string
pool?: DbPool
migrations: {
directory: string;
tableName: string;
stub?: string;
loadExtensions: string[];
};
directory: string
tableName: string
stub?: string
loadExtensions: string[]
}

seeds: {
directory: string;
loadExtensions: string[];
};
directory: string
loadExtensions: string[]
}
}

const ConfigFileProperties = ConvictFileConfig.getProperties()
Expand Down Expand Up @@ -95,11 +95,11 @@ const KnexDatabaseConfig: DatabaseConfig = {
directory: migrationsDirectory,
stub: `${migrationsDirectory}/migration.template`,
tableName: 'als-consent-oracle',
loadExtensions: ['.ts']
loadExtensions: ['.js']
},
seeds: {
directory: seedsDirectory,
loadExtensions: ['.ts']
loadExtensions: ['.js']
}
}

Expand Down
16 changes: 8 additions & 8 deletions config/serviceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import KnexDatabaseConfig, { DatabaseConfig } from './knexfile'
import ConvictFileConfig from './convictFileConfig'

export interface ServiceConfig {
PORT: number;
HOST: string;
DATABASE: DatabaseConfig;
INSPECT? : {
DEPTH: number;
SHOW_HIDDEN: boolean;
COLOR: boolean;
};
PORT: number
HOST: string
DATABASE: DatabaseConfig
INSPECT?: {
DEPTH: number
SHOW_HIDDEN: boolean
COLOR: boolean
}
}

const ConfigFileProperties = ConvictFileConfig.getProperties()
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ services:
- mojaloop-net
depends_on:
- mysql
environment:
- ALS_CO_DATABASE_HOST=mysql
- ALS_CO_DATABASE_PORT=3306
volumes:
- ./scripts/wait4.js:/opt/als-consent-oracle/scripts/wait4.js
- ./scripts/wait4.config.js:/opt/als-consent-oracle/scripts/wait4.config.js
Expand Down
Loading