Skip to content

Commit 75e5b32

Browse files
authored
add experimental Rust base image (#28)
1 parent 2468efe commit 75e5b32

File tree

8 files changed

+166
-0
lines changed

8 files changed

+166
-0
lines changed

.github/workflows/build.yml

+38
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,41 @@ jobs:
144144
with:
145145
push: ${{ github.event_name != 'pull_request' }}
146146
targets: ${{ steps.target.outputs.TARGET }}
147+
148+
build_rust_kernels:
149+
runs-on: ubuntu-22.04
150+
permissions:
151+
id-token: write
152+
packages: write
153+
strategy:
154+
matrix:
155+
version: [1.70.0]
156+
env:
157+
VERSION: ${{ matrix.version }}
158+
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
159+
GITHUB_SHA: ${{ github.ref }}
160+
steps:
161+
- uses: actions/checkout@v3
162+
- name: Install Task
163+
uses: arduino/setup-task@e26d8975574116b0097a1161e0fe16ba75d84c1c # v1.0.3
164+
with:
165+
repo-token: ${{ github.token }}
166+
- run: |
167+
task rust:base:copy-files NBL_LANGUAGE_VERSION=${{ matrix.version }}
168+
- run: scripts/set-variables.sh ${{ github.ref_name }} ${{ github.event_name }} ${{ github.event.pull_request.number }}
169+
- uses: docker/login-action@v2
170+
with:
171+
registry: ghcr.io
172+
username: ${{ github.actor }}
173+
password: ${{ github.token }}
174+
- name: Set target
175+
id: target
176+
run: echo "TARGET=rust_${VERSION//./_}" >> "$GITHUB_OUTPUT"
177+
178+
- uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
179+
180+
- name: Build kernels
181+
uses: docker/bake-action@f32f8b8d70bc284af19f8148dd14ad1d2fbc6c28 # v3.1.0
182+
with:
183+
push: ${{ github.event_name != 'pull_request' }}
184+
targets: ${{ steps.target.outputs.TARGET }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dev_packages
3333
!r/Aptfile
3434
!r/datascience/Aptfile
3535
!r/noteable/Aptfile
36+
!rust/Aptfile
3637

3738
!python/base-gpu/gpu.Aptfile
3839
!python/base-gpu/environment.txt
@@ -46,6 +47,7 @@ dev_packages
4647
!python/run.sh
4748
!python/base-gpu/run.sh
4849
!r/run.sh
50+
!rust/run.sh
4951

5052
!python/noteable/.pythonrc
5153
!python/noteable/ipython_config.py

Taskfile.rust.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: 3
2+
3+
# https://hub.docker.com/_/rust/tags
4+
vars:
5+
NBL_RUST_VERSION: 1.70
6+
IDENTIFIER: base
7+
8+
# NOTE: When using `deps: []`, variables are inherited from the current task, but when calling them
9+
# directly in `cmds: []`, the variables have to be passed in explicitly.
10+
tasks:
11+
core:build:
12+
desc: Build the Rust 1.x image
13+
cmds:
14+
- >-
15+
docker build rust/{{.IDENTIFIER}}/{{.NBL_RUST_VERSION}} \
16+
--build-arg "NBL_RUST_VERSION={{.NBL_RUST_VERSION}}" \
17+
--build-arg "BASE_IMAGE={{.BASE_IMAGE}}" \
18+
--tag "local/kernel-rust-{{.NBL_RUST_VERSION}}-{{.IDENTIFIER}}:dev"
19+
20+
base:copy-files:
21+
desc: Copy files from the Rust directory to the build directories
22+
cmds:
23+
- task copy-root-files LANGUAGE=rust IDENTIFIER={{.IDENTIFIER}} NBL_LANGUAGE_VERSION={{.NBL_RUST_VERSION}}
24+
- task copy-language-files LANGUAGE=rust IDENTIFIER={{.IDENTIFIER}} NBL_LANGUAGE_VERSION={{.NBL_RUST_VERSION}}
25+
26+
base:build:
27+
desc: Build the Rust 1.x base image after copying required files
28+
cmds:
29+
- task rust:base:copy-files IDENTIFIER=base NBL_LANGUAGE_VERSION={{.NBL_RUST_VERSION}}
30+
- task rust:core:build IDENTIFIER=base NBL_RUST_VERSION={{.NBL_RUST_VERSION}}

Taskfile.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: 3
33
includes:
44
python: ./Taskfile.python.yaml
55
r: ./Taskfile.R.yaml
6+
rust: ./Taskfile.rust.yaml
67

78
tasks:
89
copy-root-files:

docker-bake.hcl

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ variable "TIMESTAMP" {
2323
default = ""
2424
}
2525

26+
# Group of Rust targets
27+
group "rust" {
28+
targets = [
29+
"rust_base_1_70",
30+
]
31+
}
32+
33+
# Group of Rust 1.70 targets
34+
group "rust_1_70_0" {
35+
targets = [
36+
"rust_base_1_70_0",
37+
]
38+
}
39+
2640
# Group of R targets
2741
group "rlang_4_3_0" {
2842
targets = [
@@ -336,3 +350,12 @@ target "rlang_noteable_4_3_0" {
336350
"ghcr.io/noteable-io/kernel-r-4.3.0-noteable:${TAG}"
337351
]
338352
}
353+
354+
# Base Rust 1.70 image
355+
target "rust_base_1_70_0" {
356+
inherits = ["base"]
357+
context = "rust/base/1.70"
358+
tags = [
359+
"ghcr.io/noteable-io/kernel-rust-1.70-base:${TAG}"
360+
]
361+
}

rust/Aptfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tini

rust/base/1.70/Dockerfile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# syntax = docker/dockerfile:1.5
2+
# ---
3+
# Bare minimum Rust 1.x.x image with evxcr_jupyter installed
4+
# - no Rust crates/packages aside from builtins and evxcr_jupyter
5+
# - no git, secrets, SQL, extensions, etc
6+
# ---
7+
ARG NBL_RUST_VERSION="1.70"
8+
FROM rust:${NBL_RUST_VERSION}-slim-bullseye as base
9+
10+
# User/group setup
11+
USER root
12+
13+
ENV NB_USER="noteable" \
14+
NB_UID=4004 \
15+
NB_GID=4004
16+
17+
RUN groupadd --gid 4004 noteable && \
18+
useradd --uid 4004 \
19+
--shell /bin/false \
20+
--create-home \
21+
--no-log-init \
22+
--gid noteable noteable \
23+
--home-dir /srv/noteable && \
24+
chown --recursive noteable:noteable /srv/noteable && \
25+
mkdir -p /etc/noteable && chown noteable:noteable /etc/noteable
26+
27+
WORKDIR /tmp
28+
29+
COPY apt-install /usr/bin/
30+
COPY Aptfile .
31+
RUN /usr/bin/apt-install Aptfile
32+
33+
USER noteable
34+
35+
ENV PATH="/srv/noteable/.cargo/bin:${PATH}"
36+
37+
RUN cargo install evcxr_jupyter && \
38+
evcxr_jupyter --install
39+
40+
COPY secrets_helper.sh /tmp/secrets_helper.sh
41+
COPY run.sh /usr/local/bin
42+
43+
ENV HOME="/srv/noteable"
44+
45+
WORKDIR /etc/noteable/project
46+
EXPOSE 50001-50005
47+
48+
RUN cargo init
49+
50+
ENTRYPOINT ["tini", "-g", "--"]
51+
CMD ["run.sh"]

rust/run.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -o pipefail
3+
set -o nounset
4+
set -o errexit
5+
6+
set -x
7+
8+
echo "Local time: $(date)"
9+
10+
set +x
11+
echo "Injecting Secrets into environment, echoing is turned off"
12+
# shellcheck disable=SC1091
13+
source /tmp/secrets_helper.sh
14+
echo "Done injecting Secrets, turning echoing back on"
15+
set -x
16+
17+
18+
echo "Starting Rust kernel"
19+
20+
exec evcxr_jupyter --control_file /etc/noteable/connections/connection_file.json

0 commit comments

Comments
 (0)