Skip to content

Commit

Permalink
rust: add basic Rust platform
Browse files Browse the repository at this point in the history
 Refs tsuru#20
  • Loading branch information
scorphus committed Dec 2, 2018
1 parent e154359 commit d273496
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All platforms are available in Docker Hub:
* tsuru/python: https://hub.docker.com/r/tsuru/python/
* tsuru/pypy: https://hub.docker.com/r/tsuru/pypy/
* tsuru/ruby: https://hub.docker.com/r/tsuru/ruby/
* tsuru/rust: https://hub.docker.com/r/tsuru/rust/
* tsuru/static: https://hub.docker.com/r/tsuru/static/

Installing platforms
Expand Down Expand Up @@ -60,3 +61,10 @@ We provide a base image which platform developers can use to build upon:
a base deployment script, which handles package downloading and extraction in
proper path, along with operating system package management. For more details,
check the README of base-platform.

To update a platform:

docker rmi 127.0.0.1:5000/rust
docker build -t 127.0.0.1:5000/rust .
docker push 127.0.0.1:5000/rust
tsuru-admin platform-update rust -i 127.0.0.1:5000/rust
11 changes: 11 additions & 0 deletions rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2016 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

FROM tsuru/base-platform
RUN pwd
RUN ls
RUN ls .
ADD . /var/lib/tsuru/rust
RUN cp /var/lib/tsuru/rust/deploy /var/lib/tsuru
RUN /var/lib/tsuru/rust/install
1 change: 1 addition & 0 deletions rust/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: %web%
24 changes: 24 additions & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rust Platform

The Rust platform supports code deployment, the application is built in the
target.


## Code deployment

If you just run a ``git push`` of your code, tsuru will install the application
using ``cargo install`` – which fetches all the dependencies automatically.

##Binary deployment

For binary deployment, ensure the name of the binary file matches what's in
Procfile. Also make sure it matches the target platform (usually linux_amd64),
For example:

$ ls
Cargo.lock Cargo.toml src target
$ rustup target add x86_64-unknown-linux-gnu
$ cargo build --release --target=x86_64-unknown-linux-gnu
$ cat Procfile
web: ./hello_world
$ tsuru app-deploy -a [app-name] target/x86_64-unknown-linux-gnu/release/hello_world Procfile
23 changes: 23 additions & 0 deletions rust/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -el

# Copyright 2016 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

SOURCE_DIR=/var/lib/tsuru
source ${SOURCE_DIR}/base/deploy
source ${SOURCE_DIR}/base/rc/config

if [ -f ${CURRENT_DIR}/Cargo.toml ]; then
pushd ${CURRENT_DIR} >/dev/null 2>&1
if [ ! -f ${CURRENT_DIR}/Procfile ]; then
echo "Procfile not found, using default one."
PKG_NAME=$(awk -F ' *= *' \
'{if ($1 ~ /^\[package\]/) stop=1; else if ($1 ~ /^name$/ && stop){print $2; exit}}' \
${CURRENT_DIR}/Cargo.toml | cut -d\" -f2)
echo "Package name: $PKG_NAME"
sed s:%web%:$PKG_NAME: ${SOURCE_DIR}/default/Procfile > ${CURRENT_DIR}/Procfile
fi
cargo install --force --verbose
popd >/dev/null 2>&1
fi
26 changes: 26 additions & 0 deletions rust/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -el

# Copyright 2016 tsuru authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

SOURCE_DIR=/var/lib/tsuru
source ${SOURCE_DIR}/base/rc/config

# As of 2016-07-07 `file` is needed. Please check:
# https://github.com/rust-lang-nursery/rustup.rs/issues/466
apt-get update && apt-get install -y file gcc git

sh <(curl -sSf https://static.rust-lang.org/rustup.sh) --verbose -y --channel=stable

cp ${SOURCE_DIR}/rust/Procfile ${SOURCE_DIR}/default/Procfile

CARGO_HOME=${APP_DIR}/.cargo
mkdir -p ${CARGO_HOME}/bin
mkdir ${CARGO_HOME}/target

echo "export CARGO_HOME=${CARGO_HOME}" >> ${HOME}/.profile
echo 'export CARGO_TARGET_DIR=$CARGO_HOME/target' >> ${HOME}/.profile
echo 'PATH=$CARGO_HOME/bin:$PATH' >> ${HOME}/.profile

chown -R ${USER}:${USER} ${CARGO_HOME}

0 comments on commit d273496

Please sign in to comment.