Skip to content

Commit

Permalink
Merge pull request #64 from gradescope/ibrahim/GSC-2257/dockerfile-ex…
Browse files Browse the repository at this point in the history
…ample

Add example Dockerfile for manual docker config
  • Loading branch information
ThaumicMekanism committed Jan 12, 2022
2 parents 98de2fe + eb15b2c commit 53724ac
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/manual_docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ script, the results should be in `/autograder/results/results.json` with the
correct formatting.

Any setup can be done in the Dockerfile, so there is no need for a `setup.sh`
script.
script. You can use one if it's easier though.

Beyond this, there are no other requirements on the structure of your Docker
image, so you can organize it as you wish.

If you're just getting started, you can look at [our sample Dockerfile](https://github.com/gradescope/autograder_samples/tree/master/manual_docker).
This example puts all the autograder source in a `source` directory and uses a
`setup.sh` file similar to the zip file upload method, so it can be a good
transition path for going from a zip file to fully custom Docker builds.

You may also wish to refer to the [Dockerfile reference docs](https://docs.docker.com/engine/reference/builder/).

## Private Docker Hub Repositories

If your Docker Hub repository is private, you'll need to give the user
Expand Down
30 changes: 30 additions & 0 deletions manual_docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# You can change these variables to use a different base image, but
# you must ensure that your base image inherits from one of ours.
# You can also override these at build time with --build-arg flags
ARG BASE_REPO=gradescope/auto-builds
ARG TAG=latest

FROM ${BASE_REPO}:${TAG}

RUN apt-get update && \
apt-get install -y dos2unix && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD source /autograder/source

RUN cp /autograder/source/run_autograder /autograder/run_autograder

# Ensure that scripts are Unix-friendly and executable
RUN dos2unix /autograder/run_autograder /autograder/source/setup.sh
RUN chmod +x /autograder/run_autograder

# Do whatever setup was needed in setup.sh, including installing apt packages
# Cleans up the apt cache afterwards in the same step to keep the image small
RUN apt-get update && \
bash /autograder/source/setup.sh && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# You can also use RUN commands in the Dockerfile to install things
# instead of using a bash script

# The base image defines the CMD and ENTRYPOINT, so don't redefine those
14 changes: 14 additions & 0 deletions manual_docker/source/run_autograder
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

/usr/games/cowsay "Hello, world!"

files_submitted=$(ls /autograder/submission)
num_files_submitted=$(ls /autograder/submission/ | wc -l)

cat > /autograder/results/results.json <<EOF
{
"output": "Good job, you passed! Submitted ${num_files_submitted} files: ${files_submitted}",
"score": 10,
"max_score": 10
}
EOF
1 change: 1 addition & 0 deletions manual_docker/source/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apt-get install -y cowsay

0 comments on commit 53724ac

Please sign in to comment.