Skip to content

Commit

Permalink
Update the Docker support to the new format.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimaruseac committed Jan 2, 2022
1 parent 1a28bd9 commit 41a9ce1
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 56 deletions.
5 changes: 1 addition & 4 deletions haskell_101/codelab/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Using haskell:8 instead of latest due to deprecation warnings
# on cabal
FROM haskell:8
WORKDIR /codelab
WORKDIR .

# Copy all source files into container
COPY . .

# Build codelab binary
RUN make codelab
75 changes: 51 additions & 24 deletions haskell_101/codelab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,60 @@ To setup your machine please consult [the official haskell website](https://www.

## Running tests

To run the tests first build the binary `make codelab` and then run the binary `./codelab` and you should see output similar to below as you progress through the lab.
To run the tests just run `make` in each of the directories. The special `00_setup` directory is only used for testing the environment, but all others contain exercises to resolve.

For each of the exercises, replace `codelab` with your implementation. When complete, running `make` would result in an output similar to below:
```
### Section 1
add 1 2 [OK] got: 3
subtract 7 2 [OK] got: 5
add 1 2 OK got: 3
subtract 7 2 OK got: 5
double 3 OK got: 6
multiply 3 11 OK got: 33
divide 9 2 OK got: 4.5
divide 8 4 OK got: 2.0
factorial 30 OK got: 265252859812191058636308480000000
gcd 12 4 OK got: 4
gcd 17 7 OK got: 1
```

If you are using the docker container, build and run the tests run with `docker-compose up --build` and you should see output similar to below:

If you are using the docker container, build and run the tests run with `docker-compose run <directory>` (without the trailing slash). For example, for `docker-compose run 01-functions`, you should see output similar to below:
```
Building haskell101
Step 1/4 : FROM haskell:latest
---> 447ebe786704
Step 2/4 : WORKDIR /codelab
---> Using cache
---> 68fdd5afea08
Step 3/4 : COPY . .
---> Using cache
---> 139ffbe127f2
Step 4/4 : RUN make codelab
---> Using cache
---> 56df8c4a8ab5
Successfully built 56df8c4a8ab5
Creating network "codelab_default" with the default driver
Building 01_functions
Step 1/3 : FROM haskell:8
8: Pulling from library/haskell
9b99af5931b3: Pull complete
580a548160a1: Pull complete
5d8e6deeb485: Pull complete
70b0645032d3: Pull complete
03b69c8eaa80: Pull complete
Digest: sha256:d26c7a6853190096137361cfe65f5b7fc6e69ec4660ffb9583ec323e85b524e6
Status: Downloaded newer image for haskell:8
---> 3baac1927856
Step 2/3 : WORKDIR .
---> Running in 7b9c08684455
Removing intermediate container 7b9c08684455
---> bd1bd24a236d
Step 3/3 : COPY . .
---> 5012253dbb4f
Successfully built 5012253dbb4f
Successfully tagged haskell101:latest
Recreating codelab_haskell101_1 ... done
Attaching to codelab_haskell101_1
haskell101_1 | #### Section 1
haskell101_1 | add 1 2 [OK] got: 3
haskell101_1 | subtract 7 2 [OK] got: 5
Creating codelab_01_functions_run ... done
make: Entering directory '/01_functions'
...
Completed 3 action(s).
add 1 2 OK got: 3
subtract 7 2 OK got: 5
double 3 OK got: 6
multiply 3 11 OK got: 33
divide 9 2 OK got: 4.5
divide 8 4 OK got: 2.0
factorial 30 OK got: 265252859812191058636308480000000
gcd 12 4 OK got: 4
gcd 17 7 OK got: 1
make: Leaving directory '/01_functions'
```

Running the first time would result in downloading and compiling needed dependencies (omitted from the above screen output).

When done, you can cleanup Docker services with `docker-compose down`.
29 changes: 27 additions & 2 deletions haskell_101/codelab/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
version: '3'
services:
haskell101:
00_setup:
build: .
image: haskell101:latest
command: "./codelab"
command: make -C 00_setup
01_functions:
build: .
image: haskell101:latest
command: make -C 01_functions
02_datatypes:
build: .
image: haskell101:latest
command: make -C 02_datatypes
03_lists:
build: .
image: haskell101:latest
command: make -C 03_lists
04_abstractions:
build: .
image: haskell101:latest
command: make -C 04_abstractions
05_maybe:
build: .
image: haskell101:latest
command: make -C 05_maybe
06_rps:
build: .
image: haskell101:latest
command: make -C 06_rps
tty: true
8 changes: 1 addition & 7 deletions haskell_102/codelab/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# Using haskell:8 instead of latest due to deprecation warning
# on cabal
FROM haskell:8

# Install codelab dependencies
RUN cabal update && cabal install random
WORKDIR /codelab
WORKDIR .

# Copy all source files into container
COPY . .

# Build all binaries
RUN make
79 changes: 72 additions & 7 deletions haskell_102/codelab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,86 @@ To setup your machine please consult [the official haskell website](https://www.

## Running tests

To run the tests first build the binaries with `make` (or `docker-compose build`) and then run the binary `./test_codelab` (or `docker-compose run codelab_test`) and you should see output similar to below as you progress through the lab.
To run the tests just run `make` in each of the directories. The special `00_setup` directory is only used for testing the environment, but `01_mastermind` contains the full game (with multiple exercises).

There are 5 separate exercises identified by a section number and a corresponding source file. For each of the exercises, running `make ARGS="check <number>"` (eg., `make ARGS="check 1") would display the file that needs to change:
```
#### Section 1
[1.1] allColors contains Red [OK] got: True
[1.1] allColors contains Yellow [OK] got: True
Checking code from src/Color.hs
...
```

## Playing the game
In the file, replace `codelab` with your implementation. When complete, running `make ARGS="check 1"` again would result in an output similar to below:
```
Checking code from src/Color.hs
allColors contains Red OK got: True
allColors contains Yellow OK got: True
allColors contains Green OK got: True
allColors contains Cyan OK got: True
allColors contains Blue OK got: True
allColors contains Magenta OK got: True
allColors size is 6 OK got: 6
show Red OK got: "R"
concatMap show allColors OK got: "RYGCBM"
allColors starts with Red OK got: R
allColors ends with Magenta OK got: M
```

If you are using the docker container, build and run the tests run with `docker-compose run`. To test the setup, run `docker-compose run setup`. To test each section, run `docker-compose run section_<number>`. For example, for `docker-compose run section_1`, you should see output similar to below:
```
Creating network "codelab_default" with the default driver
Building section_1
Step 1/3 : FROM haskell:8
8: Pulling from library/haskell
9b99af5931b3: Pull complete
580a548160a1: Pull complete
5d8e6deeb485: Pull complete
70b0645032d3: Pull complete
03b69c8eaa80: Pull complete
Digest: sha256:d26c7a6853190096137361cfe65f5b7fc6e69ec4660ffb9583ec323e85b524e6
Status: Downloaded newer image for haskell:8
---> 3baac1927856
Step 2/3 : WORKDIR .
---> Running in 7b9c08684455
Removing intermediate container 7b9c08684455
---> bd1bd24a236d
Step 3/3 : COPY . .
---> 5012253dbb4f
Similar to above, to play the game you must first build the binaries with `make` (or `docker-compose build`), and then run the binary `./codelab <play/solve>` (or `docker-compose run codelab_<play/solve>`) and you should see output similar to below.
Successfully built 5012253dbb4f
Successfully tagged haskell101:latest
Creating codelab_section_1_run ... done
make: Entering directory '/01_mastermind'
...
Progress 7/8: codelab
Checking code from src/Color.hs
allColors contains Red OK got: True
allColors contains Yellow OK got: True
allColors contains Green OK got: True
allColors contains Cyan OK got: True
allColors contains Blue OK got: True
allColors contains Magenta OK got: True
allColors size is 6 OK got: 6
show Red OK got: "R"
concatMap show allColors OK got: "RYGCBM"
allColors starts with Red OK got: R
allColors ends with Magenta OK got: M
make: Leaving directory '/01_mastermind'
```

Running the first time would result in downloading and compiling needed dependencies (omitted from the above screen output).

When done, you can cleanup Docker services with `docker-compose down`.

## Playing the game

Once all the five sections have been completed, you can play the game using either `make ARGS=play` or `docker-compose run play`. You can also let an AI solve the game with either `make ARGS=solve` or `docker-compose run solve`. In this case, you should see an output similar to below:
```
Valid colors: [R,Y,G,C,B,M]
Size of the answer: 4
Number of tries: 8
Good luck!
Turn 1:
[R,R,R,R] => black: 3, white: 0
[R,R,R,Y] => black: 3, white: 0
[R,R,R,G] => black: 3, white: 0
[R,R,R,C] => well done!
```
33 changes: 21 additions & 12 deletions haskell_102/codelab/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
version: '3'
services:
codelab_test:
setup:
build: .
image: haskell102:latest
command: "./test_codelab"
codelab_play:
command: make -C 00_setup
section_1:
build: .
image: haskell102:latest
command: "./codelab play"
codelab_solve:
command: make -C 01_mastermind ARGS="check 1"
section_2:
build: .
image: haskell102:latest
command: "./codelab solve"
solution_test:
command: make -C 01_mastermind ARGS="check 2"
section_3:
build: .
image: haskell102:latest
command: "./test_solution"
solution_play:
command: make -C 01_mastermind ARGS="check 3"
section_4:
build: .
image: haskell102:latest
command: "./solution play"
solution_solve:
command: make -C 01_mastermind ARGS="check 4"
section_5:
build: .
image: haskell102:latest
command: "./solution solve"
command: make -C 01_mastermind ARGS="check 5"
play:
build: .
image: haskell102:latest
command: make -C 01_mastermind ARGS=play
tty: true
solve:
build: .
image: haskell102:latest
command: make -C 01_mastermind ARGS=solve

0 comments on commit 41a9ce1

Please sign in to comment.