Skip to content

Commit c5468f0

Browse files
committed
Add perl6
1 parent 6475726 commit c5468f0

File tree

6 files changed

+67
-27
lines changed

6 files changed

+67
-27
lines changed

build-langs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,19 @@
22

33
docker pull alpine:edge
44

5-
pwd=`pwd`
5+
cd containers
66

7-
# Perl & Ruby
8-
for lang in perl ruby; do
9-
cd $pwd/containers/$lang
7+
for lang in *; do
8+
mkdir -p $lang/rootfs/old-root
109

11-
docker build -t $lang-build .
10+
docker build -t $lang $lang
1211

13-
id=`docker run -d $lang-build true`
12+
id=`docker run -d $lang -v`
1413

15-
rm -fr rootfs
16-
mkdir -p rootfs/lib rootfs/old-root rootfs/usr/{bin,lib}
14+
docker export $id | tar -C $lang/rootfs -xf -
1715

18-
docker cp $id:/lib/ld-musl-x86_64.so.1 rootfs/lib
19-
docker cp $id:/usr/bin/$lang rootfs/usr/bin
16+
docker rm -f $id
2017

21-
if [ $lang = 'perl' ]; then
22-
docker cp $id:/usr/lib/perl5 rootfs/usr/lib
23-
else
24-
docker cp $id:/usr/lib/$lang rootfs/usr/lib
25-
fi
26-
27-
docker rm $id
18+
# Remove the crap we gained from running the container, this is hacky.
19+
rm -r $lang/rootfs/{.dockerenv,dev,etc,proc,sys}
2820
done
29-
30-
# Cleanup
31-
cd ..
32-
33-
sudo chown -R $USER: */rootfs
34-
35-
find */rootfs/usr/lib -regex '.*\.\(h\|md\|pod\)' -delete

code-golf.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ func runCode(lang, code string) string {
230230
var out bytes.Buffer
231231

232232
cmd := exec.Cmd{
233-
Args: []string{"perl", "/usr/bin/" + lang},
234233
Dir: "containers/" + lang,
235234
Path: "../../run-container",
236235
Stderr: os.Stdout,
@@ -241,6 +240,22 @@ func runCode(lang, code string) string {
241240
},
242241
}
243242

243+
// $binary, @new_argv where $new_argv[0] is used for hostname too.
244+
switch lang {
245+
case "perl6":
246+
cmd.Args = []string{
247+
"/usr/bin/moar",
248+
"perl6",
249+
"--execname=perl6",
250+
"--libpath=/usr/share/nqp/lib",
251+
"--libpath=/usr/share/perl6/runtime",
252+
"/usr/share/perl6/runtime/perl6.moarvm",
253+
"-",
254+
}
255+
default:
256+
cmd.Args = []string{"/usr/bin/" + lang, lang}
257+
}
258+
244259
if err := cmd.Start(); err != nil {
245260
panic(err)
246261
}

containers/perl/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ RUN cd perl-5.26.0 \
1111
-des \
1212
&& make \
1313
&& make install-strip
14+
15+
RUN find /usr/lib/perl5 -regex '.*\.\(h\|pod\)' -delete
16+
17+
FROM scratch
18+
19+
COPY --from=0 /lib/ld-musl-x86_64.so.1 /lib/
20+
COPY --from=0 /usr/bin/perl /usr/bin/
21+
COPY --from=0 /usr/lib/perl5 /usr/lib/perl5
22+
23+
ENTRYPOINT ["/usr/bin/perl"]

containers/perl6/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM alpine:edge
2+
3+
RUN apk add --no-cache curl gcc linux-headers make musl-dev perl
4+
5+
RUN curl http://rakudo.org/downloads/star/rakudo-star-2017.04.tar.gz \
6+
| tar xzf -
7+
8+
RUN cd rakudo-star-2017.04 \
9+
&& perl Configure.pl --backend=moar --gen-moar --prefix=/usr \
10+
&& make install
11+
12+
FROM scratch
13+
14+
COPY --from=0 /lib/ld-musl-x86_64.so.1 /lib/
15+
COPY --from=0 /usr/bin/moar /usr/bin/
16+
COPY --from=0 /usr/lib/libmoar.so /usr/lib/
17+
COPY --from=0 /usr/share/nqp /usr/share/nqp
18+
COPY --from=0 /usr/share/perl6 /usr/share/perl6
19+
20+
ENTRYPOINT ["/usr/bin/moar"]

containers/ruby/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ RUN cd ruby-2.4.1 \
1111
--prefix=/usr \
1212
&& make \
1313
&& make install
14+
15+
RUN find /usr/lib/ruby -name '*.md' -delete
16+
17+
FROM scratch
18+
19+
COPY --from=0 /lib/ld-musl-x86_64.so.1 /lib/
20+
COPY --from=0 /usr/bin/ruby /usr/bin/
21+
COPY --from=0 /usr/lib/ruby /usr/lib/ruby
22+
23+
ENTRYPOINT ["/usr/bin/ruby"]

run-container.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(int argc, char const* const argv[]) {
6060
if (call2(SYS_umount2, "/old-root", MNT_DETACH) < 0)
6161
die("umount");
6262

63-
if (call2(SYS_sethostname, argv[0], strlen(argv[0])) < 0)
63+
if (call2(SYS_sethostname, argv[1], strlen(argv[1])) < 0)
6464
die("host");
6565

6666
if (call1(SYS_setgid, GID_nobody) < 0)
@@ -69,7 +69,7 @@ int main(int argc, char const* const argv[]) {
6969
if (call1(SYS_setuid, UID_nobody) < 0)
7070
die("setuid");
7171

72-
call1(SYS_execve, argv[1]);
72+
call2(SYS_execve, argv[0], argv + 1);
7373
die("exec");
7474

7575
return 0;

0 commit comments

Comments
 (0)