Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from Cargill/amundson-merge-pike
Browse files Browse the repository at this point in the history
Merge pike code into grid
  • Loading branch information
vaporos authored Mar 25, 2019
2 parents 898d072 + 8c6b94b commit 670626d
Show file tree
Hide file tree
Showing 79 changed files with 5,953 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sawtooth-pike/addresser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2018 Cargill Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[package]
name = "addresser"
version = "0.1.0"
authors = ["Cargill"]

[dependencies]
45 changes: 45 additions & 0 deletions sawtooth-pike/addresser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2018 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/// Represents part of address that designates resource type
#[derive(Debug)]
pub enum Resource {
AGENT,
ORG
}

/// Convert resource part to byte value in hex
pub fn resource_to_byte(part: Resource) -> String {
match part {
Resource::AGENT => String::from("00"),
Resource::ORG => String::from("01")
}
}

/// Convert byte string to Resource
pub fn byte_to_resource(bytes: &str) -> Result<Resource, ResourceError> {
match bytes {
"00" => Ok(Resource::AGENT),
"01" => Ok(Resource::ORG),
_ => Err(ResourceError::UnknownResource(
format!("No resource found matching byte pattern {}", bytes)))
}
}


#[derive(Debug)]
pub enum ResourceError {
UnknownResource(String)
}
39 changes: 39 additions & 0 deletions sawtooth-pike/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2018 Cargill Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[package]
name = "pike-api"
version = "0.0.0"
authors = ["Cargill, Incorporated"]

[dependencies]
rocket = "0.3.3"
rocket_codegen = "0.3.8"
rocket_cors = "0.2.0"
serde = "1.0"
serde_yaml = "0.7"
serde_json = "1.0"
serde_derive = "1.0"
sawtooth-sdk = "^0.2"
pike_db = { path = "../db/pike_db/" }
protobuf = "2"
uuid = { version = "0.5", features = ["v4"] }

[dependencies.rocket_contrib]
version = "*"
default-features = false
features = ["json"]

[build-dependencies]
protoc-rust = "2"
38 changes: 38 additions & 0 deletions sawtooth-pike/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2018 Cargill Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:bionic

RUN apt-get update \
&& apt-get install -y -q \
curl \
gcc \
libpq-dev \
libssl-dev \
libzmq3-dev \
pkg-config \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# For Building Protobufs
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& /root/.cargo/bin/rustup default nightly \
&& curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \
&& unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \
&& rm protoc-3.5.1-linux-x86_64.zip

WORKDIR /project/contracts/sawtooth-pike/api

ENV PATH=$PATH:/protoc3/bin:/root/.cargo/bin:/project/contracts/sawtooth-pike/api/target/debug/
62 changes: 62 additions & 0 deletions sawtooth-pike/api/Dockerfile-installed-bionic
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2018 Cargill Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# docker build -f contracts/sawtooth-pike/api/Dockerfile-installed-bionic -t sawtooth-pike-api .

# -------------=== pike api build ===-------------

FROM ubuntu:bionic as pike-api-builder

ENV VERSION=AUTO_STRICT

RUN apt-get update \
&& apt-get install -y \
curl \
gcc \
git \
libpq-dev \
libssl-dev \
libzmq3-dev \
pkg-config \
python3 \
unzip

# For Building Protobufs
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& /root/.cargo/bin/rustup default nightly \
&& curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \
&& unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \
&& rm protoc-3.5.1-linux-x86_64.zip

ENV PATH=$PATH:/protoc3/bin
RUN /root/.cargo/bin/cargo install cargo-deb

COPY . /project

WORKDIR /project/contracts/sawtooth-pike/api

RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"$(../../../bin/get_version)\"/" Cargo.toml
RUN /root/.cargo/bin/cargo deb

# -------------=== pike api docker build ===-------------

FROM ubuntu:bionic

COPY --from=pike-api-builder /project/contracts/sawtooth-pike/api/target/debian/pike-api*.deb /tmp

RUN apt-get update \
&& dpkg -i /tmp/pike-api*.deb || true \
&& apt-get -f -y install

ENTRYPOINT ["tail", "-f", "/dev/null"]
62 changes: 62 additions & 0 deletions sawtooth-pike/api/Dockerfile-installed-xenial
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2018 Cargill Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# docker build -f contracts/sawtooth-pike/api/Dockerfile-installed-xenial -t sawtooth-pike-api .

# -------------=== pike api build ===-------------

FROM ubuntu:xenial as pike-api-builder

ENV VERSION=AUTO_STRICT

RUN apt-get update \
&& apt-get install -y \
curl \
gcc \
git \
libpq-dev \
libssl-dev \
libzmq3-dev \
pkg-config \
python3 \
unzip

# For Building Protobufs
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& /root/.cargo/bin/rustup default nightly \
&& curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \
&& unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \
&& rm protoc-3.5.1-linux-x86_64.zip

ENV PATH=$PATH:/protoc3/bin
RUN /root/.cargo/bin/cargo install cargo-deb

COPY . /project

WORKDIR /project/contracts/sawtooth-pike/api

RUN sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"$(../../../bin/get_version)\"/" Cargo.toml
RUN /root/.cargo/bin/cargo deb

# -------------=== pike api docker build ===-------------

FROM ubuntu:xenial

COPY --from=pike-api-builder /project/contracts/sawtooth-pike/api/target/debian/pike-api*.deb /tmp

RUN apt-get update \
&& dpkg -i /tmp/pike-api*.deb || true \
&& apt-get -f -y install

ENTRYPOINT ["tail", "-f", "/dev/null"]
39 changes: 39 additions & 0 deletions sawtooth-pike/api/Dockerfile-swagger-ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2018 Cargill Incorporated
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:bionic

RUN apt-get update \
&& apt-get install -y -q \
apache2 \
curl \
vim \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*

WORKDIR /var/www

RUN curl \
-s https://codeload.github.com/swagger-api/swagger-ui/tar.gz/v3.6.0 \
-o swagger-ui.tar.gz
RUN tar xfz swagger-ui.tar.gz
RUN mv swagger-ui-3.6.0/dist/* /var/www/html/

RUN sed -ibak \
's#http://petstore.swagger.io/v2/swagger.json#http://localhost:9001/openapi.yaml#' \
/var/www/html/index.html

EXPOSE 80

CMD ["apachectl", "-D", "FOREGROUND"]
34 changes: 34 additions & 0 deletions sawtooth-pike/api/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2018 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate protoc_rust;
use protoc_rust::Customize;

use std::fs;
use std::fs::File;
use std::io::prelude::*;

fn main() {
fs::create_dir_all("src/protos").unwrap();
protoc_rust::run(protoc_rust::Args {
out_dir: "src/protos",
input: &["../protos/payload.proto", "../protos/state.proto"],
includes: &["../protos"],
customize: Customize::default(),
}).expect("protoc");

let mut file = File::create("src/protos/mod.rs").unwrap();
file.write_all(b"pub mod payload;\n").unwrap();
file.write_all(b"pub mod state;\n").unwrap();
}
Loading

0 comments on commit 670626d

Please sign in to comment.