Skip to content

Commit

Permalink
changes for c only docker
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencao committed Nov 1, 2023
1 parent 95f9424 commit db12d45
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 24 deletions.
23 changes: 23 additions & 0 deletions docs/c-guide/c-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: CS 2110 Docker for C Only
---

The image is set up to be a very basic Ubuntu 22.04 machine that includes the following tools that you need for this class:
- `gcc` and `gdb`

One thing that it does not include is a text editor. **STUDENTS SHOULD NOT EDIT ANY FILES INSIDE OF THE CONTAINER!** When you write code later in the semester, you will edit the files in your favorite text editor *outside* of the container, and test them inside the container using the tools provided.

# Installation

First, download the latest stable version of one of the CS 2110 Docker scripts down below, and put it in a folder where you want to do all your work for this class.
- [Windows](../files/cs2110docker-c.bat){:download}
- [MacOS/Linux](../files/cs2110docker-c.sh){:download}

Next, you need to install Docker. Please follow the instructions below for your platform:
- [Windows](../install-windows.md)
- [macOS](../install-mac.md)
- [Linux](../install-linux.md)

After you finish installing, check out [Using the CS 2110 Docker Container](using-docker-c.md) and make sure everything is working.

If you run into any issues, please take a look at [Common Issues](../common-issues.md), and also don't hesitate to ask one of your TAs for help!
35 changes: 35 additions & 0 deletions docs/c-guide/using-docker-c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Using the CS 2110 Docker Contaner for C Only
---

When you first start the Docker container, you will still be in the same window that you ran the script from. However, the container is now presenting you with a Linux shell. If you run the command `ls`, you should see a device called `host`, which contains all of the same files and folders as the folder containing your CS 2110 Docker script (`cs2110docker.sh` or `cs2110docker-c.bat`). For instance, if your script is stored in Desktop, then you should see all the contents of your Desktop folder inside `host`. The folder has been *mounted* inside the container, meaning updating the files on your computer will be reflected in the container and vice versa.

You should then see something like this:
![image](assets/dockerit1.png){:.centered}

And then you can move around and interact with the Docker container like in any other termninal:
![image](assets/dockerit2.png){:.centered}


**When you are doing your work, you should edit all of you files in this folder on your host machine. Then, use the Docker container to run the code. DO NOT SAVE FILES INSIDE THE CONTAINER ANYWHERE EXCEPT IN THE `host` FOLDER. THEY WILL DISAPPEAR. PLEASE DON'T DO IT. PLEASE.**

You will not get extensions on projects because you saved stuff where you should not have. We are making this very clear up front. Don't do it.

When you are done using the container, you can shut it down by running

./cs2110docker.sh stop
on MacOS/Linux or

cs2110docker.bat stop
on Windows.

**Note for Windows users**: Docker Desktop on Windows uses a WSL 2 virtual machine to run the Docker container. Stopping the container will not stop the VM, which can eat up a lot of RAM. Therefore, you may also want to run the following command after stopping the container and/or [create a .wslconfig file](../common-issues.md#wslconfig){:target="_blank"}.:

wsl --shutdown


## Wrap up

That's about all that there is to the CS 2110 Docker container setup. If you have any questions or issues, please post on Ed Discussion / Piazza **under the Docker folder**, so we can sort through Docker questions efficiently.

If there is no Docker folder for your section, then please post any Docker questions under "General".
71 changes: 71 additions & 0 deletions docs/files/cs2110docker-c.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@echo off
setlocal enabledelayedexpansion

set release=stable
set imageBaseName=gtcs2110/cs2110docker-c
set imageName=%imageBaseName%:%release%

set description="Run the CS 2110 C Docker Container: cs2110docker.bat [start|stop|help]"


set action=" "
set "arg=%1"
if not defined arg (
set action=start
goto end_if
)
if /i "%arg%"=="start" (
set action=start
goto end_if
)
if /i "%arg%"=="stop" (
set action=stop
goto end_if
)
if /i "%arg%"=="help" (
echo %description%
exit /b 0
)
set "arg=%2"
if defined arg (
echo Error: unrecognized argument %2
exit /b 1
)
:end_if

powershell Get-Process 'com.docker.proxy' > nul
if "%errorlevel%" neq "0" (
echo ERROR: Docker not found. Ensure that Docker is installed and is running before running this script. Refer to the CS 2110 Docker Guide.
exit /b 1
)

echo Found Docker Installation

if "%action%"=="stop" (
for /f "tokens=3" %%A in ('docker images ^| findstr /c:"gtcs2110/cs2110docker-c"') do set imageId=%%A
for /f "tokens=1" %%i in ('docker ps -qf "ancestor=%imageId%"') do (
set containerId=%%i
echo !containerId!
if !containerId!=="" (
echo No existing CS 2110 containers
) else (
docker stop !containerId!
docker rm -f !containerId!
)
)
echo Successfully stopped all CS 2110 containers
exit /b 0
)

echo Pulling down most recent image of %imageName%
docker pull %imageName%
if "%errorlevel%" neq "0" (
echo ERROR: Unable to pull down the most recent image of %imageName%
exit /b 1
)

set currDir=%cd%

if "%action%"=="start" (
docker run --rm -v %currDir%:/cs2110/host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it "%imageName%"
)
115 changes: 115 additions & 0 deletions docs/files/cs2110docker-c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

release="stable"
imageBaseName="gtcs2110/cs2110docker-c"
imageName="${imageBaseName}:${release}"

define() { IFS=$'\n' read -r -d '' "${1}" || true; }

description="Run the CS 2110 C Docker container"

usage_text=""
define usage_text <<'EOF'
USAGE:
./cs2110docker-c.sh [start|stop|-h|--help]
OPTIONS:
start
Start a new nongraphical container in the background. This is the default if no options
are provided.
stop
Stop and remove any running instances of the container.
-h, --help
Show this help text.
EOF

print_help() {
>&2 echo -e "$description\n\n$usage_text"
}

print_usage() {
>&2 echo "$usage_text"
}

action=""
if [ $# -eq 0 ]; then
action="start"
elif [ $# -eq 1 ]; then
case "$1" in
start)
action="start"
;;
stop)
action="stop"
;;
-h|--help)
print_help
exit 0
;;
*)
>&2 echo "Error: unrecognized argument: $1"
>&2 echo ""
print_usage
exit 1
;;
esac
elif [ $# -gt 1 ]; then
>&2 echo "Error: too many arguments"
>&2 echo ""
print_usage
exit 1
fi

if ! docker -v >/dev/null; then
>&2 echo "ERROR: Docker not found. Please install Docker before running this script. Refer to the CS 2110 Docker Guide."
exit 1
fi

if ! docker container ls >/dev/null; then
>&2 echo "ERROR: Docker is not currently running. Please start Docker before running this script."
exit 1
fi

echo "Found Docker Installation"

if [ "$action" = "stop" ]; then
existingContainers=($(docker ps -a | grep "$imageBaseName" | awk '{print $1}'))
echo "${existingContainers[@]}"
if [ "${#existingContainers[@]}" -ne 0 ]; then
echo "Found CS 2110 containers. Stopping and removing them."
docker stop "${existingContainers[@]}" >/dev/null
docker rm "${existingContainers[@]}" >/dev/null
else
echo "No existing CS 2110 containers."
fi

echo "Successfully stopped CS 2110 containers"
exit 0
fi

echo "Pulling down most recent image of $imageName"

if ! docker pull $imageName; then
>&2 echo "ERROR: Unable to pull down the most recent image of $imageName"
fi

echo "Starting up new CS 2110 Docker Container:"

if command -v docker-machine &> /dev/null; then
# We're on legacy Docker Toolbox
# pwd -W doesn't work with Docker Toolbox
# Extra '/' fixes some mounting issues
currDir="/$(pwd)"
else
# pwd -W should correct path incompatibilites on Windows for Docker Desktop users
currDir="/$(pwd -W 2>/dev/null || pwd)"
fi

if [ "$action" = "start" ]; then
if command -v winpty &> /dev/null; then
# Run with winpty when available
winpty docker run --rm -v "$currDir":/cs2110/host/ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it "$imageName"
else
docker run --rm -v "$currDir":/cs2110/host/ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it "$imageName"
fi
fi
20 changes: 4 additions & 16 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
---
title: Welcome to CS 2110!
---
*Guide last updated: August 24, 2022*
*Guide last updated: October 31, 2023*


We have created a Docker image for the students of CS 2110 that contains all of the tools that they will need throughout this course. The image itself is hosted on [Docker Hub](https://hub.docker.com/r/gtcs2110/cs2110docker/){:target="_blank"}, but we have developed a script for you to use so you don't need to worry about that.

The image is set up to be a very basic Ubuntu 20.04 machine that includes the following tools that you need for this class:
- CircuitSim (for circuits)
- complx (for assembly)
- `gcc` and `gdb` (for C)

One thing that it does not include is a text editor. **STUDENTS SHOULD NOT EDIT ANY FILES INSIDE OF THE CONTAINER!** When you write code later in the semester, you will edit the files in your favorite text editor *outside* of the container, and test them inside the container using the tools provided.

# Installation

First, download the [latest stable version of the CS 2110 Docker script](files/cs2110docker.sh){:download}, and put it in a folder where you want to do all your work for this class.

Next, you need to install Docker. Please follow the instructions below for your platform:
- [Windows](install-windows.md)
- [macOS](install-mac.md)
- [Linux](install-linux.md)
### **Note: We have two variations of CS 2110 Docker images for this course. Please select the guide that is applicable to your section of the course!**
- [C Docker container guide](c-guide/c-guide.md)
- [noVNC Docker container guide](novnc-guide/novnc-guide.md)

If you run into any issues, please take a look at [Common Issues](common-issues.md), and also don't hesitate to ask one of your TAs for help!

Expand Down
2 changes: 1 addition & 1 deletion docs/install-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ The installation process should have set the Docker daemon to start on boot, so
5. Run the script by typing `./cs2110docker.sh`.
* This may take a moment if it is your first time running the script, but if everything goes as planned, you should see eventually see the message `Successfully launched CS 2110 Docker container.`

Installation is done, and you have the container up and running! Finally, check out [Using the CS 2110 Docker Container](using-docker.md).
Installation is done, and you have the container up and running! Finally, check out [Using the CS 2110 Docker Container](c-guide/using-docker-c.md).
2 changes: 1 addition & 1 deletion docs/install-mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ If your Mac is older than 2010, please post privately on Ed Discussion / Piazza
6. Run the script by typing `./cs2110docker.sh`.
* This may take a moment if it is your first time running the script, but if everything goes as planned, you should see eventually see the message `Successfully launched CS 2110 Docker container.`

Installation is done, and you have the container up and running! Finally, check out [Using the CS 2110 Docker Container](using-docker.md).
Installation is done, and you have the container up and running! Finally, check out [Using the CS 2110 Docker Container](c-guide/using-docker-c.md).
9 changes: 4 additions & 5 deletions docs/install-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ Docker Desktop only runs on relatively recent builds of Windows:

If you are running an older version and do not want to or cannot update, please ask your TA for help. You can determine your version of Windows by pressing `⊞ Win` + `R`, typing `winver` in the box that shows up, and then hitting Enter.


### Installation Steps
1. Install Git for Windows if you do not already have it, which can
1. (**Skip this step when installing Docker for just C**) Install Git for Windows if you do not already have it, which can
be found at <https://gitforwindows.org/>{:target="_blank"}.
* The Git installation will prompt you for lots of configuration options about Git; if you don't know what an option means, select the default option.

Expand All @@ -33,9 +32,9 @@ be found at <https://gitforwindows.org/>{:target="_blank"}.
* Search for "Windows PowerShell" in the Start Menu, right click it, and select "Run as administrator". Then, run the command `wsl --install`.
* If that fails (some error like `wsl: command not found`, or something about `--install` being an invalid flag), then follow **Steps 1-5 only** of the manual installation instructions found [here](https://docs.microsoft.com/en-us/windows/wsl/install-manual){:target="_blank"}.
6. When the whale in the bottom left of this window is green and says "Running" on hover, Docker is ready to run. If you cannot get Docker for Windows to run at this point, please ask a TA for help.
7. After Docker has started, search for "Git Bash" in the Start Menu, and use `cd` to navigate to the directory in which you put the `cs2110docker.sh` script.
7. After Docker has started, use `cd` to navigate to the directory in which you put the `cs2110docker.bat` script.
* See [Navigating the Terminal](navigating-terminal.md){:target="_blank"} if you are not familiar with how to do this.
8. Run the script by typing `./cs2110docker.sh`.
8. Run the script by typing `cs2110docker.bat`.
* This may take a moment if it is your first time running the script, but if everything goes as planned, you should see eventually see the message `Successfully launched CS 2110 Docker container.`

Installation is done, and you have the container up and running! Finally, check out [Using the CS 2110 Docker Container](using-docker.md).
Installation is done, and you have the container up and running! Finally, check out [Using the CS 2110 Docker Container](c-guide/using-docker-c.md).
7 changes: 7 additions & 0 deletions docs/navigating-terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ Here are some useful commands and examples if you're not familiar or comfortable
* `ls` (list): shows you all the files in your current directory.
* `pwd` (path to working directory): tells you what directory you're currently in.

While you are running the Docker container, you will be working with a Linux Terminal. This will ensure that the commands above stay consistent across systems.

Note: Outside of the Docker container, Windows users might find that the above commands don't work in the Command Prompt. The following are the equivalent for Windows:
* `cd` will have the same functionality
* `dir` will serve the same purpose as `ls`
* `echo %cd%` will serve the same purpose as `pwd`

Also, on most terminals you can use the Tab key to autocomplete file or directory names, which can make it much easier and quicker to navigate if you have a lot of long folder names.
23 changes: 23 additions & 0 deletions docs/novnc-guide/novnc-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: CS 2110 Docker for noVNC
---

The image is set up to be a very basic Ubuntu 22.04 machine that includes the following tools that you need for this class:
- CircuitSim (for circuits)
- complx (for assembly)
- `gcc` and `gdb` (for C)

One thing that it does not include is a text editor. **STUDENTS SHOULD NOT EDIT ANY FILES INSIDE OF THE CONTAINER!** When you write code later in the semester, you will edit the files in your favorite text editor *outside* of the container, and test them inside the container using the tools provided.

# Installation

First, download the [latest stable version of the CS 2110 Docker script](../files/cs2110docker.sh){:download}, and put it in a folder where you want to do all your work for this class.

Next, you need to install Docker. Please follow the instructions below for your platform:
- [Windows](../install-windows.md)
- [macOS](../install-mac.md)
- [Linux](../install-linux.md)

After you finish installing, check out [Using the CS 2110 Docker Container](using-docker-novnc.md) and make sure everything is working.

If you run into any issues, please take a look at [Common Issues](../common-issues.md), and also don't hesitate to ask one of your TAs for help!
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Using the CS 2110 Docker Contaner
title: Using the CS 2110 Docker Contaner with noVNC
---

There are two ways to run the Docker image---using a browser or using a VNC client. When you ran the `cs2110docker.sh` script, the last line outputted a URL, which should be something along the lines of:
Expand Down

0 comments on commit db12d45

Please sign in to comment.