diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..de46666 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +[target.armv7-unknown-linux-musleabihf] +linker = "musl-gcc" diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 0000000..1b503db --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/target/ +/.git/ diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..92aff47 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,64 @@ +--- +kind: pipeline +type: docker +name: default + +platform: + os: "linux" + arch: "arm" + +steps: +- name: "deps" + image: "rust:1.49" + volumes: + - name: "cache" + path: "/.target" + commands: + - "apt-get update" + - "apt-get install -yqq musl-tools make" + - "rustup target add armv7-unknown-linux-musleabihf" + - "cargo check" + - "cargo test" + - "cargo build --release --target=armv7-unknown-linux-musleabihf" + +- name: "check" + image: "rust:1.49" + depends_on: + - "deps" + volumes: + - name: "cache" + path: "/.target" + commands: + - "cargo check" + +- name: "test" + image: "rust:1.49" + depends_on: + - "deps" + volumes: + - name: "cache" + path: "/.target" + commands: + - "cargo test" + +- name: "deploy" + image: "rust:1.49" + depends_on: + - "check" + - "test" + environment: + SSH_PK: + from_secret: SSH_PRIVATE_KEY + SSH_PARAMS: '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/tmp/known_hosts' + TARGET_DIR: "./.target/armv7-unknown-linux-musleabihf/release" + commands: + - "mkdir /tmp/ssh 2>&1" + - "echo -n ${SSH_PK} | base64 -d > /tmp/ssh/deploy_key " + - "eval $(ssh-agent -s)" + - "chmod 600 /tmp/ssh/deploy_key" + - "ssh-add /tmp/ssh/deploy_key" + - "scp ${SSH_PARAMS} ${TARGET_DIR}/alterego ${SSH_USER}@${SSH_HOST}:/home/pi/alterego" + +volumes: +- name: "cache" + temp: {} diff --git a/.env b/.env old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Cargo.lock b/Cargo.lock old mode 100644 new mode 100755 index 8bce451..4ddbf13 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,7 @@ dependencies = [ "env_logger", "envconfig", "log", + "openssl", "reqwest", "serde", "serde_json", @@ -723,6 +724,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +[[package]] +name = "openssl-src" +version = "111.13.0+1.1.1i" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "045e4dc48af57aad93d665885789b43222ae26f4886494da12d1ed58d309dcb6" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.58" @@ -732,6 +742,7 @@ dependencies = [ "autocfg", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml old mode 100644 new mode 100755 index b63b3b8..5bb499b --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ uuid = { version = "0.8.1", features = ["v4"] } log = "0.4" env_logger = "0.8.1" envconfig = "0.9.1" +openssl = {version="*", features = ["vendored"]} diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..e10da88 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM docker.io/rust:1.49 + +RUN apt-get update && apt-get install -yqq \ + musl-tools \ + make + +RUN rustup target add armv7-unknown-linux-musleabihf diff --git a/makefile b/makefile new file mode 100755 index 0000000..8139814 --- /dev/null +++ b/makefile @@ -0,0 +1,27 @@ +export DOCKER_BUILDKIT=1 + +DOCKERFLAGS:=-it --rm \ + -v "${PWD}":"/app" \ + --workdir "/app" \ + -e "PWD=/app" + +DOCKERIMG:="rust-build-env:V1" + +image: + docker build -t rust-build-env:V1 . +.PHONY: image + +ARM_PREFIX:=CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-ld \ + REALGCC=arm-linux-gnueabihf-gcc-8 \ + TARGET_CC=musl-gcc + +build_debug_arm: + ${ARM_PREFIX} cargo build --target=armv7-unknown-linux-musleabihf +.PHONY: build_debug_arm + +build_release_arm: + docker run ${DOCKERFLAGS} ${DOCKERIMG} /bin/sh -c 'cargo build --release --target=armv7-unknown-linux-gnueabihf' +.PHONY: build_release_arm + +docker_build_release_arm: + docker run ${DOCKERFLAGS} ${DOCKERIMG} make build_release_arm diff --git a/src/main.rs b/src/main.rs old mode 100644 new mode 100755 index a43fc02..f4b1e6e --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use teloxide::{prelude::*, utils::command::BotCommand}; #[tokio::main] async fn main() { - run().await + tokio::spawn(run()).await.unwrap(); } #[derive(Envconfig, Clone)]