Add Dev Container Configuration Files (#7)

This commit is contained in:
Olivier Benz 2023-07-23 17:35:21 +02:00 committed by GitHub
parent 4f7ab0ac1b
commit 931b138bb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 441 additions and 0 deletions

View File

@ -0,0 +1,68 @@
ARG BUILD_ON_IMAGE=glcr.b-data.ch/julia/base
ARG JULIA_VERSION=latest
FROM ${BUILD_ON_IMAGE}:${JULIA_VERSION} as files
ARG DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN mkdir /files
COPY julia-base/conf/user /files
COPY julia-base/scripts /files
## Ensure file modes are correct when using CI
## Otherwise set to 777 in the target image
RUN find /files -type d -exec chmod 755 {} \; \
&& find /files -type f -exec chmod 644 {} \; \
&& find /files/usr/local/bin -type f -exec chmod 755 {} \;
FROM ${BUILD_ON_IMAGE}:${JULIA_VERSION}
ARG DEBIAN_FRONTEND=noninteractive
## Update environment
ARG USE_ZSH_FOR_ROOT
ARG SET_LANG
ARG SET_TZ
ENV LANG=${SET_LANG:-$LANG} \
TZ=${SET_TZ:-$TZ} \
PARENT_IMAGE_BUILD_DATE=${BUILD_DATE}
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
## Change root's shell to ZSH
RUN if [ ! -z "$USE_ZSH_FOR_ROOT" ]; then \
chsh -s /bin/zsh; \
fi \
## Update timezone if needed
&& if [ "$TZ" != "Etc/UTC" ]; then \
echo "Setting TZ to $TZ"; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone; \
fi \
## Add/Update locale if needed
&& if [ "$LANG" != "en_US.UTF-8" ]; then \
sed -i "s/# $LANG/$LANG/g" /etc/locale.gen; \
locale-gen; \
echo "Setting LANG to $LANG"; \
update-locale --reset LANG=$LANG; \
fi \
## Allow updating pre-installed Julia packages
## Make sure $JULIA_PATH/local/share/julia/registries/* is deleted
&& rm -rf ${JULIA_PATH}/local/share/julia/registries/*
## Pip: Install to the Python user install directory (1) or not (0)
ARG PIP_USER=1
ENV PIP_USER=${PIP_USER}
## Copy files as late as possible to avoid cache busting
COPY --from=files /files /
## Reset environment variable BUILD_DATE
ARG BUILD_START
ENV BUILD_DATE=${BUILD_START}

View File

@ -0,0 +1,70 @@
{
"name": "Julia base",
"build": {
"dockerfile": "./Julia.Dockerfile",
"context": ".",
"args": {
"BUILD_ON_IMAGE": "glcr.b-data.ch/julia/base",
"JULIA_VERSION": "1.7.3",
"USE_ZSH_FOR_ROOT": "unset-to-use-bash",
"SET_LANG": "en_US.UTF-8",
"SET_TZ": "Etc/UTC"
}
},
"postStartCommand": {
"julia": "postStartCommand.sh"
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": true,
"upgradePackages": false,
"username": "vscode",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"moby": false
},
// A comma separated list of packages to install
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": ""
}
},
"customizations": {
"vscode": {
"extensions": [
"editorconfig.editorconfig",
"ms-python.python",
"mutantdino.resourcemonitor",
"julialang.language-julia",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-python.black-formatter",
"ms-azuretools.vscode-docker"
],
"settings": {
"julia.enableCrashReporter": false,
"julia.enableTelemetry": false,
"resmon.show.battery": false,
"resmon.show.cpufreq": false
}
}
},
// Set 'remoteUser' to 'root' to connect as root instead.
"remoteUser": "vscode",
// "remoteUser": "root",
// By default,
// - Julia starts up with a single thread of execution.
// - BLAS/OpenMP will use as many threads as possible.
// Set the following environment variables to control the exact number to use.
"remoteEnv": {
// "JULIA_NUM_THREADS": "1",
// "OMP_NUM_THREADS": "1"
}
}

View File

@ -0,0 +1,45 @@
println("Executing user-specific startup file (", @__FILE__, ")...")
# https://github.com/julia-vscode/julia-vscode/issues/3304
project = (Base.JLOptions().project != C_NULL ?
unsafe_string(Base.JLOptions().project) :
get(ENV, "JULIA_PROJECT", nothing))
if !isnothing(project)
Pkg.activate(; io=devnull)
end
try
using Revise
println("Revise started")
catch e
@warn "Error initializing Revise" exception=(e, catch_backtrace())
end
if !isnothing(project) &&
# https://github.com/julia-vscode/julia-vscode/issues/3304
!startswith(Base.load_path_expand(Base.LOAD_PATH[end]), project)
if startswith(project, "@")
if startswith(project, "@.")
if isnothing(Base.current_project())
Pkg.activate(joinpath("$(ENV["HOME"])", ".julia",
"environments", "v$(VERSION.major).$(VERSION.minor)"))
else
Pkg.activate(Base.current_project(); io=devnull)
end
else
Pkg.activate(Base.load_path_expand(project); io=devnull)
end
else
Pkg.activate(abspath(expanduser(project)); io=devnull)
end
else
if isfile(joinpath(pwd(), "Project.toml")) &&
isfile(joinpath(pwd(), "Manifest.toml"))
Pkg.activate(pwd())
else
Pkg.activate(joinpath("$(ENV["HOME"])", ".julia", "environments",
"v$(VERSION.major).$(VERSION.minor)"))
end
end

View File

@ -0,0 +1,3 @@
if !in(MIME("application/pdf"), IJulia.ijulia_mime_types)
IJulia.register_mime(MIME("application/pdf"))
end

View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Copyright (c) 2023 b-data GmbH.
# Distributed under the terms of the MIT License.
set -e
mkdir -p "${HOME}/.julia/config"
# Copy user-specific startup files if home directory is bind mounted
if [ ! -f "${HOME}/.julia/config/startup_ijulia.jl" ]; then
cp -a /etc/skel/.julia/config/startup_ijulia.jl \
"${HOME}/.julia/config"
fi
if [ ! -f "${HOME}/.julia/config/startup.jl" ]; then
cp -a /etc/skel/.julia/config/startup.jl \
"${HOME}/.julia/config"
fi

View File

@ -0,0 +1,72 @@
{
"name": "Julia pubtools",
"build": {
"dockerfile": "../Julia.Dockerfile",
"context": "..",
"args": {
"BUILD_ON_IMAGE": "glcr.b-data.ch/julia/pubtools",
"JULIA_VERSION": "1.7.3",
"USE_ZSH_FOR_ROOT": "unset-to-use-bash",
"SET_LANG": "en_US.UTF-8",
"SET_TZ": "Etc/UTC"
}
},
"postStartCommand": {
"julia": "postStartCommand.sh"
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": true,
"upgradePackages": false,
"username": "vscode",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"moby": false
},
// A comma separated list of packages to install
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": ""
}
},
"customizations": {
"vscode": {
"extensions": [
"editorconfig.editorconfig",
"ms-python.python",
"mutantdino.resourcemonitor",
"julialang.language-julia",
"James-Yu.latex-workshop",
"quarto.quarto",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-python.black-formatter",
"ms-azuretools.vscode-docker"
],
"settings": {
"julia.enableCrashReporter": false,
"julia.enableTelemetry": false,
"resmon.show.battery": false,
"resmon.show.cpufreq": false
}
}
},
// Set 'remoteUser' to 'root' to connect as root instead.
"remoteUser": "vscode",
// "remoteUser": "root",
// By default,
// - Julia starts up with a single thread of execution.
// - BLAS/OpenMP will use as many threads as possible.
// Set the following environment variables to control the exact number to use.
"remoteEnv": {
// "JULIA_NUM_THREADS": "1",
// "OMP_NUM_THREADS": "1"
}
}

View File

@ -10,6 +10,7 @@ book that has been written by Bogumił Kamiński and has been published by [Mann
* [Setting up your environment](#setting-up-your-environment)
* [General instructions](#general-instructions)
* [Note for Linux users](#note-for-linux-users)
* [Dev Containers](#dev-containers)
* [Organization of the code](#organization-of-the-code)
* [Running the example codes](#running-the-example-codes)
* [Accompanying materials](#accompanying-materials)
@ -91,6 +92,17 @@ export PATH="$PATH:/opt/julia-1.7.2/bin"
line (assuming you have downloaded Julia 1.7.2 and extracted it to `/opt` folder).
### Dev Containers
Folder `/.devcontainer` contains configuration files for
[Dev Containers](https://containers.dev).
* For use with Github Codespaces, please follow the instruction at
[Creating a codespace for a repository](https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace-for-a-repository#creating-a-codespace-for-a-repository).
* For local/'remote host' usage with Visual Studio Code, please follow the
instructions at
[Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers).
## Organization of the code
The codes for each chapter are stored in files named *chXX.jl*, where *XX* is

View File

@ -28,6 +28,17 @@
"### Comparison of execution speed of Julia, Java, Python, and C"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99c45eb6",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -35,6 +35,17 @@
"## Representing values"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2338b85b",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### A single function can have multiple methods"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1f7359c",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -63,6 +63,17 @@
"### Getting the data into a matrix"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e16f874",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### Syntax and meaning of broadcasting in Julia"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1d9574f4",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### Downloading data from the web"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10d11474",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### Standard process of parsing JSON response"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a179627e",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -26,6 +26,17 @@
"## Fetching, unpacking, and inspecting the Lichess data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2ade007",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -42,6 +42,17 @@
"## Advanced data frame indexing"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "65b9f2cc",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"## Review of most important ways of creating a data frame"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b94d80ed",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -26,6 +26,17 @@
"## Converting a data frame to other value types"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6408a31f",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### Fetching GitHub developer data from the web"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b3a42231",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### Loading all required packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8c7f637",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -34,6 +34,17 @@
"### Calculation of asian option payoff"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da189a22",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"Pkg.activate(Base.current_project())"
]
},
{
"cell_type": "code",
"execution_count": 1,