Skip to content

Commit

Permalink
Feat/dockerfile update (#21)
Browse files Browse the repository at this point in the history
* updated tsconfig

Signed-off-by: Ash Entwisle <[email protected]>

* removed misc deps

Signed-off-by: Ash Entwisle <[email protected]>

* docker tweaks

Signed-off-by: Ash Entwisle <[email protected]>

* updated dockerignore

Signed-off-by: Ash Entwisle <[email protected]>

* fixed non-root user to dockerfile

Signed-off-by: Ash Entwisle <[email protected]>

---------

Signed-off-by: Ash Entwisle <[email protected]>
  • Loading branch information
ash-entwisle authored Aug 20, 2023
1 parent a9658cb commit 6b59e3c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules/
docs/
.git/
.env
install/
install/
21 changes: 16 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ ADD https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64.zip bu
# unzip bun binary
RUN unzip bun-linux-x64.zip

# test bun binary
RUN ./bun-linux-x64/bun --version

# start building the main image
FROM frolvlad/alpine-glibc:latest

# install app dependencies
RUN apk add lua5.4
RUN apk add python3
RUN apk add nodejs-current
# deps for eval command, remove if needed # install app dependencies
# RUN apk add lua5.4
# RUN apk add python3
# RUN apk add nodejs-current

# copy bun binary
COPY --from=build /tmp/bun-linux-x64/bun /usr/local/bin/bun

# set app working directory
WORKDIR /usr/src/app
WORKDIR /app/

# Copy app source
COPY . .
Expand All @@ -36,5 +39,13 @@ RUN bun install
# run unit tests
RUN bun test

# add non priviledged user
RUN addgroup -S bot
RUN adduser -S bot -G bot
RUN chown -R bot:bot /app

# switch to non priviledged user
USER bot

# start app
CMD [ "bun", "start" ]
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

services:
openbot:
build: .
volumes:
- ./install/bot-config.toml:/app/config.toml
env_file:
- ./.env
5 changes: 0 additions & 5 deletions src/.dockerignore

This file was deleted.

116 changes: 62 additions & 54 deletions src/commands/misc/eval.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { latency } from '../../libs/sysinfo';
import { embed } from '../../libs/reply';
import { embed, message } from '../../libs/reply';
import { Command, ECommandOption } from '../../libs/command';

export const data = new Command({
Expand Down Expand Up @@ -33,61 +33,69 @@ export const data = new Command({

export async function execute(interaction: any) {

const script = interaction.options.getString('script')
const interpreter = interaction.options.getString('interpreter')
// this command is currently disabled, if you want to use it, uncomment the code below, remove the message at the end and uncomment the dependencies in the dockerfile

let arg = "";
let output = "";
let md = "";

switch (interpreter) {
case "node":
arg = "-e";
md = "js";
break;
case "python":
arg = "-c";
md = "py";
break;
case "sh":
arg = "-c";
md = "sh";
break;
case "lua":
arg = "-e";
md = "lua";
break;
default:
arg = "-e";
break;
}

const startTime = Date.now();

if (script) {
const proc = Bun.spawn([interpreter, arg, script], {
cwd: "./",
env: { ...process.env },
onExit(proc, exitCode, signalCode, error) {
// todo: handle errors
}
});

output = await new Response(proc.stdout).text();
} else {
output = "*No script provided.*";
}

const endTime = Date.now();

embed({
//
// const script = interaction.options.getString('script')
// const interpreter = interaction.options.getString('interpreter')
//
// let arg = "";
// let output = "";
// let md = "";
//
// switch (interpreter) {
// case "node":
// arg = "-e";
// md = "js";
// break;
// case "python":
// arg = "-c";
// md = "py";
// break;
// case "sh":
// arg = "-c";
// md = "sh";
// break;
// case "lua":
// arg = "-e";
// md = "lua";
// break;
// default:
// arg = "-e";
// break;
// }
//
// const startTime = Date.now();
//
// if (script) {
// const proc = Bun.spawn([interpreter, arg, script], {
// cwd: "./",
// env: { ...process.env },
// onExit(proc, exitCode, signalCode, error) {
// // todo: handle errors
// }
// });
//
// output = await new Response(proc.stdout).text();
// } else {
// output = "*No script provided.*";
// }
//
// const endTime = Date.now();
//
// embed({
// interaction: interaction,
// title: `Running with \`${interpreter}\`:`,
// content: `\`\`\`${md}\n${script} \`\`\` \n **Output:** \`\`\` ${output}\`\`\``,
// footer: `Took \`${endTime - startTime}ms\` to Execute. `,
// ephemeral: false,
// timestamp: true,
// });
//
message({
interaction: interaction,
title: `Running with \`${interpreter}\`:`,
content: `\`\`\`${md}\n${script} \`\`\` \n **Output:** \`\`\` ${output}\`\`\``,
footer: `Took \`${endTime - startTime}ms\` to Execute. `,
ephemeral: false,
timestamp: true,
});
content: `This command is currently disabled.`
})
}


Expand Down
29 changes: 17 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
{
"compilerOptions": {
"lib": ["ESNext"],
// add Bun type definitions
"types": ["bun-types"],

// enable latest features
"lib": ["esnext"],
"module": "esnext",
"target": "esnext",

// if TS 5.x+
"moduleResolution": "bundler",
"moduleDetection": "force",
"noEmit": true,
"allowImportingTsExtensions": true,
"moduleDetection": "force",

"jsx": "react-jsx", // support JSX
"allowJs": true, // allow importing `.js` from `.ts`
"esModuleInterop": true, // allow default imports for CommonJS modules

// best practices
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "preserve",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"noEmit": true,
"types": [
"bun-types" // add Bun global
]
"skipLibCheck": true
}
}
}

0 comments on commit 6b59e3c

Please sign in to comment.