Browse Source

Add docker stuff

master
Chris Smith 5 years ago
parent
commit
71035550ee
5 changed files with 56 additions and 0 deletions
  1. 1
    0
      .dockerignore
  2. 18
    0
      Dockerfile
  3. 4
    0
      docker/entrypoint.sh
  4. 22
    0
      docker/spliterator.py
  5. 11
    0
      run.sh

+ 1
- 0
.dockerignore View File

@@ -0,0 +1 @@
1
+venv

+ 18
- 0
Dockerfile View File

@@ -0,0 +1,18 @@
1
+FROM pypy:3
2
+
3
+RUN pip3 install numpy
4
+
5
+ADD docker/entrypoint.sh /entrypoint.sh
6
+ADD 2018.ipynb /code/2018.ipynb
7
+ADD data /code/data
8
+ADD docker/spliterator.py /code/spliterator.py
9
+RUN chmod +x /entrypoint.sh && \
10
+    chown -R nobody /code/ && \
11
+    chmod +x /code/spliterator.py
12
+
13
+USER nobody
14
+
15
+WORKDIR /code
16
+RUN pypy3 /code/spliterator.py
17
+
18
+CMD /entrypoint.sh

+ 4
- 0
docker/entrypoint.sh View File

@@ -0,0 +1,4 @@
1
+#!/bin/bash
2
+
3
+cd /code
4
+time pypy3 ${1:-$(find -regex './[0-9]+.py' | sort | tail -n 1)}

+ 22
- 0
docker/spliterator.py View File

@@ -0,0 +1,22 @@
1
+import json
2
+
3
+with open('2018.ipynb', 'r') as f:
4
+    notebook = json.load(f)
5
+    common = ''
6
+    days = {}
7
+
8
+    for cell in notebook['cells']:
9
+        if cell['cell_type'] == 'code':
10
+            day = cell['metadata']['day']
11
+            if day == 0:
12
+                common += ''.join(cell['source']) + '\n'
13
+            else:
14
+                if day not in days:
15
+                    days[day] = common
16
+                days[day] += ''.join(cell['source'][:-1])
17
+                days[day] += f"print({cell['source'][-1]})\n\n"
18
+
19
+    for day, code in days.items():
20
+        with open(f"{day:02}.py", "w") as py:
21
+            print(f'Writing day {day}...')
22
+            py.write(code)

+ 11
- 0
run.sh View File

@@ -0,0 +1,11 @@
1
+#!/bin/bash
2
+
3
+IMAGE=csmith/aoc-2018
4
+
5
+echo "Building docker image..."
6
+docker build . -t $IMAGE
7
+
8
+echo "To manually run without rebuilding:"
9
+echo "   docker run --rm -it $IMAGE /entrypoint.sh $@"
10
+
11
+docker run --rm -it $IMAGE /entrypoint.sh $@