Skip to content

Commit efe20d5

Browse files
committed
Add container image for the runner
1 parent 690cb11 commit efe20d5

File tree

12 files changed

+1902
-18
lines changed

12 files changed

+1902
-18
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!workspace/
3+
workspace/node_modules/

.github/workflows/publish-image.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Manually trigger image build and push.
2+
# This must be done after publishing a new version of the package
3+
# and updating `workspace/package.json` to use it.
4+
name: Push Image
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: Tag for the new image
10+
required: true
11+
jobs:
12+
build-and-push-image:
13+
if: ${{ github.repository == 'codewars/lambda-calculus' }}
14+
name: Build Images
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v1
24+
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v1
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.repository_owner }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Build and push image
33+
uses: docker/build-push-action@v2
34+
with:
35+
context: .
36+
push: true
37+
tags: |
38+
ghcr.io/${{ github.repository_owner }}/lambda-calculus:latest
39+
ghcr.io/${{ github.repository_owner }}/lambda-calculus:${{ github.event.inputs.tag }}
40+
cache-from: type=gha
41+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM node:16.13-alpine3.15
2+
3+
RUN set -ex; \
4+
adduser -D codewarrior; \
5+
mkdir -p /workspace; \
6+
chown codewarrior:codewarrior /workspace;
7+
8+
COPY --chown=codewarrior:codewarrior workspace/package.json /workspace/package.json
9+
COPY --chown=codewarrior:codewarrior workspace/package-lock.json /workspace/package-lock.json
10+
COPY --chown=codewarrior:codewarrior workspace/files.js /workspace/files.js
11+
12+
USER codewarrior
13+
WORKDIR /workspace
14+
RUN npm install

example/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Minimal example with a solution and tests.
2+
3+
Use `./test.sh` to run this in a container.

example/solution.lc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Kacarott
2+
3+
true = \ a b . a
4+
false = \ a b . b
5+
6+
zero = false
7+
succ = \ n f x . f (n f x)
8+
9+
y = \ f . (\ x . f (x x)) (\ x . f (x x))
10+
11+
counter = y (\ count n b . b (count (succ n)) (n) ) zero

example/test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { assert, config as chaiConfig } from "chai";
2+
chaiConfig.truncateThreshold = 0;
3+
4+
import * as LC from "@codewars/lambda-calculus";
5+
import { solution } from "./files.js"; // /workspace/files.js
6+
7+
LC.config.purity = "Let";
8+
LC.config.numEncoding = "Church";
9+
const toInt = LC.toIntWith(LC.config);
10+
const { counter } = LC.compile(solution());
11+
12+
const T = t => _ => t;
13+
const F = _ => f => f;
14+
15+
describe("counter", () => {
16+
it("fixed tests", () => {
17+
assert.strictEqual(toInt(counter(T)(T)(T)(F)), 3);
18+
assert.strictEqual(toInt(counter(T)(F)), 1);
19+
assert.strictEqual(toInt(counter(T)(T)(T)(T)(T)(T)(T)(F)), 7);
20+
});
21+
});

example/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Test example in a container similar to the runner
3+
W=/workspace/
4+
C=$(docker container create --rm -w $W ghcr.io/codewars/lambda-calculus:latest npx mocha)
5+
docker container cp ./solution.lc $C:$W
6+
docker container cp ./test.js $C:$W
7+
docker container start --attach $C

kata/submit-tests.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

workspace/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The `/workspace` directory where the submitted solution is tested in.
2+
3+
```text
4+
├─ files.js a wrapper module to load submitted solution and preloaded
5+
├─ preloaded.lc optional preloaded file
6+
├─ solution.lc submitted solution file
7+
└─ test.js tests
8+
```
9+
10+
See `Dockerfile` and `examples/`.

workspace/files.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { readFileSync } from "fs";
2+
3+
const read = (path) => readFileSync(new URL(path, import.meta.url), {encoding: "utf8"});
4+
5+
/** Return the contents of the solution file */
6+
export const solution = () => read("./solution.lc");
7+
8+
/** Return the contents of the optional preloaded file */
9+
export const preloaded = () => read("./preloaded.lc");

0 commit comments

Comments
 (0)