Skip to content

Commit

Permalink
Updated Docker configuration & python_wrapper configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lexara-prime-ai committed Jun 6, 2024
1 parent 157d899 commit 2247b8c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 19 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "wspr_cdk",
"image": "mcr.microsoft.com/devcontainers/rust:bullseye",
"postCreateCommand": "bash .devcontainer/post_create.sh",
"customizations": {
"vscode": {
"extensions": [
"ms-python.black-formatter",
"rust-lang.rust-analyzer",
"charliermarsh.ruff"
],
"settings": {
"editor.formatOnSave": true
}
}
},
"features": {
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
}
}
13 changes: 13 additions & 0 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -euxo pipefail
# pipefail

# If set, the return value of a pipeline is the value of the last
# (rightmost) command to exit with a non-zero status, or zero if
# all commands in the pipeline exit successfully.
# This option is disabled by default.

sudo apt-get update
sudo apt-get install -y python3-dev python3-pip python3-venv libclang-dev
sudo python3 -m venv .venv
29 changes: 15 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ FROM chef AS builder

# Install python 3.11 development files and virtual environment tools
RUN apt-get update --no-install-recommends && \
apt-get install -y python3.11-dev python3.11-venv --no-install-recommends && \
apt-get install libclang-dev -y && \
apt-get install -y python3-dev python3-venv --no-install-recommends && \
apt-get clean --no-install-recommends

# Create and activate a virtual environment.
RUN python3.11 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Copy the prepared recipe.json from the [planner] stage.
COPY --from=planner /wspr_cdk/recipe.json recipe.json

# Cook the dependencies according to the recipe.
RUN cargo chef cook --release --recipe-path recipe.json

# Copy [python_deps] script to manage dependencies.
# The script currently installs the following dependencies:
# "mkdocs" "maturin" "tableauhyperapi" "google-api-python-client" "google-auth-httplib2" "google-auth-oauthlib"

COPY scripts/bash/python_deps.sh /scripts/bash/python_deps.sh

# Create and activate a virtual environment.
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
ENV VIRTUAL_ENV=/opt/venv

# Modify script permissions.
RUN chmod +x /scripts/bash/python_deps.sh

RUN python3 -m venv .venv

RUN /scripts/bash/python_deps.sh

# Copy the prepared recipe.json from the [planner] stage.
COPY --from=planner /wspr_cdk/recipe.json recipe.json

# Cook the dependencies according to the recipe.
RUN cargo chef cook --release --recipe-path recipe.json

COPY . .

# Set environment variables for Rocket
Expand All @@ -58,7 +58,8 @@ RUN cargo build --workspace --release
#------------------------------------

# [CURRENT] entry point.
CMD ["./target/release/wspr_cdk_server"]
# Run maturin develop during container initialization
ENTRYPOINT ["/bin/bash", "-c", ". /opt/venv/bin/activate && maturin develop -m python_wrapper/Cargo.toml && ./target/release/wspr_cdk_server"]

#------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion python_wrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ crate-type = ["cdylib"]

[dependencies]
wspr_cdk = { path = "../" }
pyo3 = "0.20.0"
pyo3 = { version = "0.20.0", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
tokio = "1.9"
7 changes: 4 additions & 3 deletions python_wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ impl ClickHouseStateWrapper {
}

/*
The '__repr__' method will provide a meaningful [string] representaion
The '__repr__' method will provide a meaningful [string] representation
for the ClickHouseState, python <object>.
...........................................................................
The '__str__' method will provide a user-friendly [string] representaion
The '__str__' method will provide a user-friendly [string] representation
for the ClickHouseState, python <object>.
*/
fn __repr__(&self) -> String {
Expand Down Expand Up @@ -99,7 +99,8 @@ fn get_wspr_spots(py: Python, limit: String, result_format: String) -> PyResult<

/// The <wspr_cdk> python module, implemented in Rust.
#[pymodule]
fn python_wrapper(_py: Python, m: &PyModule) -> PyResult<()> {
fn python_wrapper(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<ClickHouseStateWrapper>()?;
m.add_function(wrap_pyfunction!(get_wspr_spots, m)?)?;
Ok(())
}
4 changes: 4 additions & 0 deletions scripts/bash/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "> [BUILDING] <wspr_cdk>..."
sudo docker build -t test .
3 changes: 2 additions & 1 deletion scripts/bash/python_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi


# Modules that will be installed/upgraded.
modules=("mkdocs" "maturin" "tableauhyperapi" "google-api-python-client" "google-auth-httplib2" "google-auth-oauthlib")
modules=("mkdocs" "maturin" "patchelf" "tableauhyperapi" "google-api-python-client" "google-auth-httplib2" "google-auth-oauthlib")

echo "Installing dependencies: ${modules[*]}..."
pip install "${modules[@]}" --upgrade
Expand All @@ -31,6 +31,7 @@ verify_installation() {
declare -A module_import_map=(
["mkdocs"]="mkdocs"
["maturin"]="maturin"
["patchelf"]="patchelf"
["tableauhyperapi"]="tableauhyperapi"
["google-api-python-client"]="googleapiclient"
["google-auth-httplib2"]="google_auth_httplib2"
Expand Down

0 comments on commit 2247b8c

Please sign in to comment.