Skip to content

Commit 9387e46

Browse files
committed
Added docker support
1 parent 6c09131 commit 9387e46

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
yarn-error.log
4+
fiddles

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM node
2+
3+
# SAMPCTL
4+
COPY sampctl-install-deb-sudo.sh /
5+
RUN dpkg --add-architecture i386 && \
6+
apt update && \
7+
apt install -y g++-multilib git ca-certificates && \
8+
sh /sampctl-install-deb-sudo.sh
9+
10+
# FIREJAIL
11+
RUN DEBIAN_FRONTEND=noninteractive apt install -y firejail
12+
13+
# SA-MP PAWN FIDDLE
14+
WORKDIR /usr/src/app
15+
COPY package*.json /usr/src/app/
16+
RUN npm install
17+
18+
WORKDIR /usr/src/app/ui
19+
COPY ./ui/package.json /usr/src/app/ui/
20+
RUN yarn install
21+
22+
WORKDIR /usr/src/app
23+
COPY . .
24+
RUN npm run compile
25+
26+
WORKDIR /usr/src/app/ui
27+
RUN yarn build
28+
29+
WORKDIR /usr/src/app
30+
ENTRYPOINT [ "npm", "start" ]

build.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ const outDir = config.compilerOptions.outDir;
55
s.rm('-rf', outDir);
66
s.mkdir(outDir);
77
s.cp('.env', `${outDir}/.env`);
8-
s.mkdir('-p', `${outDir}/common/swagger`);
9-
s.cp('server/common/swagger/Api.yaml', `${outDir}/common/swagger/Api.yaml`);

sampctl-install-deb-sudo.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# a simple install script for sampctl
3+
4+
ARCH=$(uname -m)
5+
PATTERN="browser_download_url.*386\.deb"
6+
7+
if [ $ARCH = "x86_64" ]; then
8+
PATTERN="browser_download_url.*amd64\.deb"
9+
fi
10+
11+
curl -s https://api.github.com/repos/Southclaws/sampctl/releases/latest |
12+
grep $PATTERN |
13+
cut -d : -f 2,3 |
14+
tr -d \" |
15+
wget -qi - -O tmp.deb
16+
dpkg -i tmp.deb
17+
rm tmp.deb

server/common/fiddle/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default class Fiddle {
161161
};
162162
} catch (ex) {
163163
const stdout: string = ex.stdout.replace('\\n', os.EOL);
164-
const regex: RegExp = /\/.*\/script\.pwn\:(\d)\s\((\w+)\)\s(.*)/g;
164+
const regex: RegExp = /\/.*\/script\.pwn\:(\d+)\s\((\w+)\)\s(.*)/g;
165165
const matches: RegExpMatchArray = stdout.match(regex);
166166

167167
let errors: string[] = [];
@@ -185,7 +185,16 @@ export default class Fiddle {
185185
if (this.process)
186186
return false;
187187

188-
this.process = execa('docker', ['run', '--rm', '-v', `${path.resolve(this.getFiddleRootPath())}:/samp`, 'southclaws/sampctl', 'package', 'run']);
188+
// TODO: Readd docker (docker-in-docker) support to run fiddles in a container
189+
this.process = execa('firejail', [
190+
'--net=none',
191+
'--overlay-tmpfs',
192+
'sampctl',
193+
'package',
194+
'run'
195+
], {
196+
cwd: path.resolve(this.getFiddleRootPath())
197+
});
189198
setTimeout(this.terminate.bind(this, this.process), 2 * 60 * 1000); // 2 Minutes
190199

191200
return true;

0 commit comments

Comments
 (0)