Author SHA1 Message Date
John Colvin 4bb5100ef0 chore: Remove redundant sqlite3 zip
No need to keep this release in source control, the apt pkg meets our
requirements
2023-04-01 09:55:09 -04:00
John Colvin 81567b1f82 feat: Add dev Dockerfile & scripts to integrate w/ devcontainers 2023-03-31 04:59:33 +00:00
John Colvin 7f5fc417c2 feat: Add flag to allow docker to mount existing dirs 2023-03-26 13:43:56 -04:00
John Colvin a91f31d1f6 improvement: Improve help text in start_docker.sh 2023-03-26 13:43:56 -04:00
John Colvin 71084aac23 style: Clean up start_docker.sh
* Address syntax issues exposed by linter
2023-03-26 13:43:56 -04:00
John Colvin c586473a8b improvement: Expose ports for sparkd in docker container
So the container can use virtual network adaptors, rather than shared
the host's network stack. This allows us to run sparkd in a docker in
WSL.
2023-03-26 13:43:56 -04:00
John Colvin e191612f42 improvement: Automatically install emumba deps
When creating/starting new containers
2023-03-26 13:43:56 -04:00
John Colvin e30e3164cb improvement: Add user in container (not image)
This way the image isn't tethered to a particular user
2023-03-26 13:43:48 -04:00
John Colvin f3a7217661 fix: Install proper versions of build deps
* Installs clang-13, g++-11, and dotnet7
* Sets up ccache symlinks for compilers to speed up repeated builds
2023-03-25 10:37:44 -04:00
John Colvin 56c61231f3 Upgrade ubuntu to latest LTS (22.10)
This is a big upgrade, from 18.04!
2022-10-04 13:49:25 -05:00
John Colvin 6537812262 Upgrade gcc to v11 2022-09-21 00:09:12 -05:00
John Colvin 823bdd85e4 Upgrade libllvm pkgs to v10 (same as clang) 2022-09-21 00:09:12 -05:00
johncolvin-og 22f9b7bc9a Upgrade pip before installing py pkgs 2022-09-21 00:09:12 -05:00
johncolvin-og 73e1a3a596 Install cmake without 'sudo' cmd
It's unnecessary, and furthermore, the sudo cmd isn't installed until after cmake
2022-09-21 00:09:12 -05:00
johncolvin-og 03c84954ff Install software-properties-common before running its cmds
e.g., apt-add-repository, apt-key
2022-09-21 00:09:12 -05:00
John Colvin 42916b0142 Use fixuid to resolve user perm conflicts in mounted dirs
It matches the user permissions in the container to those in the host. This has
clear advantages to our previous solution, which matched the permissions in the
image. One immediate benefit is that the jenkins server-build node can pull the
image from Docker Hub, rather than build it on the host (for each build, to
ensure the image is up-to-date).
2022-09-21 00:09:12 -05:00
John Colvin 191d74b404 Add ccapi_cpp deps to docker
* Add rapidjson-dev
* Add Kitware repo to get latest cmake (the ccapi_cpp lib relies on
  'add_compile_definitions', which was introduced in cmake 3.12)
2022-06-08 14:40:44 -04:00
John Colvin c3630582cc Upgrade dotnet-sdk to 6.0 2022-04-21 13:41:25 -04:00
John Colvin 05967d0f18 Mount host's sparkdata dir in docker 2021-12-29 21:58:21 -05:00
John Colvin eee74d82b2 fix: Change update-alternative calls to use clang-10 (not 9)
This fixes the docker image build (all clang tools were recently
upgraded from v9 to 10)
2021-12-29 16:05:19 -05:00
John Colvin 4744ddc633 Add script to start docker container 2021-12-29 16:05:19 -05:00
John Colvin 713cdf165e Upgrade compiler to clang-10 2021-12-11 15:50:41 -05:00
John Colvin 8fbd35654e Re-install pkg-config after installing onload
This is a workaround for what appears to be a dependency conflict
related to onload
2021-12-10 14:33:32 -06:00
John Colvin f2e2963489 Add python3-venv to docker 2021-12-10 14:30:32 -06:00
John Colvin 54c0c16d3b Install latest npm (outside of apt repo)
This resolves a dependency conflict between libssl-dev and the npm
available in apt standard repos
2021-11-06 10:42:50 -05:00
John Colvin 4000d62710 Add emumba deps to Dockerfile 2021-11-02 13:54:36 -05:00
John Colvin 117143d9e1 style: Clean up Dockerfile
* Add labels
* Indent command chains
2021-11-02 12:54:26 -05:00
John Colvin f1d398ba81 Add docker_user and password args to Dockerfile
Symlinking /etc/passwd files leads to invalid cross-device link errors
when running apt commands.

Internally, apt uses dpkg, which adds a user "irc" when performing apt
installs/upgrades.  This subprocess leads to the error.

The solution implemented here creates a user with the same name and id
as the current user.  This gives both users the the same file permissions,
without having to symlink /etc/passwd.
2021-10-10 14:20:07 -04:00
John Colvin fc316243c2 Use /bin/bash instead of /bin/sh
The docker build was failing because /bin/sh doesn't exist.
Did the base image change?
2021-10-10 14:03:53 -04:00
John Colvin dd4ca356d4 Get rid of rtags and cgdb
I don't think anyone actually uses this
2021-10-10 14:00:25 -04:00
11 changed files with 837 additions and 254 deletions

No files matched your search

+79 -253
View File
@@ -1,263 +1,89 @@
FROM ubuntu:bionic
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
gnupg \
software-properties-common \
wget
FROM ubuntu:22.10
RUN \
echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main" >> /etc/apt/sources.list && \
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key > llvm_key && apt-key add llvm_key
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
clang-13 \
clang-format-13 \
clangd-13 \
clang-15 \
clang-format-15 \
clangd-15 \
cmake \
curl \
dotnet7 \
fish \
g++-11 \
g++-12 \
gnupg \
liblttng-ust-dev \
libssh2-1-dev \
libpcap0.8-dev \
locales \
ninja-build \
nodejs \
npm \
openssh-server \
python3-pip \
python3-venv \
rapidjson-dev \
software-properties-common \
sqlite3 \
sudo \
tar \
vim \
wget
# Add Kitware repo to get latest cmake
# this is done here so that ccache sees clang++ installed, not clang-10
RUN \
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add - && \
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' && \
apt update
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y ccache
# emumba deps
RUN \
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
libllvm-9-ocaml-dev libllvm9 llvm-9 llvm-9-dev llvm-9-doc llvm-9-examples llvm-9-runtime \
clang-9 clang-tools-9 clang-9-doc libclang-common-9-dev libclang-9-dev libclang1-9 clang-format-9 python-clang-9 clangd-9 \
libfuzzer-9-dev \
lldb-9 \
lld-9 \
libc++-9-dev libc++abi-9-dev \
autoconf \
automake \
bsdmainutils \
cmake \
curl \
libunwind8 \
flex \
bison \
autopoint \
gettext \
g++ \
gcc \
gdb \
git \
glibc-source \
htop \
iputils-ping \
libc6-dbg \
liblttng-ust-dev \
libncurses5-dev \
libreadline-dev \
libtool \
libz-dev \
locales \
lttng-modules-dkms \
lttng-tools \
make \
nano \
net-tools \
ninja-build \
openssh-server \
pkg-config \
python-pip \
python3-pip \
python3-venv \
screen \
silversearcher-ag \
sudo \
tcl \
tcsh \
texinfo \
tmux \
tree \
unzip \
uuid-dev \
vim \
tcpdump \
valgrind \
tzdata \
npm \
nodejs \
rsync \
datamash \
hwloc \
strace \
sshpass \
libssh2-1-dev \
# temporary mono dependency until .net core 2.1
mono-runtime \
libfsharp-core4.3-cil \
libmono-system-net-http4.0-cil \
mono-reference-assemblies-4.0 \
bash-completion \
libpq-dev \
libpqxx-dev \
zip \
parallel \
patchelf \
# aws tools
awscli \
&& rm -rf /var/lig/apt/lists/*
run \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-9 100; \
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-9 100; \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-9 100; \
update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-9 100; \
update-alternatives --config clang; \
update-alternatives --config clang++; \
update-alternatives --config clang-format; \
update-alternatives --config clangd
# this is done here so that ccache sees clang++ installed, not clang-9
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y ccache
run pip install pybars3 paramiko mkdocs
run pip3 install paramiko cryptography
run npm install -g npx
# fix locale so we can run tmux
run sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
ENV LANG='en_US.utf8' LANGUAGE='en_US:en' LC_ALL='en_US.utf8' TZ='America/Chicago'
run locale-gen
# expand libc sources
run cd /usr/src/glibc ; tar xvf glibc-*.tar.xz
# setup ssh
RUN mkdir /var/run/sshd && echo 'root:root' | chpasswd && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
# vim friendlier defaults
RUN echo 'set background=dark \n\
set showcmd \n\
set showmatch \n\
set ignorecase \n\
set smartcase \n\
set incsearch \n\
set autowrite \n\
set hidden \n\
set mouse= \n\
imap jj <Esc> \n\
' >> /etc/vim/vimrc
# region NETCORE
# for netcore2 reference https://hub.docker.com/_/microsoft-dotnet-core-sdk
# for netcore3 reference https://github.com/dotnet/dotnet-docker/blob/master/3.0/sdk/bionic/amd64/Dockerfile
# taken from https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install
RUN wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
&& sudo dpkg -i packages-microsoft-prod.deb \
&& sudo apt-get update \
&& sudo apt-get install apt-transport-https -y \
&& sudo apt-get update \
&& sudo apt-get install dotnet-sdk-2.1 -y \
&& sudo apt-get install dotnet-sdk-3.1 -y
# Enable detection of running in a container
ENV DOTNET_RUNNING_IN_CONTAINER=true \
# Enable correct mode for dotnet watch (only mode supported in a container)
DOTNET_USE_POLLING_FILE_WATCHER=true \
# Skip extraction of XML docs - generally not useful within an image/container - helps performance
NUGET_XMLDOC_MODE=skip
# Trigger first run experience by running arbitrary cmd
RUN dotnet help
# Install PowerShell global tool
ENV POWERSHELL_VERSION=7.0.0-preview.4 \
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetCoreSDK-Ubuntu-18.04
RUN curl -SL --output PowerShell.Linux.x64.$POWERSHELL_VERSION.nupkg https://pwshtool.blob.core.windows.net/tool/$POWERSHELL_VERSION/PowerShell.Linux.x64.$POWERSHELL_VERSION.nupkg \
&& powershell_sha512='0fb0167e13560371bffec38a4a87bf39377fa1a5cc39b3a078ddec8803212bede73e5821861036ba5c345bd55c74703134c9b55c49385f87dae9e2de9239f5d9' \
&& echo "$powershell_sha512 PowerShell.Linux.x64.$POWERSHELL_VERSION.nupkg" | sha512sum -c - \
&& mkdir -p /usr/share/powershell \
&& dotnet tool install --add-source / --tool-path /usr/share/powershell --version $POWERSHELL_VERSION PowerShell.Linux.x64 \
&& rm PowerShell.Linux.x64.$POWERSHELL_VERSION.nupkg \
&& ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \
# To reduce image size, remove the copy nupkg that nuget keeps.
&& find /usr/share/powershell -print | grep -i '.*[.]nupkg$' | xargs rm
#vsdbg for remote .net core debugging
RUN wget https://aka.ms/getvsdbgsh -O - 2>/dev/null | /bin/sh /dev/stdin -v latest -l ~/vsdbg
# endregion NETCORE
run DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 dotnet tool install --tool-path /usr/local/bin paket
run chmod +X /usr/local/bin/paket
copy sqlite-version-3.26.0.zip extension-functions.c build_sqlite.sh /
run ./build_sqlite.sh && rm -rf /sqlite-version-3.26.0/
#git-lfs
copy git-lfs /usr/bin/
run chmod +x /usr/bin/git-lfs && git lfs install
##### Onload Stuff #####
# Onload version and its md5sum
ARG ONLOAD_VERSION="201811-u1"
ARG ONLOAD_MD5SUM="357e64862aa4145e49d218fd04e63407"
# When ONLOAD_WITHZF is non-empty, the build includes Solarflare's TCPDirect library.
# Default is to exclude it.
ARG ONLOAD_WITHZF
# 1) Install OpenOnload build dependencies
# 2) Download and verify OpenOnload from Solarflare's site
# 3) Extract, build, and install onload
# 4) Cleanup
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
tzdata \
build-essential \
cmake-curses-gui \
git-all \
doxygen \
python3-sphinx \
graphviz \
libgtest-dev \
libssl-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-test-dev \
libboost-date-time-dev \
zlib1g-dev \
netcat-traditional \
net-tools \
gdb gdbserver \
pkg-config
# set up default executables (update-alternatives)
RUN \
DEBIAN_FRONTEND=noninteractive apt-get update -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ethtool \
gcc-multilib \
libc6-dev-i386 \
libpcap0.8-dev \
libtool-bin \
&& cd /tmp \
## && curl -fSL https://www.openonload.org/download/openonload-${ONLOAD_VERSION}.tgz -o /tmp/openonload-${ONLOAD_VERSION}.tgz \
&& curl -fSL https://github.com/rigtorp/openonload/archive/master.zip -o /tmp/openonload-${ONLOAD_VERSION}.zip \
## && echo "${ONLOAD_MD5SUM} openonload-${ONLOAD_VERSION}.tgz" | md5sum --check \
## && tar -zxf openonload-${ONLOAD_VERSION}.tgz \
&& unzip -a openonload-${ONLOAD_VERSION}.zip \
## && cd /tmp/openonload-${ONLOAD_VERSION} \
&& cd /tmp/openonload-master \
&& cd scripts \
&& ./onload_build --user \
&& ./onload_install --userfiles --nobuild \
&& cd /tmp \
&& rm -rf openonload* \
&& if [ -z ${ONLOAD_WITHZF} ] ; then rm -rf /usr/include/zf /usr/bin/zf_stackdump /usr/bin/zf_debug /usr/lib/x86_64-linux-gnu/zf /usr/lib/x86_64-linux-gnu/libonload_zf* ; fi \
&& DEBIAN_FRONTEND=noninteractive apt-get remove -y --purge \
curl \
patch \
&& DEBIAN_FRONTEND=noninteractive apt-get autoremove -y
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-13 100; \
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-13 100; \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-13 100; \
update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-13 100; \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100; \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
########################
# Add compiler symlinks for ccache
RUN \
ln -s /usr/bin/ccache /usr/local/bin/clang; \
ln -s /usr/bin/ccache /usr/local/bin/clang++; \
ln -s /usr/bin/ccache /usr/local/bin/clang-13; \
ln -s /usr/bin/ccache /usr/local/bin/clang++-13; \
ln -s /usr/bin/ccache /usr/local/bin/clang-15; \
ln -s /usr/bin/ccache /usr/local/bin/clang++-15; \
ln -s /usr/bin/ccache /usr/local/bin/gcc; \
ln -s /usr/bin/ccache /usr/local/bin/g++; \
ln -s /usr/bin/ccache /usr/local/bin/gcc-11; \
ln -s /usr/bin/ccache /usr/local/bin/g++-11; \
ln -s /usr/bin/ccache /usr/local/bin/gcc-12; \
ln -s /usr/bin/ccache /usr/local/bin/g++-12
# build rtags
run \
git clone --recursive https://github.com/Andersbakken/rtags.git && \
cd rtags && \
git submodule update && \
git checkout v2.38 && \
cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=1 . && \
make -j$(nproc) install && \
cd .. && \
rm -rf rtags
# build cgdb (the version shipped with ubuntu is too old)
run \
git clone https://github.com/cgdb/cgdb.git && \
cd cgdb && \
git checkout v0.7.1 && \
./autogen.sh && \
./configure && make -j$(nproc) && \
make install
RUN locale-gen en_US.UTF-8
+95 -1
View File
@@ -1 +1,95 @@
docker build -t bluetradingsystems/linux_docker .
#!/usr/bin/env bash
function print_help_and_exit() {
cat <<EOF
Build the (dev) docker image
Usage: build.sh [OPTIONS]
Options:
-u,--user The user (name) to add to the image (defaults to the current user)
-p,--pass The password for the <--user> in the image (defaults to the username in the image)
-i,--image The name to give the image
-h,--help Print this help message and exit
EOF
exit $1
}
declare docker_user=""
declare docker_pass=""
declare image_name=""
while [[ $# -gt 0 ]]; do
case "$1" in
-i)
;&
--image)
if [[ -z "$2" ]]; then
echo "Image (-i,--image) must be non-empty"
print_help_and_exit 1
fi
image_name="$2"
shift 2
;;
-u)
;&
--user)
if [[ -z "$2" ]]; then
echo "User (-u,--user) must be non-empty"
print_help_and_exit 1
fi
docker_user="$2"
shift 2
;;
-p)
;&
--pass)
if [[ -z "$2" ]]; then
echo "Password (-p,--pass) must be non-empty"
print_help_and_exit 1
fi
docker_pass="$2"
shift 2
;;
-h)
;&
--help)
print_help_and_exit 0
;;
*)
echo "Unexpected argument '$1'"
print_help_and_exit 1
;;
esac
done
if [[ -z "$image_name" ]]; then
image_name="bluetradingsystems/spark-crypto-dev"
echo "Pulling image '$image_name' from Dockerhub (use --image <name> to build a new image)"
docker pull "$image_name"
declare -n pull_status=$?
if [[ $pull_status -ne 0 ]]; then
echo "docker pull exited with code $pull_status"
fi
exit $?
fi
if [[ -z "$docker_user" ]]; then
docker_user="$USER"
fi
if [[ -z "$docker_pass" ]]; then
docker_pass="$docker_user"
echo "Giving user '$docker_user' a secure password: $docker_pass"
fi
echo "Building image
image_name : $image_name
user : $docker_user"
docker build \
--build-arg docker_user=$docker_user \
--build-arg docker_password=$docker_pass \
-t "$image_name" \
.
+14
View File
@@ -0,0 +1,14 @@
FROM johncolvin/bluetradingsystems:spark-dev
ARG docker_user
ARG docker_uid
ARG docker_pass
RUN \
groupadd -g "$docker_uid" "$docker_user" \
&& useradd -u "$docker_uid" -g "$docker_uid" "$docker_user" \
&& usermod --password "$(openssl passwd -1 "$docker_pass")" "$docker_user" \
&& usermod -aG sudo "$docker_user"
# Set the default user
USER $docker_user:$docker_user
+40
View File
@@ -0,0 +1,40 @@
# Spark Dev Container
## How to create a Spark VS Code Devcontainer
<a name="build_image"></a>
## 1. Build the Docker image
Run the script `build.sh` located in this directory to build the image
```
build.sh
```
***Notes***
* Builds an image named `$USER:spark-dev`
* Adds a user to the image with the same name/uid/gid as the current user so
it has proper file permissions in mounted directories
* Run `build.sh --help` to see available options
<a name="gen_devcontainer_json"></a>
## 2. Generate a devcontainer.json
Run the script `gen_devcontainer.sh` located in this directory to create a devcontainer.json file.<br>
***Note:** The file path must be `<repo_dir>/.devcontainer/devcontainer.json`*
```
# Dump `gen_devcontainer.sh` output to devcontainer.json
gen_devcontainer.sh > $workspaceFolder/.devcontainer/devcontainer.json
```
***Notes***
* Mounts the following directories (`<container_path>:<host_path>`):
- `/home/<user>:/home/<user>/.spark-dev/mounts/<container_name>`
- `/home/<user>/spark:/path/to/this/repo`
* Run `gen_devcontainer.sh --help` to see available options
<a name="open_vscode_in_container"></a>
## 3. Open VS Code in Container
1. Launch **VS Code** and open the repo folder on the host machine.
1. Run **Dev Containers: Open Folder in Container** from the command palette.<br>
***Notes**
* The container stops when you close VS Code. All processes, including
`sparkd`, will be suspened until you open the workspace again (or manually
restart the container).
Executable
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/env bash
function print_help_and_exit() {
cat <<EOF
Build the (dev) docker image
Usage: build.sh [OPTIONS]
Options:
-u,--user USER or USER:UID The user to add to the image (defaults to the current user)
-p,--pass The password for the <--user> in the image (defaults to the username in the
image)
-i,--image The name to give the image (defaults to "USER:spark-dev")
-h,--help Print this help message and exit
EOF
exit "$1"
}
declare docker_user=""
declare docker_pass=""
declare image_name=""
declare -i docker_pull=1
while [[ $# -gt 0 ]]; do
case "$1" in
-i)
;&
--image)
if [[ -z "$2" ]]; then
echo "Image (-i,--image) must be non-empty"
print_help_and_exit 1
fi
image_name="$2"
shift 2
;;
-u)
;&
--user)
if [[ -z "$2" ]]; then
echo "User (-u,--user) must be non-empty"
print_help_and_exit 1
fi
docker_user="$2"
shift 2
;;
-p)
;&
--pass)
if [[ -z "$2" ]]; then
echo "Password (-p,--pass) must be non-empty"
print_help_and_exit 1
fi
docker_pass="$2"
shift 2
;;
--no-pull)
docker_pull=0
shift 1
;;
-h)
;&
--help)
print_help_and_exit 0
;;
*)
echo "Unexpected argument '$1'"
print_help_and_exit 1
;;
esac
done
declare -a docker_user_args=($(echo "$docker_user" | sed -e 's/:/ /g'))
case ${#docker_user_args[@]} in
0)
docker_user="$USER"
docker_uid="$(id -u)"
;;
1)
docker_user="${docker_user_args[0]}"
docker_uid="$(id -u)"
;;
2)
docker_user="${docker_user_args[0]}"
docker_uid="${docker_user_args[1]}"
;;
*)
echo "Invalid docker_user: $docker_user"
print_help_and_exit 1
;;
esac
if [[ $docker_pull -eq 1 ]]; then
# Pull the base image from Docker Hub
base_image_name="johncolvin/bluetradingsystems:spark-dev"
echo "Pulling image '$base_image_name' from Docker Hub"
docker pull "$base_image_name"
declare -i pull_status=$?
if [[ $pull_status -ne 0 ]]; then
echo "Docker pull exited with code $pull_status"
exit 1
fi
fi
if [[ -z "$image_name" ]]; then
image_name="${docker_user}:spark-dev"
fi
echo "Building image
image_name : $image_name
user : $docker_user"
if [[ -z "$docker_pass" ]]; then
docker_pass="$docker_user"
echo "Giving user '$docker_user' a secure password: $docker_pass"
fi
docker build \
--build-arg docker_user="$docker_user" \
--build-arg docker_pass="$docker_pass" \
--build-arg docker_uid="$docker_uid" \
-t "$image_name" \
.
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
function print_help_and_exit() {
cat <<EOF
Generate a devcontainer json object for the current workspace.
Usage: gen_devcontainer_json.sh [OPTIONS]
Options:
-u,--user USER The user to add to the image (defaults to the current user)
-i,--image The name to give the image (defaults to "USER:spark-dev")
-h,--help Print this help message and exit
EOF
exit "$1"
}
declare docker_user=""
declare image_name=""
while [[ $# -gt 0 ]]; do
case "$1" in
-i)
;&
--image)
if [[ -z "$2" ]]; then
echo "Image (-i,--image) must be non-empty"
print_help_and_exit 1
fi
image_name="$2"
shift 2
;;
-u)
;&
--user)
if [[ -z "$2" ]]; then
echo "User (-u,--user) must be non-empty"
print_help_and_exit 1
fi
docker_user="$2"
shift 2
;;
-h)
;&
--help)
print_help_and_exit 0
;;
*)
echo "Unexpected argument '$1'"
print_help_and_exit 1
;;
esac
done
if [[ -z "$docker_user" ]]; then
docker_user="$USER"
fi
if [[ -z "$image_name" ]]; then
image_name="${docker_user}:spark-dev"
fi
cat <<EOF
{
"image": "$image_name",
"remoteUser": "$docker_user",
"containerUser": "$docker_user",
"initializeCommand": "mkdir -p $HOME/.spark-dev/mounts/spark-dev",
"workspaceMount": "source=\${localWorkspaceFolder},target=/home/$docker_user/spark,type=bind",
"workspaceFolder": "/home/$docker_user/spark",
"mounts": [
"source=$HOME/.spark-dev/mounts/spark-dev,target=/home/$docker_user,type=bind"
],
}
EOF
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
if [ $# -gt 1 ]; then
echo $2
exit 0
fi
declare image_name="$1"
if [ $# -eq 0 ]; then
declare image_name_cmd="$(realpath $(dirname "$0"))/docker_image_name.fish"
image_name="$(eval $image_name_cmd)"
fi
echo "${USER}s_$image_name"
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
function print_help_and_exit() {
cat <<EOF
Open a shell inside the docker container
Usage: docker_shell.sh [OPTIONS] [CONTAINER]
Options:
-u,--user The user to login with in the container (defaults to the current user)
-c,--container The container name (may also be specified as positional arg)
-h,--help Print this help message and exit
EOF
exit "$1"
}
declare docker_user=""
declare cont_name=""
while [[ $# -gt 0 ]]; do
case "$1" in
-u)
;&
--user)
if [[ -z "$2" ]]; then
echo "User (-u,--user) must be non-empty"
print_help_and_exit 1
fi
docker_user="$2"
shift 2
;;
-h)
;&
--help)
print_help_and_exit 0
;;
-c)
;&
--container)
shift 1
;&
*)
if [[ ! -z "$cont_name" ]]; then
echo "Unexpected argument '$1'"
print_help_and_exit 1
fi
cont_name="$1"
shift 1
;;
esac
done
if [[ -z "$cont_name" ]]; then
echo "Please specify the container ([-c,--container])"
print_help_and_exit 1
fi
if [[ -z "$docker_user" ]]; then
docker_user="$USER"
fi
docker exec -u "$docker_user" -it "$cont_name" bash
Binary file not shown.
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env fish
function print_help_and_exit
echo "\
Start a docker dev container
Usage: start_docker.fish [OPTIONS]
Options:
-i,--image The image to use
-c,--container The name to give the container
-h,--help Print this help message and exit
"
return $argv
end
argparse 'h/help' 'i/image' 'c/container' -- $argv
if set -q _flag_help
print_help_and_exit 0
return 0
end
set pos 1
# Set 'image_name'
set image_name ""
if set -q _flag_image
if test (count $argv) -ge $pos
set image_name "$argv[$pos]"
set pos (math $pos + 1)
if test "$image_name" = ""
echo "Image (-i,--image) must be non-empty"
print_help_and_exit 1
return 1
end
else
echo "Invalid arguments"
print_help_and_exit 1
return 1
end
else
set image_name "bluetradingsystems/spark-crypto-dev"
end
# Set 'cont_name'
set cont_name ""
if set -q _flag_container
if test (count $argv) -ge $pos
set cont_name "$argv[$pos]"
set pos (math $pos + 1)
if test "$cont_name" = ""
echo "Container (-c,--container) must be non-empty"
print_help_and_exit 1
return 1
end
else
echo "Invalid arguments"
print_help_and_exit 1
return 1
end
end
set home_src $HOME/.spark-dev/mounts/$cont_name
set home_tgt $HOME
set repo_src (git rev-parse --show-superproject-working-tree)
set repo_tgt $HOME/(basename $repo_src)
set working_dir $HOME
# Make sure the $home_src dir exists before executing 'docker run' (otherwise
# Docker will automatically create the directory with root ownership).
mkdir -p $home_src
echo "\
Starting container
image_name : $image_name
cont_name : $cont_name
home_src : $home_src
home_tgt : $home_tgt
repo_src : $repo_src
repo_tgt : $repo_tgt
working dir : $working_dir"
docker run \
--net host \
-h (hostname) \
-e "TZ=America/New_York" \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
--name $cont_name \
-v $home_src:$home_tgt \
-v $repo_src:$repo_tgt \
-u (id -u $USER):(id -g $USER) \
-w $working_dir \
--shm-size=4024m \
-t \
-i \
-d \
-e DISPLAY="$DISPLAY" \
"$image_name" \
fixuid bash
+233
View File
@@ -0,0 +1,233 @@
#!/usr/bin/env bash
mount_prefix="$HOME/.spark-dev/mounts"
function print_help_and_exit() {
cat <<EOF
Start a docker dev container
Usage: start_docker.sh [OPTIONS] image container
Positionals:
image The image to instantiate
container The name for the container
Options:
-u,--user USER The user to add in the container (defaults to the current user)
-p,--pass PASS The password for USER in the container (defaults to USER)
-i,--image IMAGE The image to instantiate
-c,--container CONT The name for the container
-m,--mount MOUNT The name for the folder (outside the container) to create/mount to the home
directory in the container. Mount folders are added here: $mount_prefix
--mount-existing Mount the specified dir even if it already exists
--port <cont_port>:<host_port> OR [<cont_port>:<host_port>,...] Port mapping(s). May be
specified multiple times.
-h,--help Print this help message and exit
EOF
exit "$1"
}
declare docker_user=""
declare docker_pass=""
declare image_name=""
declare cont_name=""
declare mount_name=""
declare -i mount_existing=0
declare -a port_mappings=()
while [[ $# -gt 0 ]]; do
case "$1" in
-u)
;&
--user)
if [[ -z "$2" ]]; then
echo "User (-u,--user) must be non-empty"
print_help_and_exit 1
fi
docker_user="$2"
shift 2
;;
-p)
;&
--pass)
if [[ -z "$2" ]]; then
echo "Password (-p,--pass) must be non-empty"
print_help_and_exit 1
fi
docker_pass="$2"
shift 2
;;
-i)
;&
--image)
if [[ -n "$image_name" ]]; then
echo "Unexpected argument '$1'"
print_help_and_exit 1
elif [[ -z "$2" ]]; then
echo "Image (-i,--image) must be non-empty"
print_help_and_exit 1
fi
image_name="$2"
shift 2
;;
-c)
;&
--container)
if [[ -n "$cont_name" ]]; then
echo "Unexpected argument '$1'"
print_help_and_exit 1
elif [[ -z "$2" ]]; then
echo "Container (-c,--container) must be non-empty"
print_help_and_exit 1
fi
cont_name="$2"
shift 2
;;
--port)
# Parse port(s) arg, and append the result to 'port_mappings'
# Note: port(s) may be specified in bracketed notation:
# [a:b,c:d,...,y:z]
next_ports="$(echo "$2" | sed -e 's/\[//g' -e 's/\]//g' -e 's/,/ /g')"
if [[ "${#port_mappings[@]}" -gt 0 ]]; then
next_ports=" $next_ports"
fi
port_mappings+=("$next_ports")
shift 2
;;
-m)
;&
--mount)
if [[ -z "$2" ]]; then
echo "Mount (-m,--mount) must be non-empty"
fi
mount_name="$2"
shift 2
;;
--mount-existing)
mount_existing=1
shift 1
;;
-h)
;&
--help)
print_help_and_exit 0
;;
*)
if [[ -z "$1" ]]; then
echo "Invalid positional argument '$1'"
print_help_and_exit 1
elif [[ -z "$image_name" ]]; then
image_name="$1"
elif [[ -z "$cont_name" ]]; then
cont_name="$1"
else
echo "Unexpected argument '$1'"
print_help_and_exit 1
fi
shift 1
;;
esac
done
if [[ -z "$image_name" ]]; then
image_name="bluetradingsystems/spark-crypto-dev"
fi
host_name="$(hostname)"
if [[ -n "$cont_name" ]]; then
host_name="$host_name.$cont_name"
fi
if [[ -z "$mount_name" ]]; then
mount_name="$cont_name"
fi
if [[ -z "$mount_name" && -z "$cont_name" ]]; then
echo "Please specify mount (-m,--mount) and/or container (-c,--container)"
print_help_and_exit 1
fi
if [[ -z "$docker_user" ]]; then
docker_user="$USER"
fi
home_src=$mount_prefix/$mount_name
home_tgt=$HOME
repo_src=$(git rev-parse --show-superproject-working-tree)
repo_tgt=$HOME/$(basename "$repo_src")
working_dir=$HOME
if [[ $mount_existing -eq 0 && -e "$home_src" ]]; then
# Don't overwrite existing dir (might be mounted in another container)
echo "Mount dir '$home_src' already exists (use --mount-existing to mount an existing directory)"
print_help_and_exit 1
fi
mkdir -p "$home_src"
if [[ "${#port_mappings[@]}" -eq 0 ]]; then
port_mappings=("8000:8000" "8001:8001" "8002:8002" "8003:8003")
fi
# Adapt port_mappings into args for `docker run` by prepending "-p " to each
# item
declare -a docker_port_args=()
for port_mapping in "${port_mappings[@]}"; do
docker_port_args+=("-p $port_mapping")
done
echo "Starting container '$cont_name'
image_name : $image_name
cont_name : $cont_name
home_src : $home_src
home_tgt : $home_tgt
repo_src : $repo_src
repo_tgt : $repo_tgt
working dir : $working_dir
ports : ${port_mappings[*]}
"
# DON'T wrap $docker_port_args in quotes. We want bash to split args by
# whitespace
docker run \
--net bridge \
-h "$host_name" \
-e "TZ=America/New_York" \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
--name "$cont_name" \
-v "$home_src:$home_tgt" \
-v "$repo_src:$repo_tgt" \
-w "$working_dir" \
${docker_port_args[*]} \
--shm-size=4024m \
-t \
-i \
-d \
-e DISPLAY="$DISPLAY" \
"$image_name" \
bash
# Add user w/ same uid and gid as the current user outside of docker, so the
# user inside the docker has file permissions in the mounted dir.
docker_group="$docker_user"
docker_user_uid="$(id -u "$USER")"
docker_user_gid="$(id -g "$USER")"
echo "Adding user in container '$cont_name'
name : $docker_user
uid : $docker_user_uid
gid : $docker_user_gid"
if [[ -z "$docker_pass" ]]; then
docker_pass="$docker_user"
echo "Giving user '$docker_user' a secure password: $docker_pass"
fi
docker exec -u root -it "$cont_name" groupadd -g "$docker_user_gid" "$docker_group"
docker exec -u root -it "$cont_name" useradd -u "$docker_user_uid" -g "$docker_user_gid" "$docker_user"
docker exec -u root -it "$cont_name" usermod --password "$(openssl passwd -1 "$docker_pass")" "$docker_user"
docker exec -u root -it "$cont_name" usermod -aG sudo "$docker_user"
docker exec -u root -it "$cont_name" "$repo_tgt/externals/src/emumba/install_emumba-deribit-connector.sh"