Created
March 6, 2024 13:26
-
-
Save leifermendez/aca138b2aaa2075b4045bb696c15def1 to your computer and use it in GitHub Desktop.
generate-body-container.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { generateExternalApiKey } = require('./generate-external-key'); | |
| const generateBodyContainer = (tenant = {}) => { | |
| const { botName, userId, uuid, openAiKey } = tenant; | |
| const sessions = `${uuid}_sessions` | |
| const EXTERNAL_API_KEY = generateExternalApiKey(userId); | |
| const OPENAI_API_KEY = openAiKey ?? process.env.OPENAI_API_KEY | |
| return { | |
| Name: `${botName.replace(/\s+/g, '')}-${uuid}`, | |
| Image: process.env.CONTAINER_IMAGE, | |
| Env: [ | |
| `OPENAI_API_KEY=${OPENAI_API_KEY}`, | |
| `ID_TENANT=${uuid}`, | |
| `EXTERNAL_API_KEY=${EXTERNAL_API_KEY}`, | |
| `UUID_USER=${userId}` | |
| ], | |
| User: `${process.getuid()}:${process.getgid()}`, | |
| HostConfig: { | |
| PortBindings: { | |
| '4000/tcp': [ | |
| { | |
| HostPort: '3000-3050' | |
| } | |
| ] | |
| }, | |
| Binds: [ | |
| `/root/sessions/${sessions}:/app/${sessions}:rw`, | |
| "/root/tmp:/app/tmp" | |
| ], | |
| CapAdd: ['SYS_ADMIN'] | |
| }, | |
| RestartPolicy: { | |
| Name: 'Always' | |
| } | |
| } | |
| } | |
| module.exports = { | |
| generateBodyContainer | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment