mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
Merge pull request #98 from Hexastack/fix/api-prod-dockerfile
Fix/api prod dockerfile
This commit is contained in:
commit
620570b955
1
.github/workflows/docker.yml
vendored
1
.github/workflows/docker.yml
vendored
@ -66,6 +66,7 @@ jobs:
|
|||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ./api/
|
context: ./api/
|
||||||
|
target: production
|
||||||
file: ./api/Dockerfile
|
file: ./api/Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
|
2
Makefile
2
Makefile
@ -41,7 +41,7 @@ start: check-env
|
|||||||
|
|
||||||
# Dev command: runs docker-compose with the main file, dev file, and any additional service dev files (if they exist)
|
# Dev command: runs docker-compose with the main file, dev file, and any additional service dev files (if they exist)
|
||||||
dev: check-env
|
dev: check-env
|
||||||
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) up -d
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) up --build -d
|
||||||
|
|
||||||
# Start command: runs docker-compose with the main file and any additional service files
|
# Start command: runs docker-compose with the main file and any additional service files
|
||||||
start-prod: check-env
|
start-prod: check-env
|
||||||
|
@ -2,13 +2,25 @@ FROM node:18-alpine AS builder
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY package*.json ./
|
||||||
|
|
||||||
FROM node:18-alpine AS installer
|
COPY merge-extensions-deps.js ./
|
||||||
|
|
||||||
|
COPY src/extensions ./src/extensions
|
||||||
|
|
||||||
|
COPY patches ./patches
|
||||||
|
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM node:18-alpine AS development
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
COPY --from=builder /app/merge-extensions-deps.js ./
|
COPY --from=builder /app/merge-extensions-deps.js ./
|
||||||
|
|
||||||
@ -16,20 +28,34 @@ COPY --from=builder /app/src/extensions ./src/extensions
|
|||||||
|
|
||||||
COPY --from=builder /app/patches ./patches
|
COPY --from=builder /app/patches ./patches
|
||||||
|
|
||||||
RUN npm update -g npm
|
RUN npm install
|
||||||
|
|
||||||
RUN npm config set registry https://registry.npmjs.com/
|
|
||||||
|
|
||||||
RUN npm i --verbose --maxsockets 6
|
|
||||||
|
|
||||||
FROM node:18-alpine AS runner
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --from=installer /app/ .
|
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
ENV NODE_ENV=development
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
CMD [ "npm", "run" , "start:dev" ]
|
CMD ["npm", "run", "start:debug"]
|
||||||
|
|
||||||
|
FROM node:18-alpine AS production
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
COPY --from=builder /app/merge-extensions-deps.js ./
|
||||||
|
|
||||||
|
COPY --from=builder /app/src/extensions ./src/extensions
|
||||||
|
|
||||||
|
COPY --from=builder /app/patches ./patches
|
||||||
|
|
||||||
|
RUN npm ci --only=production
|
||||||
|
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["npm", "run", "start:prod"]
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
"test:cov": "jest --coverage --runInBand --detectOpenHandles --forceExit",
|
"test:cov": "jest --coverage --runInBand --detectOpenHandles --forceExit",
|
||||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||||
"cache:init": "ts-node -T ./src/database-init.ts",
|
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"containers:restart": "cd .. && make init && make stop && make start",
|
"containers:restart": "cd .. && make init && make stop && make start",
|
||||||
"containers:rebuild": "cd .. && make init && make destroy && make start",
|
"containers:rebuild": "cd .. && make init && make destroy && make start",
|
||||||
@ -77,13 +76,13 @@
|
|||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"slug": "^8.2.2",
|
"slug": "^8.2.2",
|
||||||
"ts-migrate-mongoose": "^3.8.3",
|
"ts-migrate-mongoose": "^3.8.3",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1",
|
||||||
|
"@nestjs/swagger": "^7.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@compodoc/compodoc": "^1.1.24",
|
"@compodoc/compodoc": "^1.1.24",
|
||||||
"@nestjs/cli": "^10.0.0",
|
"@nestjs/cli": "^10.0.0",
|
||||||
"@nestjs/schematics": "^10.0.0",
|
"@nestjs/schematics": "^10.0.0",
|
||||||
"@nestjs/swagger": "^7.2.0",
|
|
||||||
"@nestjs/testing": "^10.0.0",
|
"@nestjs/testing": "^10.0.0",
|
||||||
"@types/bcryptjs": "^2.4.6",
|
"@types/bcryptjs": "^2.4.6",
|
||||||
"@types/cookie-parser": "^1.4.6",
|
"@types/cookie-parser": "^1.4.6",
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2024 Hexastack. All rights reserved.
|
|
||||||
*
|
|
||||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
|
||||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
|
||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
|
||||||
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { NestFactory } from '@nestjs/core';
|
|
||||||
import moduleAlias from 'module-alias';
|
|
||||||
|
|
||||||
moduleAlias.addAliases({
|
|
||||||
'@': __dirname,
|
|
||||||
});
|
|
||||||
|
|
||||||
import { AppModule } from './app.module';
|
|
||||||
import { config } from './config';
|
|
||||||
import { seedDatabase } from './seeder';
|
|
||||||
|
|
||||||
async function databaseInit() {
|
|
||||||
const isProduction = config.env.toLowerCase().includes('prod');
|
|
||||||
|
|
||||||
const app = await NestFactory.createApplicationContext(AppModule);
|
|
||||||
|
|
||||||
if (!isProduction) await seedDatabase(app);
|
|
||||||
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
databaseInit();
|
|
@ -22,6 +22,7 @@ moduleAlias.addAliases({
|
|||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
import { LoggerService } from './logger/logger.service';
|
import { LoggerService } from './logger/logger.service';
|
||||||
|
import { seedDatabase } from './seeder';
|
||||||
import { swagger } from './swagger';
|
import { swagger } from './swagger';
|
||||||
import { sessionStore } from './utils/constants/session-store';
|
import { sessionStore } from './utils/constants/session-store';
|
||||||
import { ObjectIdPipe } from './utils/pipes/object-id.pipe';
|
import { ObjectIdPipe } from './utils/pipes/object-id.pipe';
|
||||||
@ -83,7 +84,10 @@ async function bootstrap() {
|
|||||||
else throw error;
|
else throw error;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isProduction) swagger(app);
|
if (!isProduction) {
|
||||||
|
await seedDatabase(app);
|
||||||
|
swagger(app);
|
||||||
|
}
|
||||||
|
|
||||||
await app.listen(3000);
|
await app.listen(3000);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
version: "3.8"
|
version: "3.8"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
database-init:
|
|
||||||
build:
|
|
||||||
context: ../api
|
|
||||||
pull_policy: build
|
|
||||||
volumes:
|
|
||||||
- ../api/src:/app/src
|
|
||||||
- ../api/migrations:/app/migrations
|
|
||||||
# - ../api/node_modules:/app/node_modules
|
|
||||||
|
|
||||||
api:
|
api:
|
||||||
build:
|
build:
|
||||||
context: ../api
|
context: ../api
|
||||||
|
target: development
|
||||||
pull_policy: build
|
pull_policy: build
|
||||||
ports:
|
ports:
|
||||||
- ${API_PORT}:3000
|
- ${API_PORT}:3000
|
||||||
@ -21,7 +13,6 @@ services:
|
|||||||
- ../api/src:/app/src
|
- ../api/src:/app/src
|
||||||
- ../api/migrations:/app/migrations
|
- ../api/migrations:/app/migrations
|
||||||
#- ../api/node_modules:/app/node_modules
|
#- ../api/node_modules:/app/node_modules
|
||||||
command: ["npm", "run", "start:debug"]
|
|
||||||
|
|
||||||
mongo-express:
|
mongo-express:
|
||||||
container_name: mongoUi
|
container_name: mongoUi
|
||||||
|
@ -1,17 +1,6 @@
|
|||||||
version: "3.9"
|
version: "3.9"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
database-init:
|
|
||||||
container_name: database-init
|
|
||||||
image: hexastack/hexabot-api:latest
|
|
||||||
command: sh -c "npm run cache:init && npm run migrate prune && npm run migrate up"
|
|
||||||
env_file: .env
|
|
||||||
networks:
|
|
||||||
- db-network
|
|
||||||
depends_on:
|
|
||||||
mongo:
|
|
||||||
condition: service_healthy
|
|
||||||
|
|
||||||
api:
|
api:
|
||||||
container_name: api
|
container_name: api
|
||||||
image: hexastack/hexabot-api:latest
|
image: hexastack/hexabot-api:latest
|
||||||
@ -26,8 +15,6 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
mongo:
|
mongo:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
database-init:
|
|
||||||
condition: service_completed_successfully
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: "wget --spider http://localhost:3000"
|
test: "wget --spider http://localhost:3000"
|
||||||
interval: 10s
|
interval: 10s
|
||||||
|
Loading…
Reference in New Issue
Block a user