From 4e6c778b5db403dbae36485c0eb494090f88f55c Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Fri, 7 Apr 2023 01:48:03 -0300 Subject: [PATCH] =?UTF-8?q?initial=20commit=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/devcontainer.json | 26 ++++++++++++++++ .gitignore | 3 ++ Cargo.toml | 13 ++++++++ Dockerfile | 31 +++++++++++++++++++ Dockerfiles/node/Dockerfile | 13 ++++++++ Dockerfiles/node/docker-compose.yml | 10 ++++++ build.sh | 3 ++ commit.sh | 4 +++ main.rs | 47 +++++++++++++++++++++++++++++ 9 files changed, 150 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 Dockerfile create mode 100644 Dockerfiles/node/Dockerfile create mode 100644 Dockerfiles/node/docker-compose.yml create mode 100644 build.sh create mode 100644 commit.sh create mode 100644 main.rs diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..8d96444 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Existing Dockerfile", + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerfile": "../Dockerfile" + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b23d98 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +Project +Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b712789 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "turbo_open" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.0", features = ["derive"] } + +[[bin]] +name = "turbo_open" +path = "main.rs" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3481782 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# FROM alpine:latest + +# RUN apk update +# RUN apk upgrade +# RUN apk add curl file git +# RUN apk add gcc +# RUN apk add rust-doc +# # RUN apk search rust-std +# # RUN apk add rust-std + +# RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -y | sh +# # RUN source $HOME/.cargo/env + + + +# CMD [""] + +FROM rust:latest + +RUN apt upgrade +RUN apt update +# RUN apt install -y \ +# clang \ +# gcc \ +# g++ \ +# zlib1g-dev \ +# libmpc-dev \ +# libmpfr-dev \ +# libgmp-dev + +CMD [""] diff --git a/Dockerfiles/node/Dockerfile b/Dockerfiles/node/Dockerfile new file mode 100644 index 0000000..2f38770 --- /dev/null +++ b/Dockerfiles/node/Dockerfile @@ -0,0 +1,13 @@ +FROM mhart/alpine-node:14 + +RUN apk add curl + +COPY [".", "/usr/src"] + +WORKDIR "/usr/src" + +RUN yarn + +ARG NODE_ENV + +CMD if [ "$NODE_ENV" = "develop" ] ; then yarn run dev ; else yarn run start ; fi \ No newline at end of file diff --git a/Dockerfiles/node/docker-compose.yml b/Dockerfiles/node/docker-compose.yml new file mode 100644 index 0000000..85ab608 --- /dev/null +++ b/Dockerfiles/node/docker-compose.yml @@ -0,0 +1,10 @@ +version: "2.9" + +services: + app: + build: . + volumes: + - .:/usr/src + - /usr/src/node_modules + environment: + NODE_ENV: ${NODE_ENV} \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..199ff0e --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +cargo build --release --target=aarch64-apple-darwin +cargo build --release --target=x86_64-unknown-linux-gnu +cargo build --release --target=x86_64-pc-windows-msvc diff --git a/commit.sh b/commit.sh new file mode 100644 index 0000000..af278b9 --- /dev/null +++ b/commit.sh @@ -0,0 +1,4 @@ +cargo fmt +git add . +echo $1 +git commit -m "$1" diff --git a/main.rs b/main.rs new file mode 100644 index 0000000..a0902f8 --- /dev/null +++ b/main.rs @@ -0,0 +1,47 @@ +use clap::Parser; +use std::process::Command; + +#[derive(Parser)] +struct Cli { + project_type: String, + path: std::path::PathBuf, +} + +fn main() { + let args = Cli::parse(); + let path = std::fs::canonicalize(args.path) + .expect("could not read file") + .into_os_string() + .into_string() + .unwrap(); + let file_names_collection = [ + ["Dockerfile", "Dockerfile"], + ["docker-compose.yml", "docker-compose.yml"], + ]; + for file_names in file_names_collection { + let origin_file_path = format!( + "{}/{}/{}", + std::fs::canonicalize("./Dockerfiles/") + .expect("could not read file") + .into_os_string() + .into_string() + .unwrap(), + &args.project_type, + file_names[1] + ); + let destiny_path = format!("{}/{}", path, file_names[1]); + std::fs::copy(origin_file_path, destiny_path).ok(); + } + let mut child = Command::new("docker-compose") + .arg("-f") + .arg(format!("{}/{}", path, "docker-compose.yml")) + .arg("up") + .spawn() + .expect("failed to execute docker-compose"); + let status = child.wait().expect("failed to wait for child process"); + if status.success() { + println!("Docker Compose command executed successfully"); + } else { + eprintln!("Docker Compose command failed with error code {}", status); + } +}