Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.12.x series #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .cache/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
projects/
.cache/
45 changes: 35 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,39 @@ RUN apt update
RUN apt install -y ca-certificates curl
RUN apt install -y default-jdk

RUN export PATH="/root/.local/share/coursier/bin:${PATH}"
# Install latest su-exec
# https://gist.github.com/dmrub/b311d36492f230887ab0743b3af7309b
RUN set -ex; \
curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c; \
fetch_deps='gcc libc-dev'; \
apt-get update && \
apt-get install -y --no-install-recommends $fetch_deps \
&& apt-get -y autoremove \
&& apt-get clean autoclean \
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*; \
gcc -Wall \
/usr/local/bin/su-exec.c -o/usr/local/bin/su-exec; \
chown root:root /usr/local/bin/su-exec; \
chmod 0755 /usr/local/bin/su-exec; \
rm /usr/local/bin/su-exec.c; \
apt-get purge -y --auto-remove $fetch_deps \
&& apt-get -y autoremove \
&& apt-get clean autoclean \
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN curl -fL https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz | gzip -d > cs
RUN chmod +x cs
RUN ./cs setup -y
RUN apt install -y gnupg2
RUN echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list
RUN echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | tee /etc/apt/sources.list.d/sbt_old.list
RUN curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add
RUN apt-get update
RUN apt-get install -y sbt
ENV PATH="/root/.local/share/coursier/bin:${PATH}"

RUN curl -fL https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz | gzip -d > /usr/local/bin/cs
RUN chmod +x /usr/local/bin/cs
RUN cs install scala:2.13.8 --dir /usr/share/coursier && cs install --dir /usr/share/coursier scalac:2.13.8
ENV PATH="$PATH:/usr/share/coursier"

RUN curl -L https://github.com/sbt/sbt/releases/download/v1.5.7/sbt-1.5.7.tgz | tar xvz -C /tmp
RUN cp /tmp/sbt/bin/sbt /usr/local/bin/sbt && chmod uga+x /usr/local/bin/sbt

RUN useradd -ms /bin/zsh me
# RUN mkdir /home/me/.cache && chown me:me /home/me/.cache

COPY docker-entrypoint.sh /bin/entrypoint.sh
RUN chmod uga+w /bin/entrypoint.sh
ENTRYPOINT ["/bin/entrypoint.sh"]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
export UID := $(shell id -u)
export GID := $(shell id -g)

build:
docker-compose build

run:
docker-compose run --rm scala bash

push:
docker-compose push scala
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
version: '3.8'
volumes:
cache:
services:
scala:
environment:
- HOST_USER_ID=${UID:-1000}
- HOST_GROUP_ID=${GID:-1000}
build: .
image: ghcr.io/soisy/applied-functional-programming:1
volumes:
- ./projects:/projects
working_dir: /projects
- ./.cache:/home/me/.cache:rw
- ./projects:/home/me/projects
working_dir: /home/me/projects
18 changes: 18 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Get standard cli USER_ID variable
USER_ID=${HOST_USER_ID:-1000}
GROUP_ID=${HOST_GROUP_ID:-1000}
# Change 'me' uid to host user's uid
echo "Running as ${GROUP_ID}:${USER_ID}"

if [ ! -z "$USER_ID" ] && [ "$(id -u me)" != "$USER_ID" ]; then
# Create the user group if it does not exist
groupadd --non-unique -g "$GROUP_ID" me
# Set the user's uid and gid
usermod --non-unique --uid "$USER_ID" --gid "$GROUP_ID" me
fi

# Setting permissions on docker.sock

# zsh shell
su-exec me $@