Skip to content

Commit

Permalink
Merge pull request #1 from ShaneMcC/master
Browse files Browse the repository at this point in the history
Add docker.sh for running in docker.
  • Loading branch information
tsumaru720 committed Dec 2, 2018
2 parents 88a9da6 + e318b81 commit 7e53b20
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docker.sh
@@ -0,0 +1,14 @@
#!/bin/bash

IMAGE=tsumaru720/aoc-01

docker image inspect $IMAGE >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "One time setup: building docker image..."
cd docker
docker build . -t $IMAGE
cd ..
fi

docker run --rm -it -v $(pwd):/code $IMAGE /entrypoint.sh $@
13 changes: 13 additions & 0 deletions docker/Dockerfile
@@ -0,0 +1,13 @@
FROM php:7.2-cli

RUN apt-get update \
&& apt-get -y install pypy

ADD entrypoint.sh /entrypoint.sh
ADD runBoth.sh /runBoth.sh
RUN chmod +x /entrypoint.sh /runBoth.sh

USER nobody

CMD /entrypoint.sh
VOLUME /code
21 changes: 21 additions & 0 deletions docker/entrypoint.sh
@@ -0,0 +1,21 @@
#!/bin/bash

YEAR="${1}"
DAY="${2}"

if ! [[ "${YEAR}" =~ ^[0-9]+$ ]]; then
echo 'Invalid Year: '${YEAR};
exit 1;
fi;

if ! [[ "${DAY}" =~ ^[0-9]+$ ]]; then
echo 'Invalid Day: '${DAY};
exit 1;
fi;

if [ ! -e "/code/${YEAR}/${DAY}/" ]; then
echo 'Unknown Year/Day: '${YEAR}'/'${DAY};
exit 1;
fi;

time /runBoth.sh ${YEAR} ${DAY}
14 changes: 14 additions & 0 deletions docker/runBoth.sh
@@ -0,0 +1,14 @@
#!/bin/bash

YEAR="${1}"
DAY="${2}"

cd /code/${YEAR}/${DAY}/

if [ -e "run.php" ]; then
php run.php 1
php run.php 2
elif [ -e "day${DAY}.py" ]; then
pypy day${DAY}.py 1
pypy day${DAY}.py 2
fi;

0 comments on commit 7e53b20

Please sign in to comment.