mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-22 16:55:30 +01:00
Optimize docker memory (#976)
This commit is contained in:
parent
c5f8d3373b
commit
d8d72074f2
|
@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Optimized Docker container to run JS code directly with node instead of yarn, npm and tsx. Reduces memory usage.
|
||||||
|
|
||||||
## [2.4.3] - 2023-09-10
|
## [2.4.3] - 2023-09-10
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
19
Dockerfile
19
Dockerfile
|
@ -14,18 +14,29 @@ COPY package.json .
|
||||||
COPY yarn.lock .
|
COPY yarn.lock .
|
||||||
|
|
||||||
RUN yarn install --prod
|
RUN yarn install --prod
|
||||||
|
RUN cp -R node_modules /usr/app/prod_node_modules
|
||||||
|
|
||||||
|
RUN yarn install
|
||||||
|
|
||||||
|
FROM dependencies AS builder
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Run tsc build
|
||||||
|
RUN yarn prisma generate
|
||||||
|
RUN yarn build
|
||||||
|
|
||||||
# Only keep what's necessary to run
|
# Only keep what's necessary to run
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
|
|
||||||
WORKDIR /usr/app
|
WORKDIR /usr/app
|
||||||
|
|
||||||
COPY --from=dependencies /usr/app/node_modules node_modules
|
COPY --from=builder /usr/app/dist ./dist
|
||||||
|
COPY --from=dependencies /usr/app/prod_node_modules node_modules
|
||||||
|
COPY --from=builder /usr/app/node_modules/.prisma/client ./node_modules/.prisma/client
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN yarn prisma generate
|
|
||||||
|
|
||||||
ARG COMMIT_HASH=unknown
|
ARG COMMIT_HASH=unknown
|
||||||
ARG BUILD_DATE=unknown
|
ARG BUILD_DATE=unknown
|
||||||
|
|
||||||
|
@ -34,4 +45,4 @@ ENV NODE_ENV production
|
||||||
ENV COMMIT_HASH $COMMIT_HASH
|
ENV COMMIT_HASH $COMMIT_HASH
|
||||||
ENV BUILD_DATE $BUILD_DATE
|
ENV BUILD_DATE $BUILD_DATE
|
||||||
|
|
||||||
CMD ["tini", "--", "yarn", "start"]
|
CMD ["tini", "--", "node", "--enable-source-maps", "dist/scripts/migrate-and-start.js"]
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
"migrations:run": "npm run prisma:with-env migrate deploy",
|
"migrations:run": "npm run prisma:with-env migrate deploy",
|
||||||
"prisma:with-env": "npm run env:set-database-url prisma",
|
"prisma:with-env": "npm run env:set-database-url prisma",
|
||||||
"env:set-database-url": "tsx src/scripts/run-with-database-url.ts",
|
"env:set-database-url": "tsx src/scripts/run-with-database-url.ts",
|
||||||
"release": "release-it"
|
"release": "release-it",
|
||||||
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@release-it/keep-a-changelog": "^2.3.0",
|
"@release-it/keep-a-changelog": "^2.3.0",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {ChatInputCommandInteraction, EmbedBuilder, PermissionFlagsBits} from 'di
|
||||||
import {injectable} from 'inversify';
|
import {injectable} from 'inversify';
|
||||||
import {prisma} from '../utils/db.js';
|
import {prisma} from '../utils/db.js';
|
||||||
import Command from './index.js';
|
import Command from './index.js';
|
||||||
import {getGuildSettings} from '../utils/get-guild-settings';
|
import {getGuildSettings} from '../utils/get-guild-settings.js';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class implements Command {
|
export default class implements Command {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {inject, injectable} from 'inversify';
|
||||||
import PlayerManager from '../managers/player.js';
|
import PlayerManager from '../managers/player.js';
|
||||||
import Command from '.';
|
import Command from '.';
|
||||||
import {SlashCommandBuilder} from '@discordjs/builders';
|
import {SlashCommandBuilder} from '@discordjs/builders';
|
||||||
import {STATUS} from '../services/player';
|
import {STATUS} from '../services/player.js';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class implements Command {
|
export default class implements Command {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import container from '../inversify.config.js';
|
||||||
import {TYPES} from '../types.js';
|
import {TYPES} from '../types.js';
|
||||||
import PlayerManager from '../managers/player.js';
|
import PlayerManager from '../managers/player.js';
|
||||||
import {getSizeWithoutBots} from '../utils/channels.js';
|
import {getSizeWithoutBots} from '../utils/channels.js';
|
||||||
import {getGuildSettings} from '../utils/get-guild-settings';
|
import {getGuildSettings} from '../utils/get-guild-settings.js';
|
||||||
|
|
||||||
export default async (oldState: VoiceState, _: VoiceState): Promise<void> => {
|
export default async (oldState: VoiceState, _: VoiceState): Promise<void> => {
|
||||||
const playerManager = container.get<PlayerManager>(TYPES.Managers.Player);
|
const playerManager = container.get<PlayerManager>(TYPES.Managers.Player);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import Config from './commands/config.js';
|
||||||
import Disconnect from './commands/disconnect.js';
|
import Disconnect from './commands/disconnect.js';
|
||||||
import Favorites from './commands/favorites.js';
|
import Favorites from './commands/favorites.js';
|
||||||
import ForwardSeek from './commands/fseek.js';
|
import ForwardSeek from './commands/fseek.js';
|
||||||
import Loop from './commands/loop';
|
import Loop from './commands/loop.js';
|
||||||
import Move from './commands/move.js';
|
import Move from './commands/move.js';
|
||||||
import Next from './commands/next.js';
|
import Next from './commands/next.js';
|
||||||
import NowPlaying from './commands/now-playing.js';
|
import NowPlaying from './commands/now-playing.js';
|
||||||
|
|
|
@ -9,11 +9,13 @@ import Prisma from '@prisma/client';
|
||||||
import ora from 'ora';
|
import ora from 'ora';
|
||||||
import {startBot} from '../index.js';
|
import {startBot} from '../index.js';
|
||||||
import logBanner from '../utils/log-banner.js';
|
import logBanner from '../utils/log-banner.js';
|
||||||
import {createDatabasePath} from '../utils/create-database-url.js';
|
import createDatabaseUrl, {createDatabasePath} from '../utils/create-database-url.js';
|
||||||
import {DATA_DIR} from '../services/config.js';
|
import {DATA_DIR} from '../services/config.js';
|
||||||
|
|
||||||
const client = new Prisma.PrismaClient();
|
const client = new Prisma.PrismaClient();
|
||||||
|
|
||||||
|
process.env.DATABASE_URL = process.env.DATABASE_URL ?? createDatabaseUrl(DATA_DIR);
|
||||||
|
|
||||||
const migrateFromSequelizeToPrisma = async () => {
|
const migrateFromSequelizeToPrisma = async () => {
|
||||||
await execa('prisma', ['migrate', 'resolve', '--applied', '20220101155430_migrate_from_sequelize'], {preferLocal: true});
|
await execa('prisma', ['migrate', 'resolve', '--applied', '20220101155430_migrate_from_sequelize'], {preferLocal: true});
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {SongMetadata, STATUS} from './player.js';
|
||||||
import PlayerManager from '../managers/player.js';
|
import PlayerManager from '../managers/player.js';
|
||||||
import {buildPlayingMessageEmbed} from '../utils/build-embed.js';
|
import {buildPlayingMessageEmbed} from '../utils/build-embed.js';
|
||||||
import {getMemberVoiceChannel, getMostPopularVoiceChannel} from '../utils/channels.js';
|
import {getMemberVoiceChannel, getMostPopularVoiceChannel} from '../utils/channels.js';
|
||||||
import {getGuildSettings} from '../utils/get-guild-settings';
|
import {getGuildSettings} from '../utils/get-guild-settings.js';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class AddQueryToQueue {
|
export default class AddQueryToQueue {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {inject, injectable} from 'inversify';
|
import {inject, injectable} from 'inversify';
|
||||||
import * as spotifyURI from 'spotify-uri';
|
import * as spotifyURI from 'spotify-uri';
|
||||||
import {SongMetadata, QueuedPlaylist, MediaSource} from './player';
|
import {SongMetadata, QueuedPlaylist, MediaSource} from './player.js';
|
||||||
import {TYPES} from '../types.js';
|
import {TYPES} from '../types.js';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
import YoutubeAPI from './youtube-api.js';
|
import YoutubeAPI from './youtube-api.js';
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {
|
||||||
} from '@discordjs/voice';
|
} from '@discordjs/voice';
|
||||||
import FileCacheProvider from './file-cache.js';
|
import FileCacheProvider from './file-cache.js';
|
||||||
import debug from '../utils/debug.js';
|
import debug from '../utils/debug.js';
|
||||||
import {getGuildSettings} from '../utils/get-guild-settings';
|
import {getGuildSettings} from '../utils/get-guild-settings.js';
|
||||||
|
|
||||||
export enum MediaSource {
|
export enum MediaSource {
|
||||||
Youtube,
|
Youtube,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {Setting} from '@prisma/client';
|
import {Setting} from '@prisma/client';
|
||||||
import {prisma} from './db';
|
import {prisma} from './db.js';
|
||||||
import {createGuildSettings} from '../events/guild-create';
|
import {createGuildSettings} from '../events/guild-create.js';
|
||||||
|
|
||||||
export async function getGuildSettings(guildId: string): Promise<Setting> {
|
export async function getGuildSettings(guildId: string): Promise<Setting> {
|
||||||
const config = await prisma.setting.findUnique({where: {guildId}});
|
const config = await prisma.setting.findUnique({where: {guildId}});
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"noEmit": true
|
"outDir": "dist"
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
|
|
Loading…
Reference in a new issue