Skip to content

Commit

Permalink
Merge branch 'main' into help50
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Jan 31, 2024
2 parents d96a3d5 + a0a1f58 commit bc67d10
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 31 deletions.
46 changes: 25 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,6 @@ RUN cd /tmp && \
pip3 install --no-cache-dir --upgrade pip


# Install R
# https://docs.posit.co/resources/install-r-source/#build-and-install-r
# https://cran.rstudio.com/src/base/R-4/
RUN sed --in-place "/^#.*deb-src.*universe$/s/^# //g" /etc/apt/sources.list && \
apt update && \
apt build-dep --yes r-base && \
cd /tmp && \
curl --remote-name https://cran.rstudio.com/src/base/R-4/R-4.3.2.tar.gz && \
tar xzf R-4.3.2.tar.gz && \
rm --force R-4.3.2.tar.gz && \
cd R-4.3.2 && \
./configure --enable-memory-profiling --enable-R-shlib && \
make && \
make install && \
cd .. && \
rm --force --recursive R-4.3.2


# Install Ruby 3.2.x
# https://www.ruby-lang.org/en/downloads/
RUN apt update && \
Expand Down Expand Up @@ -201,6 +183,8 @@ RUN apt update && \
libpangocairo-1.0-0 `# For R` \
libtiff5 `# For R` \
libxt6 `# For R` \
libgmp-dev `# For gem` \
libffi-dev `# For gem` \
libyaml-0-2 `# Runtime package for gem` \
man \
man-db \
Expand All @@ -220,14 +204,34 @@ RUN apt update && \
# Install CS50 library
RUN curl https://packagecloud.io/install/repositories/cs50/repo/script.deb.sh | bash && \
apt update && \
apt install --yes libcs50
apt install --yes \
libcs50
# Install Docker CLI
# https://docs.docker.com/engine/install/ubuntu/
# https://docs.docker.com/engine/install/linux-postinstall/
RUN apt update && \
apt install --no-install-recommends --no-install-suggests --yes \
ca-certificates \
curl \
socat && \
install -d /etc/apt/keyrings -m 0755 && \
curl --fail --location --show-error --silent https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt update && \
sudo apt install --no-install-recommends --no-install-suggests --yes \
docker-ce-cli && \
groupadd docker
# Install Python packages
RUN pip3 install --no-cache-dir \
autopep8 \
black \
"check50<4" \
cli50 \
compare50 \
cs50 \
Flask \
Expand Down Expand Up @@ -261,7 +265,8 @@ RUN useradd --home-dir /home/ubuntu --shell /bin/bash ubuntu && \
echo "ubuntu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
echo "Defaults umask_override" >> /etc/sudoers && \
echo "Defaults umask=0022" >> /etc/sudoers && \
sed --expression="s/^Defaults\tsecure_path=.*/Defaults\t!secure_path/" --in-place /etc/sudoers
sed --expression="s/^Defaults\tsecure_path=.*/Defaults\t!secure_path/" --in-place /etc/sudoers && \
usermod --append --groups docker ubuntu
# Version the image (and any descendants)
Expand All @@ -272,7 +277,6 @@ ONBUILD ARG VCS_REF
ONBUILD RUN echo "$VCS_REF" >> /etc/issue
ONBUILD USER ubuntu
# Set user
USER ubuntu
WORKDIR /home/ubuntu
Expand Down
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
ifeq ($(shell uname -m), arm64)
TAG := arm64
else
TAG := amd64
endif

.PHONY: default
default: run

build:
docker build --build-arg VCS_REF="$(shell git rev-parse HEAD)" --tag cs50/cli .
$(MAKE) squash
docker build --build-arg TAG=$(TAG) --build-arg VCS_REF=$(shell git rev-parse HEAD) --tag cs50/cli:$(TAG) .

depends:
pip3 install docker-squash

rebuild:
docker build --no-cache --tag cs50/cli .
$(MAKE) squash
docker build --build-arg TAG=$(TAG) --build-arg VCS_REF=$(shell git rev-parse HEAD) --no-cache --tag cs50/cli:$(TAG) .

run:
docker run --env LANG="$(LANG)" --interactive --publish-all --rm --security-opt seccomp=unconfined --tty --volume "$(PWD)":/home/ubuntu cs50/cli bash --login || true
docker run --env LANG=$(LANG) --env LOCAL_WORKSPACE_FOLDER="$(PWD)" --interactive --publish-all --rm --security-opt seccomp=unconfined --tty --volume "$(PWD)":/mnt --volume /var/run/docker.sock:/var/run/docker-host.sock --workdir /mnt cs50/cli:$(TAG) bash --login || true

squash: depends
docker images cs50/codespace
docker-squash --tag cs50/cli cs50/cli
docker images cs50/codespace
docker-squash --tag cs50/cli:$(TAG) cs50/cli:$(TAG)
39 changes: 39 additions & 0 deletions etc/init.d/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Adapted from https://github.com/devcontainers/features/blob/main/src/docker-outside-of-docker/install.sh.
# If docker-ce is installed, shadows its own.

SOURCE_SOCKET=/var/run/docker-host.sock
TARGET_SOCKET=/var/run/docker.sock
SOCAT_PID=/tmp/docker.pid

case "$1" in
start)
echo "Starting Docker"
socat UNIX-LISTEN:${TARGET_SOCKET},fork,group=docker,mode=660 UNIX-CONNECT:${SOURCE_SOCKET} & echo "$!" > "$SOCAT_PID"
;;
stop)
echo "Stopping Docker"
kill -9 $(cat "$SOCAT_PID" 2> /dev/null) 2> /dev/null
rm --force "$SOCAT_PID" "$TARGET_SOCKET"
;;
restart)
$0 stop
$0 start
;;
status)
if [[ ! -f "${SOCAT_PID}" ]] || ! ps -p $(cat "$SOCAT_PID" 2> /dev/null) &> /dev/null; then
echo "Docker is not running"
exit 1
else
echo "Docker is running"
exit 0
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit 0
3 changes: 1 addition & 2 deletions etc/profile.d/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ if [ "$(whoami)" != "root" ]; then
alias mv="mv -i"
alias pip="pip --no-cache-dir"
alias python="python -q"
alias R="R --vanilla"
alias rm="rm -i"
alias sudo="sudo " # Trailing space enables elevated command to be an alias

Expand All @@ -41,7 +40,7 @@ if [ "$(whoami)" != "root" ]; then
export PROMPT_COMMAND='history -a' # Store Bash History Immediately

# Java
export JAVA_HOME="/opt/jdk-21.0.1"
export JAVA_HOME="/opt/jdk"

# Make
export CC="clang"
Expand Down
22 changes: 22 additions & 0 deletions opt/cs50/bin/R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

IMAGE=rocker/r-ver

options=(
--interactive
--rm
--volume "$LOCAL_WORKSPACE_FOLDER":/mnt
--workdir /mnt
$IMAGE
R "$@"
)

# If TTY
if [[ -t 0 ]]; then
options=(--tty "${options[@]}")
docker run "${options[@]}"

# If pipe
else
cat | docker run "${options[@]}"
fi

0 comments on commit bc67d10

Please sign in to comment.