Skip to content

Commit fea3df7

Browse files
committed
1st commit: minimal working version
1 parent 11ab1e1 commit fea3df7

16 files changed

+453
-2
lines changed

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Rust
2+
target
3+
4+
# Docker
5+
Dockerfile
6+
.dockerignore
7+
8+
# Git
9+
.git
10+
.gitignore
11+
.gitattributes
12+
13+
# Images
14+
images
15+
.png

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
notebooks/* linguist-documentation
2+
notebooks/**/* linguist-documentation
3+
images/* linguist-documentation

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# Jupyter notebook checkpoints
14+
.ipynb_checkpoints
15+
16+
# Ignore Bash
17+
.sh

Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "greenhouse"
3+
version = "0.1.0"
4+
authors = ["Felipe Penha <[email protected]>"]
5+
description = "A Rust containerized framework for a better Data X development workflow."
6+
repository = "https://github.com/felipepenha/rust-greenhouse"
7+
license = "Apache-2.0"
8+
include = [
9+
"src/**/*.rs",
10+
"Cargo.toml",
11+
]
12+
edition= "2018"
13+
14+
[workspace]
15+
members = ["src/*"]
16+
17+
[lib]
18+
name = "foo"
19+
path = "src/lib.rs"
20+
crate-type = ["lib"]
21+
test = true
22+
23+
[[bin]]
24+
name = "script"
25+
path = "src/main.rs"
26+
27+
[dependencies]
28+
datafusion = "2.0.0"
29+
arrow = "2.0.0"

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM rust:latest AS base
2+
3+
USER root
4+
5+
ARG APP_DIR=/usr/app
6+
7+
RUN mkdir $APP_DIR
8+
WORKDIR $APP_DIR
9+
10+
# Install Jupyter and evcxr
11+
12+
RUN apt update && apt install -y \
13+
jupyter-notebook \
14+
cmake
15+
16+
RUN cargo install evcxr_repl
17+
RUN cargo install evcxr_jupyter
18+
19+
RUN evcxr_jupyter --install
20+
21+
# Configure Rust Channel
22+
23+
RUN rustup install nightly-2021-01-21
24+
RUN rustup override set nightly-2021-01-21
25+
RUN rustup default nightly-2021-01-21
26+
RUN echo $(rustup show)
27+
28+
# Copy project directories
29+
30+
COPY src $APP_DIR/src
31+
COPY Cargo.toml $APP_DIR/Cargo.toml

LICENSE

100644100755
File mode changed.

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
BUILD = docker-compose build
2+
RUN = docker-compose run
3+
4+
5+
help:
6+
@echo "USAGE"
7+
@echo
8+
@echo " make <command>"
9+
@echo " Include 'sudo' when necessary."
10+
@echo
11+
@echo
12+
@echo "COMMANDS"
13+
@echo
14+
@echo " build: build image using cache"
15+
@echo " build-no-cache: build image from scratch, and not from cache"
16+
@echo " bash: bash REPL (Read-Eval-Print loop), suitable for debugging"
17+
@echo " rust: access rust through the Evcxr REPL (Read-Eval-Print loop)"
18+
@echo " rust-jupyter: access rust through the Evcxr Jupyter Notebook"
19+
20+
#################
21+
# User Commands #
22+
#################
23+
24+
build:
25+
$(BUILD)
26+
27+
build-no-cache:
28+
$(BUILD) --no-cache
29+
30+
bash:
31+
$(RUN) bash
32+
33+
rust:
34+
$(RUN) rust
35+
36+
rust-jupyter:
37+
$(RUN) --service-ports rust-jupyter
38+

README.md

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,184 @@
1-
# rust-greenhouse
2-
A Rust containerized framework for a better Data X development workflow. Where X = Science, Engineering, Analytics, etc.
1+
![](/images/Greenhouse_github_card.png)
2+
3+
# Greenhouse
4+
5+
A containerized Rust framework for a better Data X development workflow. Where X = Science, Engineering, Analytics, etc.
6+
7+
The name "Greenhouse" is a metaphor. A greenhouse is a structure made of glass to grow plants despite of external conditions such as a cold winter. Likewise, the Greenhouse framework builds a standalone container which is fully transparent to the user.
8+
9+
10+
# Quick Start
11+
12+
This is a template repository. [Follow this link for instructions to create a repository from a template](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template#creating-a-repository-from-a-template).
13+
14+
15+
The greenhouse work is initiated with `make` commands.
16+
17+
18+
To see the most up to date list of available commands run
19+
20+
```bash
21+
$ make help
22+
23+
USAGE
24+
25+
make <command>
26+
Include 'sudo' when necessary.
27+
28+
29+
COMMANDS
30+
31+
build: build image using cache
32+
build-no-cache: build image from scratch, and not from cache
33+
bash: bash REPL (Read-Eval-Print loop), suitable for debugging
34+
rust: access rust through the Evcxr REPL (Read-Eval-Print loop)
35+
rust-jupyter: access rust through the Evcxr Jupyter Notebook
36+
```
37+
38+
39+
To build your greenhouse (as it is), you first need to run:
40+
41+
```bash
42+
$ make build-no-cache
43+
```
44+
45+
46+
To access Jupyter in your local browser:
47+
48+
```bash
49+
$ make rust-jupyter
50+
51+
Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
52+
53+
To access the notebook, open this file in a browser:
54+
file:///root/.local/share/jupyter/runtime/nbserver-1-open.html
55+
Or copy and paste one of these URLs:
56+
http://(xxxxxxxxxxxx or 127.0.0.1):8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
57+
```
58+
59+
Next, you simply need to follow the instructions printed out on your own terminal.
60+
61+
In the generic example above, I would paste the following on my browser:
62+
63+
```bash
64+
http://127.0.0.1:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
65+
```
66+
67+
Any changes made in the files within the Jupyter interface, for example saved changes in `.rs`, `.ipynb`, and `.py` files, will be reflected in the original files you store locally, and vice-versa. This is ensured by the fact that the whole greenhouse directory is set as a `volume` in the `docker-compose.yml` configuration file.
68+
69+
You may also choose to run code using the REPL (Read-Eval-Print loop) in the terminal by running:
70+
71+
```bash
72+
$ make rust
73+
```
74+
75+
76+
Now, you are ready to start developing Rust code by creating new `.rs` files in the `/src` directory.
77+
78+
79+
During development phase, you can normally test out new code in a Jupyter Notebook, as you would do with Python.
80+
81+
82+
For example, in the file `src/messages.rs` we have a public function defined as
83+
84+
```rust
85+
pub fn hello_world() {
86+
println!("Hello, world! From `src/message.rs`");
87+
}
88+
```
89+
90+
91+
In the Jupyter Notebook you will be able to access it through
92+
93+
```rust
94+
>> #[path = "/usr/app/src/messages.rs"] mod messages;
95+
>> use messages::hello_world;
96+
```
97+
98+
Next, to actually use the function:
99+
100+
```rust
101+
>> messages::hello_world();
102+
103+
Hello, world! From `src/message.rs`
104+
```
105+
106+
Check out additional examples in the `/notebooks` directory (`.ipynb` files with preffix `example_`).
107+
108+
109+
# Greenhouse Structure
110+
111+
112+
```bash
113+
.
114+
├── Cargo.lock
115+
├── Cargo.toml
116+
├── docker-compose.yml
117+
├── Dockerfile
118+
├── LICENSE
119+
├── Makefile
120+
├── notebooks
121+
│   ├── example_datafusion.ipynb
122+
│   └── example_messages.ipynb
123+
├── README.md
124+
├── rust-toolchain.toml
125+
├── src
126+
│   ├── lib.rs
127+
│   ├── main.rs
128+
│   └── messages.rs
129+
└── target
130+
```
131+
132+
* `Cargo.toml`: manifest of the package. Dependencies are defined here.
133+
* `src/`: source directory for your Rust package
134+
* `src/lib.rs`: defines your package (ex: which crates are included)
135+
* `src/main.rs`: a script for dev purposes with `$cargo run`
136+
* `messages.rs`: example of crate that yields a "Hello World" message
137+
138+
# Adding External Dependencies
139+
140+
You need to include any external dependencies to the `Cargo.toml` file in addition to the default list:
141+
142+
```yaml
143+
[dependencies]
144+
datafusion = "2.0.0"
145+
arrow = "2.0.0"
146+
```
147+
148+
You may also want to change a few lines in the `Dockerfile` to ensure that the correct version of Rust, consistent with your dependencies, is being used. We keep it fixed in the original Greenhouse template at `nightly-2021-01-01`:
149+
150+
```yaml
151+
RUN rustup install nightly-2021-01-01
152+
RUN rustup override set nightly-2021-01-01
153+
RUN rustup run nightly rustc --version
154+
```
155+
156+
`$ make build` will print out on your screen the version that is being used, in your own greenhouse. You may want to double-check it by running:
157+
158+
```bash
159+
$ make bash
160+
$ rustup run nightly rustc --version
161+
162+
Default host: x86_64-unknown-linux-gnu
163+
rustup home: /usr/local/rustup
164+
165+
installed toolchains
166+
--------------------
167+
168+
nightly-2021-01-01-x86_64-unknown-linux-gnu
169+
1.49.0-x86_64-unknown-linux-gnu (default)
170+
171+
active toolchain
172+
----------------
173+
174+
nightly-2021-01-01-x86_64-unknown-linux-gnu (directory override for '/usr/app')
175+
rustc 1.51.0-nightly (44e3daf5e 2020-12-31)
176+
```
177+
178+
The above output means that, in fact, `nightly-2021-01-01` is being used for `/usr/app`.
179+
180+
181+
182+
183+
184+

docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: "3"
2+
3+
services:
4+
5+
base:
6+
build:
7+
context: .
8+
dockerfile: Dockerfile
9+
image: base_image
10+
11+
bash:
12+
image: base_image
13+
user: root
14+
volumes:
15+
- .:/usr/app/
16+
working_dir: /usr/app/
17+
entrypoint: /bin/sh
18+
19+
rust:
20+
image: base_image
21+
user: root
22+
volumes:
23+
- .:/usr/app/
24+
working_dir: /usr/app/
25+
26+
command: "evcxr"
27+
28+
29+
rust-jupyter:
30+
image: base_image
31+
user: root
32+
volumes:
33+
- .:/usr/app/
34+
working_dir: /usr/app/
35+
command: "jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --no-browser"
36+
ports:
37+
- 8888:8888

images/Greenhouse_github_card.png

124 KB
Loading

images/Greenhouse_logo.png

19.7 KB
Loading

notebooks/example_datafusion.ipynb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"extern crate arrow;\n",
10+
"extern crate datafusion;"
11+
]
12+
}
13+
],
14+
"metadata": {
15+
"kernelspec": {
16+
"display_name": "Rust",
17+
"language": "rust",
18+
"name": "rust"
19+
},
20+
"language_info": {
21+
"codemirror_mode": "rust",
22+
"file_extension": ".rs",
23+
"mimetype": "text/rust",
24+
"name": "Rust",
25+
"pygment_lexer": "rust",
26+
"version": ""
27+
}
28+
},
29+
"nbformat": 4,
30+
"nbformat_minor": 2
31+
}

0 commit comments

Comments
 (0)