Skip to content

Commit a3a9220

Browse files
committed
Add files
1 parent de485c1 commit a3a9220

File tree

8 files changed

+170
-0
lines changed

8 files changed

+170
-0
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace/fixture.ml

.github/workflows/push-image.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Build and push a Docker image to GitHub Container Registry when
2+
# a new tag is pushed.
3+
name: Push Image
4+
5+
on:
6+
push:
7+
tags:
8+
- "*"
9+
10+
jobs:
11+
build-and-push-image:
12+
if: ${{ github.repository == 'codewars/ocaml' }}
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v1
22+
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v1
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.repository_owner }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build and push image
31+
uses: docker/build-push-action@v2
32+
with:
33+
context: .
34+
push: true
35+
tags: |
36+
ghcr.io/${{ github.repository }}:latest
37+
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max

Dockerfile

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM buildpack-deps:bionic
2+
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
10+
11+
RUN set -ex; \
12+
mkdir -p $OPAMROOT; \
13+
chown codewarrior:codewarrior $OPAMROOT; \
14+
apt-get update; \
15+
apt-get install -y --no-install-recommends \
16+
software-properties-common \
17+
m4 \
18+
rsync \
19+
aspcud \
20+
; \
21+
# Needed for opam 2.0
22+
add-apt-repository -y ppa:avsm/ppa; \
23+
apt-get update; \
24+
apt-get install -y --no-install-recommends \
25+
opam \
26+
; \
27+
rm -rf /var/lib/apt/lists/*;
28+
29+
USER codewarrior
30+
ENV USER=codewarrior \
31+
HOME=/home/codewarrior
32+
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
40+
41+
RUN opam install -y \
42+
'ounit=2.0.8' \
43+
'batteries=2.9.0' \
44+
'core=v0.11.3' \
45+
;
46+
47+
COPY workspace/test.ml /workspace/test.ml
48+
COPY workspace/_tags /workspace/_tags

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Qualified
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# OCaml Image
2+
3+
Container image for OCaml used by CodeRunner.
4+
5+
## Usage
6+
7+
```bash
8+
W=/workspace/
9+
# 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')
12+
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
16+
17+
# Run tests
18+
docker container start --attach $C
19+
```
20+
21+
## Building
22+
23+
```bash
24+
docker build -t ghcr.io/codewars/ocaml:latest .
25+
```

workspace/_tags

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<test.ml> : package(oUnit), use_str
2+
<fixture.ml> or <test.native> : package(oUnit), package(batteries), package(core), thread

workspace/fixture.ml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(* TODO Avoid concatenating in the next version *)
2+
let add x y = x + y;;
3+
4+
module Tests = struct
5+
open OUnit
6+
let test1 test_ctxt = assert_equal 2 (add 1 1);;
7+
let suite = ["1+1 is 2" >:: test1];;
8+
end

workspace/test.ml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
open OUnit
2+
3+
let _esc_lf s =
4+
s |> Str.global_replace (Str.regexp_string "\n") "<:LF:>";;
5+
6+
(* TODO Fix missing `<COMPLETEDIN::>` *)
7+
let cw_print_test_event = function
8+
| EStart (name::rest) -> print_endline ("\n<IT::>" ^ string_of_node name)
9+
| EResult result ->
10+
begin match result with
11+
| RSuccess _ -> print_endline ("\n<PASSED::>Test passed")
12+
| RFailure (_, err) -> print_endline ("\n<FAILED::>" ^ (_esc_lf err))
13+
| RError (_, err) -> print_endline ("\n<ERROR::>" ^ (_esc_lf err))
14+
| _ -> ()
15+
end
16+
| _ -> ()
17+
18+
let run_test = function
19+
| TestLabel (name, suite) -> begin
20+
print_endline ("\n<DESCRIBE::>" ^ name);
21+
perform_test cw_print_test_event suite
22+
end
23+
| suite -> perform_test cw_print_test_event suite
24+
25+
(* Solution and Tests are concatenated to `fixture.ml` *)
26+
let _ = List.map run_test Fixture.Tests.suite |> ignore

0 commit comments

Comments
 (0)