Skip to content

Commit 8545abf

Browse files
authored
Merge pull request #6 from monadius/5.0
2 parents 8054aad + 3a492d0 commit 8545abf

29 files changed

+355
-51
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.repository == 'codewars/ocaml' }}
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: docker/setup-buildx-action@v2
15+
16+
- name: Build image
17+
uses: docker/build-push-action@v3
18+
with:
19+
context: .
20+
push: false
21+
# Make the image available in next step
22+
load: true
23+
tags: ghcr.io/codewars/ocaml:latest
24+
cache-from: type=gha
25+
cache-to: type=gha,mode=max
26+
27+
- name: Run Batteries Example
28+
run: bin/run examples/batteries
29+
30+
- name: Run Base Example (with failing tests)
31+
run: bin/run examples/base
32+
33+
- name: Run Domainslib Example
34+
run: bin/run examples/domainslib
35+
36+
- name: Run Zarith Example
37+
run: bin/run examples/zarith
38+
39+
- name: Report Image Size
40+
run: |
41+
echo "## Image Size" >> $GITHUB_STEP_SUMMARY
42+
docker image inspect --format '{{.Size}}' ghcr.io/codewars/ocaml:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY

Dockerfile

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,64 @@
1-
FROM buildpack-deps:bionic
1+
FROM ubuntu:22.04 AS Builder
22

3-
RUN set -ex; \
4-
useradd --create-home codewarrior; \
5-
# TODO Remove symlink in the next version
6-
ln -s /home/codewarrior /workspace;
7-
8-
ENV OPAMROOT=/opt/opam \
9-
OPAMCOLOR=never
3+
ENV OPAMROOT=/opt/ocaml
104

115
RUN set -ex; \
126
mkdir -p $OPAMROOT; \
7+
useradd --create-home codewarrior; \
138
chown codewarrior:codewarrior $OPAMROOT; \
149
apt-get update; \
1510
apt-get install -y --no-install-recommends \
1611
software-properties-common \
17-
m4 \
18-
rsync \
19-
aspcud \
20-
; \
21-
# Needed for opam 2.0
22-
add-apt-repository -y ppa:avsm/ppa; \
12+
libgmp-dev \
13+
opam \
14+
;
15+
16+
USER codewarrior
17+
ENV USER=codewarrior
18+
19+
RUN set -ex; \
20+
opam init -y --shell-setup --disable-sandboxing --compiler=5.0.0;
21+
22+
RUN set -ex; \
23+
opam install -y \
24+
'batteries=3.6.0' \
25+
'base=v0.15.1' \
26+
'domainslib=0.5.0' \
27+
'ocamlbuild=0.14.2' \
28+
'ocamlfind=1.9.6' \
29+
'ounit2=2.2.7' \
30+
'zarith=1.12' \
31+
;
32+
33+
FROM ubuntu:22.04
34+
35+
RUN set -ex; \
2336
apt-get update; \
2437
apt-get install -y --no-install-recommends \
25-
opam \
38+
gcc \
39+
libc6-dev \
40+
libgmp-dev \
2641
; \
2742
rm -rf /var/lib/apt/lists/*;
2843

29-
USER codewarrior
30-
ENV USER=codewarrior \
31-
HOME=/home/codewarrior
44+
COPY --from=builder \
45+
/opt/ocaml/5.0.0/bin/ocamlc.opt \
46+
/opt/ocaml/5.0.0/bin/ocamlopt.opt \
47+
/opt/ocaml/5.0.0/bin/ocamldep.opt \
48+
/opt/ocaml/5.0.0/bin/ocamlbuild \
49+
/opt/ocaml/5.0.0/bin/ocamlfind \
50+
/opt/ocaml/5.0.0/bin/
51+
COPY --from=builder \
52+
/opt/ocaml/5.0.0/lib/ /opt/ocaml/5.0.0/lib/
3253

33-
# --disable-sandboxing is needed to do this in a container witout `--privileged`
34-
RUN opam init -y --compiler=4.07.1 --disable-sandboxing
35-
36-
ENV OPAM_SWITCH_PREFIX=/opt/opam/4.07.1 \
37-
CAML_LD_LIBRARY_PATH=/opt/opam/4.07.1/lib/stublibs \
38-
OCAML_TOPLEVEL_PATH=/opt/opam/4.07.1/lib/toplevel \
39-
PATH=/opt/opam/4.07.1/bin:$PATH
54+
RUN set -ex; \
55+
useradd --create-home codewarrior; \
56+
mkdir -p /workspace; \
57+
chown -R codewarrior:codewarrior /workspace;
4058

41-
RUN opam install -y \
42-
'ounit=2.0.8' \
43-
'batteries=2.9.0' \
44-
'core=v0.11.3' \
45-
;
59+
USER codewarrior
60+
ENV USER=codewarrior \
61+
PATH=/opt/ocaml/5.0.0/bin:$PATH
4662

47-
COPY workspace/test.ml /workspace/test.ml
48-
COPY workspace/_tags /workspace/_tags
63+
COPY --chown=codewarrior:codewarrior workspace/. /workspace/
64+
WORKDIR /workspace

DockerfileAlpine

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
FROM alpine:3.17 AS builder
2+
3+
ENV OPAMROOT=/opt/ocaml
4+
5+
RUN set -ex; \
6+
mkdir -p $OPAMROOT; \
7+
adduser -D codewarrior; \
8+
chown -R codewarrior:codewarrior /opt/ocaml; \
9+
apk update; \
10+
apk add --virtual .build-deps \
11+
build-base \
12+
ocaml-compiler-libs \
13+
gmp-dev \
14+
opam \
15+
;
16+
17+
USER codewarrior
18+
ENV USER=codewarrior
19+
20+
RUN set -ex; \
21+
opam init -y --shell-setup --disable-sandboxing --compiler=5.0.0;
22+
23+
RUN set -ex; \
24+
opam install -y \
25+
'batteries=3.6.0' \
26+
'base=v0.15.1' \
27+
'domainslib=0.5.0' \
28+
'ocamlbuild=0.14.2' \
29+
'ocamlfind=1.9.6' \
30+
'ounit2=2.2.7' \
31+
'zarith=1.12' \
32+
;
33+
34+
FROM alpine:3.17
35+
36+
RUN set -ex; \
37+
apk add --no-cache \
38+
gcc \
39+
gmp-dev \
40+
musl-dev \
41+
;
42+
43+
COPY --from=builder \
44+
/opt/ocaml/5.0.0/bin/ocamlc.opt \
45+
/opt/ocaml/5.0.0/bin/ocamlopt.opt \
46+
/opt/ocaml/5.0.0/bin/ocamldep.opt \
47+
/opt/ocaml/5.0.0/bin/ocamlbuild \
48+
/opt/ocaml/5.0.0/bin/ocamlfind \
49+
/opt/ocaml/5.0.0/bin/
50+
COPY --from=builder \
51+
/opt/ocaml/5.0.0/lib/ /opt/ocaml/5.0.0/lib/
52+
53+
RUN set -ex; \
54+
adduser -D codewarrior; \
55+
mkdir /workspace; \
56+
chown -R codewarrior:codewarrior /workspace;
57+
58+
USER codewarrior
59+
ENV USER=codewarrior \
60+
PATH=/opt/ocaml/5.0.0/bin:$PATH
61+
62+
COPY --chown=codewarrior:codewarrior workspace/. /workspace/
63+
WORKDIR /workspace

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ Container image for OCaml used by CodeRunner.
55
## Usage
66

77
```bash
8-
W=/workspace/
8+
W=/workspace
99
# Create container
10-
C=$(docker container create --rm -w $W ghcr.io/codewars/ocaml:latest \
11-
sh -c 'ocamlbuild -quiet -use-ocamlfind test.native && exec ./test.native')
10+
BUILD="ocamlbuild -quiet -use-ocamlfind cwtest.native"
11+
C=$(docker container create --rm -w $W ghcr.io/codewars/ocaml:latest sh -c "$BUILD && exec ./cwtest.native")
1212

13-
# Write solution and tests in workspace/fixture.ml
14-
# Then copy it inside a container
15-
docker container cp workspace/fixture.ml $C:$W/fixture.ml
13+
# Copy solution and test files
14+
docker container cp ${1:-examples/basic}/. $C:$W
1615

17-
# Run tests
16+
# Start
1817
docker container start --attach $C
1918
```
2019

bin/alpine_build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker build -f DockerfileAlpine -t ocaml:alpine .

bin/alpine_run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export IMAGE=ocaml:alpine
2+
exec "$(dirname "$0")/run" "$@"

bin/build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker build -t ghcr.io/codewars/ocaml:latest .

bin/run

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set -eu
2+
3+
if [ -z "${IMAGE:+x}" ]; then
4+
IMAGE=ghcr.io/codewars/ocaml:latest
5+
fi
6+
7+
W=/workspace
8+
# Create container
9+
BUILD="ocamlbuild -quiet -use-ocamlfind cwtest.native"
10+
C=$(docker container create --rm -w $W $IMAGE sh -c "$BUILD && exec ./cwtest.native")
11+
12+
# Copy files
13+
docker container cp ${1:-examples/basic}/. $C:$W
14+
15+
# Start
16+
docker container start --attach $C

examples/base/preloaded.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
open Base
2+
3+
let print_int_list = Fn.compose Sexp.to_string (sexp_of_list sexp_of_int)

examples/base/solution.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
open Base
2+
3+
let cubes = List.map ~f:Int.(fun x -> x ** 3)

0 commit comments

Comments
 (0)