Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cyberdproxy process to docker container. Add status endpoint #55

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cosmos/poc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ COPY --from=builder /go/bin/cyberd /usr/bin/cyberd
COPY --from=builder /go/bin/cyberdcli /usr/bin/cyberdcli
COPY --from=builder /go/bin/cyberdproxy /usr/bin/cyberdproxy

COPY start_script.sh start_script.sh
RUN chmod +x start_script.sh

COPY genesis.json /genesis.json
COPY config.toml /config.toml

EXPOSE 26656 26657
EXPOSE 26656 26657 26660

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["cyberd", "start"]
CMD ["./start_script.sh"]
7 changes: 4 additions & 3 deletions cosmos/poc/cyberdproxy/cyberdproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func StartCmd() *cobra.Command {

mux := http.NewServeMux()
mux.HandleFunc("/link", proxy.LinkHandlerFn(ctx))
mux.HandleFunc("/search", proxy.SearchHandlerFn(ctx))
mux.HandleFunc("/account", proxy.AccountHandlerFn(ctx))
mux.HandleFunc("/health", proxy.HealthHandlerFn(ctx))
mux.HandleFunc("/search", proxy.GetWithParamHandlerFn(ctx, "/search", "cid"))
mux.HandleFunc("/account", proxy.GetWithParamHandlerFn(ctx, "/account", "address"))
mux.HandleFunc("/health", proxy.GetHandlerFn(ctx, "/health"))
mux.HandleFunc("/status", proxy.GetHandlerFn(ctx, "/status"))

c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
Expand Down
28 changes: 0 additions & 28 deletions cosmos/poc/cyberdproxy/proxy/account.go

This file was deleted.

41 changes: 41 additions & 0 deletions cosmos/poc/cyberdproxy/proxy/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package proxy

import "net/http"

func GetHandlerFn(ctx ProxyContext, endpoint string) func(http.ResponseWriter, *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json")

resp, err := ctx.Get(endpoint)
if err != nil {
HandleError(err, w)
return
}

w.Write(resp)
}
}

func GetWithParamHandlerFn(ctx ProxyContext, endpoint string, param string) func(http.ResponseWriter, *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json")

paramValue, err := getSingleParamValue(param, r)
if err != nil {
HandleError(err, w)
return
}

resp, err := ctx.Get(endpoint + "?" + param + "=\"" + paramValue + "\"")
if err != nil {
HandleError(err, w)
return
}

w.Write(resp)
}
}
21 changes: 0 additions & 21 deletions cosmos/poc/cyberdproxy/proxy/health.go

This file was deleted.

28 changes: 0 additions & 28 deletions cosmos/poc/cyberdproxy/proxy/search.go

This file was deleted.

2 changes: 1 addition & 1 deletion cosmos/poc/docker_build_run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

docker build -t cybercongress/cyberd .
docker run -d --restart always --name=cyberd -p 34656:26656 -p 34657:26657 -v /cyberdata/cyberd/data:/root/.cyberd/data -v /cyberdata/cyberd/config:/root/.cyberd/config cybernode/cyberd:master
docker run -d --restart always --name=cyberd -p 34656:26656 -p 34657:26657 -p 34660:26660 -v /cyberdata/cyberd/data:/root/.cyberd/data -v /cyberdata/cyberd/config:/root/.cyberd/config cybernode/cyberd:master
2 changes: 1 addition & 1 deletion cosmos/poc/scripts/reset_earth_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ docker stop cyberd
docker rm cyberd
docker run --rm -v /cyberdata/cyberd/data:/root/.cyberd/data -v /cyberdata/cyberd/config:/root/.cyberd/config cybernode/cyberd:master cyberd unsafe_reset_all
docker pull cybernode/cyberd:master
docker run -d --restart always --name=cyberd -p 34656:26656 -p 34657:26657 -v /cyberdata/cyberd/data:/root/.cyberd/data -v /cyberdata/cyberd/config:/root/.cyberd/config cybernode/cyberd:master
docker run -d --restart always --name=cyberd -p 34656:26656 -p 34657:26657 -p 34660:26660 -v /cyberdata/cyberd/data:/root/.cyberd/data -v /cyberdata/cyberd/config:/root/.cyberd/config cybernode/cyberd:master
36 changes: 36 additions & 0 deletions cosmos/poc/start_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# Start the first process
cyberd start . &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start cyberd: $status"
exit $status
fi

# Start the second process
cyberdproxy start . &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start cyberdproxy: $status"
exit $status
fi

# Naive check runs checks once a minute to see if either of the processes exited.
# This illustrates part of the heavy lifting you need to do if you want to run
# more than one service in a container. The container exits with an error
# if it detects that either of the processes has exited.
# Otherwise it loops forever, waking up every 60 seconds
while sleep 60; do
ps aux |grep cyberd |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep cyberdproxy |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done