From 6abcfd1334a571342768056d29c1c1754d063b40 Mon Sep 17 00:00:00 2001 From: Tobias Maier Date: Tue, 12 Sep 2023 21:46:26 +0000 Subject: [PATCH] added tasting code --- .devcontainer/Dockerfile | 3 ++ .devcontainer/devcontainer.json | 55 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 32 +++++++++++++++++++ .gitignore | 5 +++ Cargo.toml | 10 ++++++ src/main.rs | 19 +++++++++++ 6 files changed, 124 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..6b53a15 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,3 @@ +FROM rust:1-bookworm +RUN apt update && apt upgrade -y && apt install fish -y +RUn rustup component add clippy rustfmt \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..59e2e47 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,55 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/rust +{ + "name": "Rust", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + + // Use 'mounts' to make the cargo cache persistent in a Docker Volume. + // "mounts": [ + // { + // "source": "devcontainer-cargo-cache-${devcontainerId}", + // "target": "/usr/local/cargo", + // "type": "volume" + // } + // ] + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": { + // "ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {} + // }, + "mounts": [ + "source=/home/tobi/.ssh,target=/home/vscode/.ssh,type=bind" + ], + + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + //"postCreateCommand": "git clone https://gitea.maiertobi.de/tobimai/dotfiles.git /home/vscode/dotfiles && cargo install cargo-tarpaulin", + "customizations": { + "vscode": { + "extensions": [ + "serayuzgur.crates", + "tamasfe.even-better-toml", + "vadimcn.vscode-lldb", + "mutantdino.resourcemonitor", + "rust-lang.rust-analyzer", + "ms-azuretools.vscode-docker" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "Fish", + "terminal.integrated.profiles.linux": { + "Fish": { + "path": "fish" + } + } + } + } + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..a542de7 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3' +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + volumes: + - ..:/workspace:cached + command: sleep infinity + + db: + image: postgres + environment: + POSTGRES_USER: dev + POSTGRES_PASSWORD: dev + POSTGRES_DB: iot + ports: + - 5432:5432 + command: ["postgres", "-c", "log_statement=all"] + + adminer: + image: michalhosna/adminer + environment: + ADMINER_DB: iot + ADMINER_DRIVER: pgsql + ADMINER_SERVER: db + ADMINER_USERNAME: dev + ADMINER_PASSWORD: dev + ADMINER_AUTOLOGIN: 1 + ADMINER_NAME: IOT DEVELOPMENT + ports: + - 1111:8080 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3ca43ae..193d30e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + + +# Added by cargo + +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ee8c2e0 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "iot-cloud" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +actix-web = "4.4.0" +sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "postgres" ] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d650da8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,19 @@ +use actix_web::{get, web, App, HttpServer, Responder}; + +#[get("/")] +async fn index() -> impl Responder { + "Hello, World!" +} + +#[get("/{name}")] +async fn hello(name: web::Path) -> impl Responder { + format!("Hello {}!", &name) +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + HttpServer::new(|| App::new().service(index).service(hello)) + .bind(("127.0.0.1", 8080))? + .run() + .await +} \ No newline at end of file