Skip to content

Commit

Permalink
implement setup_repo for k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicBurkart committed Oct 6, 2020
1 parent 18450a0 commit 3bc51b5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ should not have relative local dependencies prone to breaking.
- if your program produces side effects when initialized, for example when
global constants are initialized, those side effects may be triggered
for each function call.
- currently, turbolift does not guarantee that the target operating system for a
program will also be used with its microservices.

## Current Project Goals
- [ ] support kubernetes ([pr](https://github.com/DominicBurkart/turbolift/pull/2)).
Expand Down
2 changes: 2 additions & 0 deletions turbolift_internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ anyhow = "1"
cached = "0.19"
async-std = "1.6"
async-trait = "0.1"
base64 = "0.13"
machine-ip = "0.2"

# kubernetes-specific requirements
kube = "0.42.0"
Expand Down
42 changes: 37 additions & 5 deletions turbolift_internals/src/kubernetes.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::collections::HashMap;
use std::process::Command;
use std::str::FromStr;

use async_trait::async_trait;
use base64::encode;
use k8s_openapi::api::core::v1::Pod;
use kube::api::{Api, PostParams};
use kube::Client;
use std::collections::HashMap;
use url::Url;

use crate::distributed_platform::{
Expand Down Expand Up @@ -75,12 +79,40 @@ impl DistributionPlatform for K8s {
}
}

fn setup_repo(_function_name: &str, _project_tar: &[u8]) -> DistributionResult<Url> {
unimplemented!()
fn setup_repo(_function_name: &str, _project_tar: &[u8]) -> anyhow::Result<Url> {
let status = Command::new("docker")
.args("run -d -p 5000:5000 --restart=always --name registry registry:2".split(' '))
.status()?; // todo choose an open port
if !status.success() {
return Err(anyhow::anyhow!("repo setup failed"));
}
let address = machine_ip::get().unwrap();
Ok(Url::from_str(&(address.to_string() + ":5000"))?)
}

fn make_image(_function_name: &str, _project_tar: &[u8]) -> DistributionResult<ImageTag> {
unimplemented!()
fn make_image(function_name: &str, project_tar: &[u8]) -> anyhow::Result<ImageTag> {
let tar_base64 = encode(project_tar);
let mut docker_file = format!(
"\
FROM rustlang/rust:nightly
RUN apt-get update \
&& apt-get install -y coreutils \
&& rm -rf /var/lib/apt/lists/*
base64 --decode {} > f.tar
tar xvf f.tar
",
tar_base64
);
docker_file.insert(0, '\'');
docker_file.push('\'');
let tag_flag = "-t ".to_string() + function_name;
let status = Command::new("docker")
.args(&["build", &tag_flag, "-", &docker_file])
.status()?;
if status.success() {
return Err(anyhow::anyhow!("docker image build failure"));
}
Ok(function_name.to_string())
}

fn add_image_to_repo(_local_tag: ImageTag) -> DistributionResult<ImageTag> {
Expand Down

0 comments on commit 3bc51b5

Please sign in to comment.