Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Azat Alimov
POD
Commits
3e18aeef
Commit
3e18aeef
authored
5 years ago
by
Bijun Li
Browse files
Options
Download
Email Patches
Plain Diff
Update for merge
parent
dae24b82
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
Dockerfile
+2
-2
Dockerfile
Dockerfile-binary
+1
-1
Dockerfile-binary
Dockerfile-musl
+0
-31
Dockerfile-musl
Settings.toml
+6
-2
Settings.toml
docker-compose.yml
+13
-9
docker-compose.yml
src/dgraph_database.rs
+4
-2
src/dgraph_database.rs
src/internal_api.rs
+7
-9
src/internal_api.rs
src/main.rs
+5
-5
src/main.rs
src/warp_api.rs
+1
-1
src/warp_api.rs
tools/start-dgraph.sh
+1
-1
tools/start-dgraph.sh
tools/start-pod.sh
+1
-1
tools/start-pod.sh
with
41 additions
and
64 deletions
+41
-64
Dockerfile
+
2
-
2
View file @
3e18aeef
...
...
@@ -15,8 +15,8 @@ COPY Cargo.toml Cargo.toml
COPY
Settings.toml Settings.toml
COPY
src src
RUN
cargo build
RUN
cargo build
--release
EXPOSE
3030
CMD
["./target/
debug
/pod"]
CMD
["./target/
release
/pod"]
This diff is collapsed.
Click to expand it.
Dockerfile-binary
+
1
-
1
View file @
3e18aeef
...
...
@@ -3,7 +3,7 @@ FROM ubuntu:latest
WORKDIR /usr/src/pod
COPY Settings.toml Settings.toml
COPY target/
debug
/pod pod
COPY target/
release
/pod pod
EXPOSE 3030
...
...
This diff is collapsed.
Click to expand it.
Dockerfile-musl
deleted
100644 → 0
+
0
-
31
View file @
dae24b82
# ------------------------------------------------------------------------------
# Cargo Build Stage
# ------------------------------------------------------------------------------
FROM rust:latest as cargo-build
RUN apt-get update
RUN apt-get install -y musl-tools cmake golang
RUN ln -s /usr/bin/musl-gcc /usr/bin/musl-g++
RUN rustup target add x86_64-unknown-linux-musl
WORKDIR /usr/src/pod
COPY Cargo.toml Cargo.toml
COPY Cargo.lock Cargo.lock
RUN mkdir src \
&& echo "fn main() {print!(\"Dummy main\");} // dummy file" > src/main.rs
RUN cargo build --release --target=x86_64-unknown-linux-musl
RUN rm -f target/x86_64-unknown-linux-musl/release/deps/pod*
COPY . .
RUN RUSTFLAGS="-C linker=musl-gcc -C link-arg=-L/usr/local/musl/lib" cargo build --release --target=x86_64-unknown-linux-musl
# ------------------------------------------------------------------------------
# Final Stage
# ------------------------------------------------------------------------------
FROM alpine:latest
COPY --from=cargo-build /usr/src/myapp/target/x86_64-unknown-linux-musl/release/pod /usr/local/bin/pod
CMD ["pod"]
This diff is collapsed.
Click to expand it.
Settings.toml
+
6
-
2
View file @
3e18aeef
drop
=
false
set
=
false
# Config option for dropping schema
schema_drop
=
false
# Config option for adding schema to dgraph
schema_set
=
false
# dgraph host
dgraph_host
=
"localhost"
This diff is collapsed.
Click to expand it.
docker-compose.yml
+
13
-
9
View file @
3e18aeef
version
:
'
3
.0
'
version
:
'
3'
services
:
dgraph
:
image
:
dgraph/standalone:latest
ports
:
-
"
8000:8000"
-
"
5080:5080"
-
"
6080:6080"
-
"
8080:8080"
-
"
9080:9080"
network_mode
:
"
host"
networks
:
-
my-net
pod
:
build
:
context
:
.
args
:
SCHEMA_DROP
:
'
false'
SCHEMA_SET
:
'
true'
dockerfile
:
Dockerfile
restart
:
always
environment
:
-
SCHEMA_DROP=false
-
SCHEMA_SET=true
-
DGRAPH_HOST=pod_dgraph_1
image
:
pod:latest
ports
:
-
"
3030:3030"
depends_on
:
-
dgraph
network_mode
:
"
host"
networks
:
-
my-net
networks
:
my-net
:
This diff is collapsed.
Click to expand it.
src/dgraph_database.rs
+
4
-
2
View file @
3e18aeef
use
crate
::
data_model
;
use
config
::
Config
;
use
dgraph
::
*
;
/// Create dgraph gRPC connection.
pub
fn
create_dgraph
()
->
Dgraph
{
let
dgraph_client
=
dgraph
::
new_dgraph_client
(
"localhost:9080"
);
pub
fn
create_dgraph
(
settings
:
&
Config
)
->
Dgraph
{
let
dgraph_host
=
settings
.get_str
(
"dgraph_host"
)
.unwrap
();
let
dgraph_client
=
dgraph
::
new_dgraph_client
((
dgraph_host
+
":9080"
)
.as_str
());
Dgraph
::
new
(
vec!
[
dgraph_client
])
}
...
...
This diff is collapsed.
Click to expand it.
src/internal_api.rs
+
7
-
9
View file @
3e18aeef
...
...
@@ -8,15 +8,13 @@ use std::collections::HashMap;
use
std
::
str
;
use
std
::
sync
::
Arc
;
/// Check if the `uid` exists in DB, or if DB contains any items
fn
item_not_found
(
result
:
&
Value
)
->
bool
{
/// Verify if the response contains the content of the requested node.
/// Return `true` if response doesn't contain any content.
/// Return `false` if the node is found and its content is included in the response.
fn
response_is_empty
(
result
:
&
Value
)
->
bool
{
let
result
=
result
.get
(
"items"
)
.unwrap
()
.as_array
()
.unwrap
();
let
empty
=
result
.len
()
==
0
||
result
.first
()
.unwrap
()
.get
(
"type"
)
==
Option
::
None
;
if
empty
{
true
}
else
{
false
}
empty
}
/// Get project version as seen by Cargo.
...
...
@@ -48,7 +46,7 @@ pub fn get_item(_dgraph: &Arc<Dgraph>, uid: u64) -> Option<String> {
.expect
(
"query"
);
let
result
:
Value
=
serde_json
::
from_slice
(
&
resp
.json
)
.unwrap
();
if
item_not_found
(
&
result
)
{
if
response_is_empty
(
&
result
)
{
None
}
else
{
Some
(
sync_state
::
set_syncstate
(
result
))
...
...
@@ -69,7 +67,7 @@ pub fn get_all_items(_dgraph: &Arc<Dgraph>) -> Option<String> {
let
resp
=
_dgraph
.new_readonly_txn
()
.query
(
query
)
.expect
(
"query"
);
let
result
:
Value
=
serde_json
::
from_slice
(
&
resp
.json
)
.unwrap
();
if
item_not_found
(
&
result
)
{
if
response_is_empty
(
&
result
)
{
None
}
else
{
Some
(
sync_state
::
set_syncstate_all
(
result
))
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
5
-
5
View file @
3e18aeef
...
...
@@ -22,22 +22,22 @@ async fn main() {
})
.init
();
let
dgraph
=
dgraph_database
::
create_dgraph
();
let
mut
settings
=
config
::
Config
::
default
();
settings
.merge
(
config
::
File
::
with_name
(
"Settings"
))
.unwrap
()
.merge
(
config
::
Environment
::
with_prefix
(
"SCHEMA"
))
.merge
(
config
::
Environment
::
new
(
))
.unwrap
();
let
dgraph
=
dgraph_database
::
create_dgraph
(
&
settings
);
// Drop schema only in DROP mode.
// Add "SCHEMA_DROP=true" before executable, default is FALSE.
if
settings
.get_
str
(
"
drop"
)
.unwrap
()
.eq
(
"true"
)
{
if
settings
.get_
bool
(
"schema_
drop"
)
.unwrap
()
{
dgraph_database
::
drop_schema_and_all_data_irreversibly
(
&
dgraph
);
}
// Set schema only in SET mode.
// Add "SCHEMA_SET=true" before executable, default is FALSE.
if
settings
.get_
str
(
"
set"
)
.unwrap
()
.eq
(
"true"
)
{
if
settings
.get_
bool
(
"schema_
set"
)
.unwrap
()
{
dgraph_database
::
set_schema
(
&
dgraph
);
}
// Start web framework warp.
...
...
This diff is collapsed.
Click to expand it.
src/warp_api.rs
+
1
-
1
View file @
3e18aeef
...
...
@@ -122,6 +122,6 @@ pub async fn run_server(server_name: String, dgraph: Dgraph) {
.or
(
update_item
)
.or
(
delete_item
),
)
.run
(([
127
,
0
,
0
,
1
],
3030
))
.run
(([
0
,
0
,
0
,
0
],
3030
))
.await
;
}
This diff is collapsed.
Click to expand it.
tools/start-dgraph.sh
+
1
-
1
View file @
3e18aeef
docker run
--rm
-it
-p
8000:8000
-p
5080:5080
-p
6080:6080
-p
8080:8080
-p
9080:9080
--network
host
dgraph/standalone:latest
docker run
--rm
-it
-p
8000:8000
-p
8080:8080
-p
9080:9080
--network
my-net
--name
pod_dgraph_1
dgraph/standalone:latest
This diff is collapsed.
Click to expand it.
tools/start-pod.sh
+
1
-
1
View file @
3e18aeef
docker run
--rm
-it
--network
host
-p
3030:3030
-e
SCHEMA_SET
=
true
pod:latest
docker run
--rm
-it
-p
3030:3030
-e
SCHEMA_SET
=
true
-e
DGRAPH_HOST
=
pod_dgraph_1
--network
my-net
--name
pod_pod_1
pod:latest
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment