From 7386dbaed5401f8e3fd4fef468523bb9b6f20336 Mon Sep 17 00:00:00 2001 From: Xsivax Date: Fri, 3 Sep 2021 16:22:33 +0200 Subject: [PATCH] first commit --- README.md | 16 +++++++++++ build/deb-rust/.env | 1 + build/deb-rust/Dockerfile | 24 +++++++++++++++++ build/deb-rust/Makefile | 11 ++++++++ build/deb-rust/Rocket.toml | 7 +++++ compose/docker-compose.yml | 47 +++++++++++++++++++++++++++++++++ compose/docker-compose.yml.save | 21 +++++++++++++++ run.sh | 25 ++++++++++++++++++ 8 files changed, 152 insertions(+) create mode 100644 README.md create mode 100644 build/deb-rust/.env create mode 100644 build/deb-rust/Dockerfile create mode 100644 build/deb-rust/Makefile create mode 100644 build/deb-rust/Rocket.toml create mode 100644 compose/docker-compose.yml create mode 100644 compose/docker-compose.yml.save create mode 100644 run.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..346d273 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +Build and run : + +. run.sh + + +terminate with : + +Ctrl-C + +then: + +cd .. + + + + diff --git a/build/deb-rust/.env b/build/deb-rust/.env new file mode 100644 index 0000000..2cd6f49 --- /dev/null +++ b/build/deb-rust/.env @@ -0,0 +1 @@ +DATABASE_URL=mysql://rocket_user:rocket_pw@mariadb/rocket_db \ No newline at end of file diff --git a/build/deb-rust/Dockerfile b/build/deb-rust/Dockerfile new file mode 100644 index 0000000..19e159f --- /dev/null +++ b/build/deb-rust/Dockerfile @@ -0,0 +1,24 @@ +FROM rustlang/rust:nightly + +WORKDIR /usr/src + +RUN apt-get update + +RUN git clone https://basabuuka.zapto.org/xsiva/rocket-3d.git + +RUN cargo install --path ./rocket-3d + +WORKDIR /usr/src/rocket-3d + +COPY Rocket.toml /usr/src/rocket-3d/Rocket.toml +COPY .env /usr/src/rocket-3d/.env + +RUN cargo install cargo-watch + +# RUN cargo install diesel_cli --no-default-features --features "mysql" + +# RUN diesel setup + +CMD ROCKET_ENV=debug cargo watch -x 'run --bin rocket-3d' + + diff --git a/build/deb-rust/Makefile b/build/deb-rust/Makefile new file mode 100644 index 0000000..22610e1 --- /dev/null +++ b/build/deb-rust/Makefile @@ -0,0 +1,11 @@ +local_build: + docker build -t rocket_local_dev -f Dockerfile . + +local_run: + docker run --rm -it -p 5000:5000 --mount source="$(shell pwd)",target=/usr/src,type=bind --name rocket-server rocket_local_dev cargo watch -x 'run --bin rocket-3d' + +local_stop: + docker stop rocket + +local_shell: + docker run --rm -it -p 5000:5000 --mount source="$(shell pwd)",target=/usr/src,type=bind --name rocket-server rocket_local_dev \ No newline at end of file diff --git a/build/deb-rust/Rocket.toml b/build/deb-rust/Rocket.toml new file mode 100644 index 0000000..d39c48f --- /dev/null +++ b/build/deb-rust/Rocket.toml @@ -0,0 +1,7 @@ +[debug] +address = "0.0.0.0" +port = 5000 + + +[default] +template_dir = "templates" diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml new file mode 100644 index 0000000..8cda86b --- /dev/null +++ b/compose/docker-compose.yml @@ -0,0 +1,47 @@ +version: "3.4" + +services: + deb-rust: + container_name: deb-rust + restart: always + build: ../build/deb-rust + environment: + - RUST_BACKTRACE=1 + - DATABASE_URL=mysql://rocket_user:rocket_pw@0.0.0.0:3306/rocket_db + ports: + - "5000:5000" + networks: + - rocket-db + #depends_on: + #- mariadb + #links: + #- "mariadb" + + + #mariadb: + #image: mariadb:latest + #container_name: mariadb + #hostname: mariadb + #restart: always + #volumes: + #- "mariadb_vol:/var/lib/mysql" + #ports: + #- "3306:3306" + #environment: + #- MYSQL_ROOT_PASSWORD=password + #- MYSQL_PASSWORD=rocket_pw + #- MYSQL_DATABASE=rocket_db + #- MYSQL_USER=rocket_user + #networks: + #- rocket-db + +networks: + rocket-db: + driver: bridge + +volumes: + maria-data: + driver: local + mariadb_vol: + + diff --git a/compose/docker-compose.yml.save b/compose/docker-compose.yml.save new file mode 100644 index 0000000..d8e86d0 --- /dev/null +++ b/compose/docker-compose.yml.save @@ -0,0 +1,21 @@ +version: "3.4" + +services: + deb-rust-rocket: + container_name: "deb-rust-rocket" + command: cargo watch -x 'run --bin rocket-3d' + build: + dockerfile: Dockerfile + context: ../build/deb-rust + cache_from: + - rustlang/rust:nightly + networks: + - library-network + tty: true + wq +volumes: + - type: bind + source: ./ + target: /usr/src + ports: + - "5000:5000" diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..4bc73ed --- /dev/null +++ b/run.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +trap "cd '..'" TERM INT + +# run docker-container +run() { + cd "compose" && \ + docker-compose build --no-cache deb-rust && \ + docker-compose up && \ + + +} + +run + +#to do: +# ctrl-c(sigint): + # stop and remove container(with custom message) + # cd .. + + + + + +