Skip to content

Commit 909461e

Browse files
committed
Add files
1 parent ae16470 commit 909461e

File tree

20 files changed

+572
-0
lines changed

20 files changed

+572
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
workspace/*/.vscode/
2+
workspace/*/bin/
3+
workspace/*/obj/
4+
workspace/*/*.log

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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/fsharp' }}
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/fsharp:latest
24+
cache-from: type=gha
25+
cache-to: type=gha,mode=max
26+
27+
- name: Run Passing Example
28+
run: bin/run passing
29+
30+
- name: Report Image Size
31+
run: |
32+
echo "## Image Size" >> $GITHUB_STEP_SUMMARY
33+
docker image inspect --format '{{.Size}}' ghcr.io/codewars/fsharp:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY

.github/workflows/push-image.yml

Lines changed: 39 additions & 0 deletions
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/fsharp' }}
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@v2
22+
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v2
25+
with:
26+
registry: ghcr.io
27+
username: codewars
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build and push image
31+
uses: docker/build-push-action@v3
32+
with:
33+
context: .
34+
push: true
35+
tags: |
36+
ghcr.io/codewars/fsharp:latest
37+
ghcr.io/codewars/fsharp:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
workspace/bin/
2+
workspace/obj/
3+
workspace/*/*.log

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0
2+
3+
RUN set -ex; \
4+
useradd --create-home -u 9999 codewarrior; \
5+
mkdir -p /workspace; \
6+
chown codewarrior:codewarrior /workspace;
7+
8+
COPY --chown=codewarrior:codewarrior workspace /workspace
9+
10+
RUN set -ex; \
11+
echo "#!/bin/sh" > /usr/bin/fsc; \
12+
echo "dotnet /usr/share/dotnet/sdk/$(dotnet --version)/FSharp/fsc.dll \$@" >> /usr/bin/fsc; \
13+
chmod +x /usr/bin/fsc; \
14+
mkdir -p /opt/nuget/packages; \
15+
mkdir -p /opt/nuget/cache; \
16+
chmod -R o+rw /opt/nuget;
17+
18+
USER codewarrior
19+
ENV USER=codewarrior \
20+
HOME=/home/codewarrior \
21+
DOTNET_CLI_TELEMETRY_OPTOUT=1 \
22+
NUGET_PACKAGES=/opt/nuget/packages \
23+
NUGET_HTTP_CACHE_PATH=/opt/nuget/cache
24+
25+
RUN set -ex; \
26+
cd /workspace; \
27+
dotnet restore; \
28+
# Copy all the necessary files to bin/
29+
dotnet build --no-restore; \
30+
# Remove obj/ to get the verbose output to extract reference paths
31+
rm -rf bin/Debug/net6.0/run.pdb obj; \
32+
# Append reference paths to `cnfig.rsp`
33+
dotnet run --verbosity normal | grep '\-r:' >> config.rsp; \
34+
# Sanity check
35+
fsc @config.rsp Preloaded.fs Solution.fs Tests.fs Program.fs; \
36+
dotnet bin/Debug/net6.0/run.dll; \
37+
# Remove examples
38+
rm Preloaded.fs Solution.fs Tests.fs bin/Debug/net6.0/run.dll;
39+
40+
WORKDIR /workspace

LICENSE

Lines changed: 21 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# fsharp
2+
3+
Container image for F#
4+
5+
## Usage
6+
7+
See [bin/run](./bin/run).
8+
9+
## Building
10+
11+
```bash
12+
docker build -t ghcr.io/codewars/fsharp:latest .
13+
```

bin/run

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
if [ -z "${IMAGE:+x}" ]; then
5+
IMAGE=ghcr.io/codewars/fsharp:latest
6+
fi
7+
8+
W=/workspace
9+
10+
# Create container
11+
# Note that Program.fs must come last
12+
C=$(docker container create --rm -w $W $IMAGE sh -c "fsc @config.rsp Preloaded.fs Solution.fs Tests.fs Program.fs && dotnet run bin/Debug/net6.0/run.dll")
13+
14+
# Copy files from the examples directory
15+
docker container cp examples/${1:-passing}/. $C:$W
16+
17+
# Run tests
18+
docker container start --attach $C

examples/failing/Preloaded.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Preloaded
2+
type Answer = Even | Odd
3+

examples/failing/Solution.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module OddOrEvenKata
2+
3+
open Preloaded
4+
5+
let oddOrEven n = match n % 2 with
6+
| 1 -> Answer.Even
7+
| _ -> Answer.Odd
8+

0 commit comments

Comments
 (0)