From 41a9ce113e0530fba300bd12e470c0a8180e2955 Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Sat, 1 Jan 2022 18:08:37 -0800 Subject: [PATCH] Update the Docker support to the new format. --- haskell_101/codelab/Dockerfile | 5 +- haskell_101/codelab/README.md | 75 ++++++++++++++++-------- haskell_101/codelab/docker-compose.yml | 29 +++++++++- haskell_102/codelab/Dockerfile | 8 +-- haskell_102/codelab/README.md | 79 +++++++++++++++++++++++--- haskell_102/codelab/docker-compose.yml | 33 +++++++---- 6 files changed, 173 insertions(+), 56 deletions(-) diff --git a/haskell_101/codelab/Dockerfile b/haskell_101/codelab/Dockerfile index 7ebc074..c8351b5 100644 --- a/haskell_101/codelab/Dockerfile +++ b/haskell_101/codelab/Dockerfile @@ -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 diff --git a/haskell_101/codelab/README.md b/haskell_101/codelab/README.md index b0e234d..e00d7c8 100644 --- a/haskell_101/codelab/README.md +++ b/haskell_101/codelab/README.md @@ -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 ` (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`. diff --git a/haskell_101/codelab/docker-compose.yml b/haskell_101/codelab/docker-compose.yml index d7d108b..8e85bfe 100644 --- a/haskell_101/codelab/docker-compose.yml +++ b/haskell_101/codelab/docker-compose.yml @@ -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 diff --git a/haskell_102/codelab/Dockerfile b/haskell_102/codelab/Dockerfile index 862e69f..d709290 100644 --- a/haskell_102/codelab/Dockerfile +++ b/haskell_102/codelab/Dockerfile @@ -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 diff --git a/haskell_102/codelab/README.md b/haskell_102/codelab/README.md index f9849df..9ab592f 100644 --- a/haskell_102/codelab/README.md +++ b/haskell_102/codelab/README.md @@ -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 "` (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_`. 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 ` (or `docker-compose run codelab_`) 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! ``` diff --git a/haskell_102/codelab/docker-compose.yml b/haskell_102/codelab/docker-compose.yml index 6b64a46..e343ccd 100644 --- a/haskell_102/codelab/docker-compose.yml +++ b/haskell_102/codelab/docker-compose.yml @@ -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