From 99891e413ec956ff90e24ba2b6fde527442127f3 Mon Sep 17 00:00:00 2001 From: Sandro Mello Date: Thu, 27 Oct 2022 12:53:17 -0300 Subject: [PATCH] Add entrypoint to deal with starting dev/prod modes (#37) - Change the ui api url on runtime if the API_URL variable is set - Add volume directive on Dockerfile to audit sessions - Remove trusted proxies on gin --- Dockerfile | 7 +++++-- README.md | 2 +- client/cmd/connect.go | 1 - client/cmd/start.go | 1 + gateway/api/server.go | 2 ++ rootfs/app/entrypoint.sh | 14 ++++++++++++++ rootfs/app/start-dev.sh | 9 ++++----- scripts/run-dev.sh | 1 + 8 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 rootfs/app/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index bbea8d30..dfae5c28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,9 @@ ENV ACCEPT_EULA=y ADD rootfs/tmp/* /tmp/ # Common -RUN mkdir -p /app && apt-get update -y && \ +RUN mkdir -p /app && \ + mkdir -p /opt/hoop/sessions && \ + apt-get update -y && \ apt-get install -y \ locales \ tini \ @@ -67,6 +69,7 @@ ENV LC_ALL en_US.UTF-8 ENV PATH="/opt/mssql-tools/bin:/app:${PATH}" ADD rootfs/app/start-dev.sh /app/ +ADD rootfs/app/entrypoint.sh /app/ COPY rootfs/ui /app/ui COPY hoop* /app/ RUN chmod +x /app/* @@ -75,4 +78,4 @@ EXPOSE 8009 EXPOSE 8010 ENTRYPOINT ["tini", "--"] -CMD ["/app/start-dev.sh"] +CMD ["/app/entrypoint.sh"] diff --git a/README.md b/README.md index 0afda1ab..63ade3da 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To customize the identity provider, the following variables can be set: | IDP_AUDIENCE | Audience of identity provider | no | no | yes | | IDP_JWKS_URL | Public keys endpoint of identity provider | no | no | yes | | IDP_AUTHORIZE_ENDPOINT | Authorization endpoint of identity provider | no | no | yes | -| IDP_TOKEN_ENDPOINTs | Token endpoint of identity provider | no | no | yes | +| IDP_TOKEN_ENDPOINT | Token endpoint of identity provider | no | no | yes | ## Development QuickStart diff --git a/client/cmd/connect.go b/client/cmd/connect.go index 5ad11c27..c8e0ed79 100644 --- a/client/cmd/connect.go +++ b/client/cmd/connect.go @@ -10,7 +10,6 @@ import ( "github.com/briandowns/spinner" "github.com/muesli/termenv" - _ "github.com/muesli/termenv" "github.com/runopsio/hoop/client/proxyexec" "github.com/runopsio/hoop/client/proxypg" "github.com/runopsio/hoop/common/grpc" diff --git a/client/cmd/start.go b/client/cmd/start.go index 7fa950ac..e075ae83 100644 --- a/client/cmd/start.go +++ b/client/cmd/start.go @@ -53,6 +53,7 @@ var startCmd = &cobra.Command{ } dockerArgs := []string{ "run", + "-e", "PROFILE=dev", "-p", "8009:8009", "-p", "8010:8010", "--name", containerName, diff --git a/gateway/api/server.go b/gateway/api/server.go index a42e4ea6..be4f625c 100644 --- a/gateway/api/server.go +++ b/gateway/api/server.go @@ -35,6 +35,8 @@ func (api *Api) StartAPI() { os.Setenv("PORT", "8009") } route := gin.Default() + // https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies + route.SetTrustedProxies(nil) // UI staticUiPath := os.Getenv("STATIC_UI_PATH") if staticUiPath == "" { diff --git a/rootfs/app/entrypoint.sh b/rootfs/app/entrypoint.sh new file mode 100644 index 00000000..a17991ad --- /dev/null +++ b/rootfs/app/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +export GIN_MODE=release +if [[ "$PROFILE" == "dev" ]]; then + /app/start-dev.sh + exit $? +fi + +# change which API to call in the UI on runtime +if [[ "$API_URL" != "" ]]; then + sed "s/http:\/\/localhost:8009/$API_URL/g" -i app/ui/public/js/app.js +fi + +"${@}" \ No newline at end of file diff --git a/rootfs/app/start-dev.sh b/rootfs/app/start-dev.sh index 97719bae..ead62431 100644 --- a/rootfs/app/start-dev.sh +++ b/rootfs/app/start-dev.sh @@ -1,11 +1,10 @@ #!/bin/bash cat - > xtdb.edn < STARTING DATABASE..." 2>/dev/null 1>&2 java -jar /app/xtdb-in-memory-1.22.0-$(uname -m)/xtdb-in-memory.jar & -until curl -s -f -o /dev/null "http://127.0.0.1:3000/_xtdb/status" +until curl -s -f -o /dev/null "http://127.0.0.1:3001/_xtdb/status" do echo -n "." sleep 1 @@ -16,12 +15,12 @@ echo "--> STARTING GATEWAY ..." export PORT=8009 export PROFILE=dev export GIN_MODE=release -export XTDB_ADDRESS=http://127.0.0.1:3000 +export XTDB_ADDRESS=http://127.0.0.1:3001 /app/hoop start gateway & unset PORT PROFILE GIN_MODE XTDB_ADDRESS -until curl -s -f -o /dev/null "http://127.0.0.1:8009/agents" +until curl -s -f -o /dev/null "http://127.0.0.1:8009/api/agents" do sleep 0.2 done diff --git a/scripts/run-dev.sh b/scripts/run-dev.sh index ffce8908..dafd469f 100755 --- a/scripts/run-dev.sh +++ b/scripts/run-dev.sh @@ -24,6 +24,7 @@ export PORT=8009 export PROFILE=dev export XTDB_ADDRESS=http://127.0.0.1:3000 export PLUGIN_AUDIT_PATH=/tmp/hoopsessions +export GIN_MODE=debug go build -o /tmp/hoop github.com/runopsio/hoop/client /tmp/hoop start gateway &