Skip to content

Commit

Permalink
Add entrypoint to deal with starting dev/prod modes (#37)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
sandromello authored Oct 27, 2022
1 parent b1c70a1 commit 99891e4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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/*
Expand All @@ -75,4 +78,4 @@ EXPOSE 8009
EXPOSE 8010

ENTRYPOINT ["tini", "--"]
CMD ["/app/start-dev.sh"]
CMD ["/app/entrypoint.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion client/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions client/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var startCmd = &cobra.Command{
}
dockerArgs := []string{
"run",
"-e", "PROFILE=dev",
"-p", "8009:8009",
"-p", "8010:8010",
"--name", containerName,
Expand Down
2 changes: 2 additions & 0 deletions gateway/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
14 changes: 14 additions & 0 deletions rootfs/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

"${@}"
9 changes: 4 additions & 5 deletions rootfs/app/start-dev.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/bash
cat - > xtdb.edn <<EOF
{:xtdb.http-server/server {}
:xtdb.calcite/server {}}
{:xtdb.http-server/server {:port 3001}}
EOF
echo "--> 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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/run-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down

0 comments on commit 99891e4

Please sign in to comment.