diff --git a/.env.example b/.env.example index ee52d25..1b56fd5 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,5 @@ GIPHY_API_KEY= PLANTNET_API_KEY= OMDB_API_KEY= REPLICATE_API_KEY= -MONGODB_URI= \ No newline at end of file +MONGODB_URI= +REGISTER_SLASH_COMMANDS= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9285518..d0cc9f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,38 @@ -FROM node:lts-alpine +################################################ +FROM node:lts-alpine AS base + +# Create user and group +RUN mkdir /app && \ + addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app + +WORKDIR /app + +################################################ +FROM base AS build # Create app directory and copy the app -WORKDIR /app -COPY . . - -# Run as non-root user -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nodejs -u 1001 -RUN chown -R nodejs:nodejs /app -USER nodejs +COPY package*.json tsconfig.json ./ # Install RUN npm install +# Copy the app +COPY src ./src + # Build RUN npm run build +################################################ +FROM node:lts-alpine + +COPY --from=build /app/package*.json ./ +COPY --from=build /app/dist ./dist + +# Install dependencies but skip dev dependencies +RUN npm install --only=production + # Start the app ENTRYPOINT ["npm", "run"] -CMD ["start"] - +CMD ["start"] \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index f8b63dc..ec77fcc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,7 +10,7 @@ interface Config { omdbApiKey: string; replicateApiKey: string; mongodbUri: string; - registerSlashCommands?: boolean; + registerSlashCommands: boolean; } const getEnv = (key: string, required = true): string | boolean | undefined => { @@ -29,7 +29,8 @@ const config: Config = { omdbApiKey: getEnv('OMDB_API_KEY') as string, replicateApiKey: getEnv('REPLICATE_API_KEY') as string, mongodbUri: getEnv('MONGODB_URI') as string, - registerSlashCommands: getEnv('REGISTER_SLASH_COMMANDS', false) as boolean, + registerSlashCommands: + (getEnv('REGISTER_SLASH_COMMANDS', false) as boolean) || false, // Default to false }; export default config;