From 9b376803e1404d83762c1680af511a2c478a20d7 Mon Sep 17 00:00:00 2001 From: shaffar3 Date: Tue, 27 Sep 2022 15:47:41 -0500 Subject: [PATCH 1/6] started docker illinois article --- src/articles/illinois/docker_mac.md | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/articles/illinois/docker_mac.md diff --git a/src/articles/illinois/docker_mac.md b/src/articles/illinois/docker_mac.md new file mode 100644 index 0000000..4d89131 --- /dev/null +++ b/src/articles/illinois/docker_mac.md @@ -0,0 +1,51 @@ +--- +title: Setting Up Your Programming Environment for CS 340 + +date: 2022-09-27 + +authors: +- shaffar3 +--- + + + + + +# Docker Setup Guide for Mac + +To do many of our MPs on M1 macs, we reccomend using docker. Here are the commands you need to run. + +Note: You NEED to press on the docker desktop app for this to work. + +```bash +# Build a light-weight docker: +docker build -t cs340 . + +# Run make clean, make, and run valgrind: +docker run --rm -it -v `pwd`:/mp1 cs340 "make clean" +docker run --rm -it -v `pwd`:/mp1 cs340 "make test" +docker run --rm -it -v `pwd`:/mp1 cs340 "valgrind ./test" +``` +If you want to run without valgrind, simply run +```bash +docker run --rm -it -v `pwd`:/mp1 cs340 "./test" +``` +Replace mp1 with whatever mp your running. +You can run any command that you would normally run on a local system in the quotes as well. + +You must also have docker desktop installed for this to work. Install using this [link](https://docs.docker.com/desktop/install/mac-install/). +We recommend that you also download the docker vscode extension. This will show you graphically what containers and images exist, and allow you to create it. + +## Why Do I Need to Do This When My Windows/Linux Friends Don't Need Docker +The most important problem with M1 macs is that valgrind is currently [not supported](https://valgrind.org/info/platforms.html) (as of 09/2022). As we require memory correctness in our MP's, valgrind is a neccisity. +Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the [security](https://www.dictionary.com/browse/control) of its users. Thus trying to do some semi-sketchy low level stuff like sideloading an unsigned by apple malloc version in MP3 will give you problems. + +## What do these commands do +Like good systems programmers, we never just run terminal commands without actually knowing what they do. Dockers [website](https://docs.docker.com/) has good documentation. +Quickly, Docker has two main things you need to know about in this scenario +1) Image - A file system with packages installed. + + From 3c7adbe6f2bbbe0239f33971c8e0d87f6deffd1b Mon Sep 17 00:00:00 2001 From: shaffar3 Date: Tue, 1 Nov 2022 15:18:44 -0500 Subject: [PATCH 2/6] added docker mac file --- src/articles/illinois/docker_mac.md | 75 ++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/src/articles/illinois/docker_mac.md b/src/articles/illinois/docker_mac.md index 4d89131..8cdd260 100644 --- a/src/articles/illinois/docker_mac.md +++ b/src/articles/illinois/docker_mac.md @@ -16,9 +16,9 @@ h3 { margin-top: 30px; } # Docker Setup Guide for Mac -To do many of our MPs on M1 macs, we reccomend using docker. Here are the commands you need to run. +To do many of our MPs on M1 macs, we hihgly recommend using docker. Here are the commands you need to run. -Note: You NEED to press on the docker desktop app for this to work. +Note: You NEED to start the docker desktop app first for this to work. ```bash # Build a light-weight docker: @@ -40,12 +40,73 @@ You must also have docker desktop installed for this to work. Install using this We recommend that you also download the docker vscode extension. This will show you graphically what containers and images exist, and allow you to create it. ## Why Do I Need to Do This When My Windows/Linux Friends Don't Need Docker -The most important problem with M1 macs is that valgrind is currently [not supported](https://valgrind.org/info/platforms.html) (as of 09/2022). As we require memory correctness in our MP's, valgrind is a neccisity. -Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the [security](https://www.dictionary.com/browse/control) of its users. Thus trying to do some semi-sketchy low level stuff like sideloading an unsigned by apple malloc version in MP3 will give you problems. +The most important problem with M1 macs is that valgrind is currently [not supported](https://valgrind.org/info/platforms.html) (as of 09/2022). As we require memory correctness in our MP's, valgrind is a necessity. +Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the [security](https://www.dictionary.com/browse/control) of its users. Thus trying to do some semi-sketchy low level stuff like sideloading an unsigned by apple malloc implementation in MP3 may give you problems. ## What do these commands do -Like good systems programmers, we never just run terminal commands without actually knowing what they do. Dockers [website](https://docs.docker.com/) has good documentation. -Quickly, Docker has two main things you need to know about in this scenario -1) Image - A file system with packages installed. +Like good systems programmers, we never just run terminal commands without actually knowing what they do. Docker's [website](https://docs.docker.com/) has good documentation. +Quickly, Docker has two main things you need to know about in this scenario. +1) Image - A file system with packages installed. +2) Container - An instance of the image. +### Building Image +An image provides a template that containers use. An image takes long to build, but it will persist so that containers, which are built for short term tasks (and are usually closed after the task is finished) can borrow from the image. Thus an image will have things like valgrind, that will take too long to install on each container, but that every container will use. + +When we run this command, we are telling it to build an image. + + +```c +docker build -t cs340 . +``` + +The -t flag is the image name. + +If you don't provide a -f command to signify the file name, it will assume that you are using the file Dockerfile, in the current directory. + +Here is what a sample Dockerfile looks like (taken from mp2 in fall 2022) +```text +FROM gcc:latest +RUN apt-get update && apt-get install -y valgrind +COPY ./docker/entrypoint.sh / +RUN chmod +x entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +``` + +The FROM command means we are using a base image (essentially a template with some pre-built stuff which we can then modify). In this case we are taking the latest version of gcc, which you can find here https://hub.docker.com/_/gcc. + +To install stuff inside the image so that every container will have packages they can use, we can use the RUN command. "apt-get update" will make sure we have the most recent packages in our list of possible packages to download, and the "apt-get install -y valgrind" installs the valgrind package, which is needed to run autograder runs. + +COPY in the Dockerfile copies files or directories from local to the docker container. + +ENTRYPOINT is a command that runs whenever we start a container (instance) of the container. In our example it is a bash script that we copy into the the root directory of the docker image. We also make sure to change the [permission](https://linuxpip.org/chmod-x-explained-everything-you-need-to-know/) using chmod +x, to allow the docker containers to execute the bash scrpt. + +In our case the entrypoint script only changes the folder to mp2 and prints out a process is running. +```text +#!/bin/bash +cd mp2 + +echo "Running \`$1\` inside of a docker container..." +$1 +``` + +### Running Container + +Once we have the template that the image provides, we are able to start instances of those images known as containers. +Containers (in our case), are designed for one time use. They are also operating on your local file system (in our case), because we mount the docker container to your local file system. Thus you can think of it like running commands on your own filesystem, just using a different operating system. + +For example + +```bash +docker run --rm -it -v `pwd`:/mp1 cs340 "make clean" +``` + +The --rm flag is used so that the container is removed when it is stopped. Otherwise, the container will stay on your system, and once you have too many containers this will take up a lot of unnesseary space. + +The -it flag starts the container in interactive mode. This allows you to make commands while the docker container is running. + +The -v flag performs a bind mount from the docker container to the local. That way your docker container is working on a mounted version of your file system. If we didn't include this or some other mechanism of changing the local files, you files would be gone after the docker container is closed. + +cs340 is the image name. + +The command is then run. MAKE SURE TO USE QUOTES AROUND THE COMMAND!!!!! Otherwise it will be confused that there are multiple different flags it doesn't recognize. From 0c7737bcd4b7e614a77b52b315258585e55d2114 Mon Sep 17 00:00:00 2001 From: shaffar3 Date: Tue, 1 Nov 2022 15:24:13 -0500 Subject: [PATCH 3/6] fixed typo in docker --- src/articles/illinois/docker_mac.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/articles/illinois/docker_mac.md b/src/articles/illinois/docker_mac.md index 8cdd260..d236e0e 100644 --- a/src/articles/illinois/docker_mac.md +++ b/src/articles/illinois/docker_mac.md @@ -16,7 +16,7 @@ h3 { margin-top: 30px; } # Docker Setup Guide for Mac -To do many of our MPs on M1 macs, we hihgly recommend using docker. Here are the commands you need to run. +To do our C MPs on M1 macs, we highly recommend using docker. Here are the commands you need to run. Note: You NEED to start the docker desktop app first for this to work. @@ -93,7 +93,7 @@ $1 ### Running Container Once we have the template that the image provides, we are able to start instances of those images known as containers. -Containers (in our case), are designed for one time use. They are also operating on your local file system (in our case), because we mount the docker container to your local file system. Thus you can think of it like running commands on your own filesystem, just using a different operating system. +Containers (in our case), are designed for one time use. They are also operating on your local file system (in our case), because we mount the docker container to your local file system (using -v flag). Thus you can think of it like running commands on your own filesystem, just using a different operating system. For example @@ -105,7 +105,7 @@ The --rm flag is used so that the container is removed when it is stopped. Other The -it flag starts the container in interactive mode. This allows you to make commands while the docker container is running. -The -v flag performs a bind mount from the docker container to the local. That way your docker container is working on a mounted version of your file system. If we didn't include this or some other mechanism of changing the local files, you files would be gone after the docker container is closed. +The -v flag performs a bind mount from the docker container to the local. That way your docker container is working on your local file system. If we didn't include this or some other mechanism of changing the local files, you files would be gone after the docker container is closed. cs340 is the image name. From aebade8a19d6e31bc63aa1ab91df50bd290a439f Mon Sep 17 00:00:00 2001 From: shaffar3 Date: Tue, 1 Nov 2022 15:38:34 -0500 Subject: [PATCH 4/6] changed ttile --- src/articles/illinois/docker_mac.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/articles/illinois/docker_mac.md b/src/articles/illinois/docker_mac.md index d236e0e..76ba21c 100644 --- a/src/articles/illinois/docker_mac.md +++ b/src/articles/illinois/docker_mac.md @@ -1,5 +1,5 @@ --- -title: Setting Up Your Programming Environment for CS 340 +title: CS 340 Docker Setup Guide for M1 MAC date: 2022-09-27 @@ -14,7 +14,7 @@ main ul > li:last-of-type { margin-bottom: 30px; } h3 { margin-top: 30px; } -# Docker Setup Guide for Mac +# CS 340 Docker Setup Guide for M1 MAC To do our C MPs on M1 macs, we highly recommend using docker. Here are the commands you need to run. From 5d0070c2156e56a3a14963b464ee08e5109c6de3 Mon Sep 17 00:00:00 2001 From: shaffar3 Date: Tue, 1 Nov 2022 15:59:47 -0500 Subject: [PATCH 5/6] fixed more typos with docker_mac.md --- src/articles/illinois/docker_mac.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/articles/illinois/docker_mac.md b/src/articles/illinois/docker_mac.md index 76ba21c..fa88fae 100644 --- a/src/articles/illinois/docker_mac.md +++ b/src/articles/illinois/docker_mac.md @@ -41,7 +41,7 @@ We recommend that you also download the docker vscode extension. This will show ## Why Do I Need to Do This When My Windows/Linux Friends Don't Need Docker The most important problem with M1 macs is that valgrind is currently [not supported](https://valgrind.org/info/platforms.html) (as of 09/2022). As we require memory correctness in our MP's, valgrind is a necessity. -Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the [security](https://www.dictionary.com/browse/control) of its users. Thus trying to do some semi-sketchy low level stuff like sideloading an unsigned by apple malloc implementation in MP3 may give you problems. +Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the [security](https://www.dictionary.com/browse/control) of its users. Thus trying to do some semi-sketchy low level tasks like sideloading an unsigned by apple malloc implementation in MP3 may give you problems. ## What do these commands do Like good systems programmers, we never just run terminal commands without actually knowing what they do. Docker's [website](https://docs.docker.com/) has good documentation. @@ -79,7 +79,7 @@ To install stuff inside the image so that every container will have packages the COPY in the Dockerfile copies files or directories from local to the docker container. -ENTRYPOINT is a command that runs whenever we start a container (instance) of the container. In our example it is a bash script that we copy into the the root directory of the docker image. We also make sure to change the [permission](https://linuxpip.org/chmod-x-explained-everything-you-need-to-know/) using chmod +x, to allow the docker containers to execute the bash scrpt. +ENTRYPOINT is a command that runs whenever we start a container. In our example it is a bash script that we copy into the the root directory of the docker image. We also make sure to change the [permission](https://linuxpip.org/chmod-x-explained-everything-you-need-to-know/) using chmod +x, to allow the docker containers to execute the bash scrpt. In our case the entrypoint script only changes the folder to mp2 and prints out a process is running. ```text @@ -109,4 +109,4 @@ The -v flag performs a bind mount from the docker container to the local. That w cs340 is the image name. -The command is then run. MAKE SURE TO USE QUOTES AROUND THE COMMAND!!!!! Otherwise it will be confused that there are multiple different flags it doesn't recognize. +The command is then run. MAKE SURE TO USE QUOTES AROUND THE ENTIRE COMMAND!!!!! Otherwise it will be confused that there are multiple different flags it doesn't recognize. From 0eb25bb7a647e02ae889eaa5c568f474525f1d80 Mon Sep 17 00:00:00 2001 From: Shahid Ikram Date: Wed, 22 Feb 2023 21:38:13 -0600 Subject: [PATCH 6/6] fixes --- src/articles/illinois/docker_mac.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/articles/illinois/docker_mac.md b/src/articles/illinois/docker_mac.md index fa88fae..ee1e4c0 100644 --- a/src/articles/illinois/docker_mac.md +++ b/src/articles/illinois/docker_mac.md @@ -41,7 +41,7 @@ We recommend that you also download the docker vscode extension. This will show ## Why Do I Need to Do This When My Windows/Linux Friends Don't Need Docker The most important problem with M1 macs is that valgrind is currently [not supported](https://valgrind.org/info/platforms.html) (as of 09/2022). As we require memory correctness in our MP's, valgrind is a necessity. -Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the [security](https://www.dictionary.com/browse/control) of its users. Thus trying to do some semi-sketchy low level tasks like sideloading an unsigned by apple malloc implementation in MP3 may give you problems. +Even if you don't use valgrind, you will find that low-level systems programming on the M1 natively will provide you with many annoyances. Apple is increasingly very concerned about the security of its users. Thus trying to do some semi-sketchy low level tasks like sideloading an unsigned by apple malloc implementation in MP3 may give you problems. ## What do these commands do Like good systems programmers, we never just run terminal commands without actually knowing what they do. Docker's [website](https://docs.docker.com/) has good documentation. @@ -79,7 +79,7 @@ To install stuff inside the image so that every container will have packages the COPY in the Dockerfile copies files or directories from local to the docker container. -ENTRYPOINT is a command that runs whenever we start a container. In our example it is a bash script that we copy into the the root directory of the docker image. We also make sure to change the [permission](https://linuxpip.org/chmod-x-explained-everything-you-need-to-know/) using chmod +x, to allow the docker containers to execute the bash scrpt. +ENTRYPOINT is a command that runs whenever we start a container. In our example it is a bash script that we copy into the the root directory of the docker image. We also make sure to change the [permission](https://linuxpip.org/chmod-x-explained-everything-you-need-to-know/) using chmod +x, to allow the docker containers to execute the bash script. In our case the entrypoint script only changes the folder to mp2 and prints out a process is running. ```text