Skip to content

Commit

Permalink
Moving lagoon url environment handling to yarn start level
Browse files Browse the repository at this point in the history
Seems like the only place where we can access the Lagoon env variables
is via a script in the node container.
We probably have to do this differently with production domains, since
we are now matching urls called something with: "nginx", "varnish" and
such.
  • Loading branch information
spaceo committed Dec 3, 2024
1 parent 81bcd5c commit d0182c9
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 56 deletions.
1 change: 0 additions & 1 deletion .env.prod

This file was deleted.

3 changes: 0 additions & 3 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ UNILOGIN_SESSION_SECRET=XXX

NEXT_PUBLIC_APP_URL=https://hellboy.the-movie.com
UNILOGIN_WELLKNOWN_URL=https://hi-i-am-well-known-url.com

LAGOON_ROUTES=https://node.pr-1707.dpl-cms.dplplat01.dpl.reload.dk,https://varnish.pr-1707.dpl-cms.dplplat01.dpl.reload.dk
NEXT_PUBLIC_LAGOON_ROUTES=$LAGOON_ROUTES
2 changes: 1 addition & 1 deletion __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Config test suite", () => {
expect(() => goConfig("unknown.thingy")).toThrowError(MissingConfigurationError)
})

test("That the env variable NEXT_PUBLIC_APP_URL has precedence over NEXT_PUBLIC_LAGOON_ROUTES", async () => {
test("That the env variable NEXT_PUBLIC_APP_URL defines the current app url", async () => {
const appUrl = goConfig("app.url")
expect(appUrl).toBe("https://hellboy.the-movie.com")
})
Expand Down
11 changes: 0 additions & 11 deletions __tests__/dpl-cms.graphql.test.ts

This file was deleted.

22 changes: 0 additions & 22 deletions __tests__/lagoon.test.ts

This file was deleted.

29 changes: 29 additions & 0 deletions lagoon/set-env-variables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

getLagoonUrl() {
local type=$1
IFS=',' read -r -a routes <<< "$LAGOON_ROUTES"
for route in "${routes[@]}"; do
if [[ $route == *"$type"* ]]; then
echo "$route"
return
fi
done
}

# Make sure app.url is set in application
app_url=$(getLagoonUrl node)
if [ -z "$app_url" ]; then
echo "Error: Unable to determine app URL"
exit 1
fi

# Make sure the DPL CMS graphql schema endpoint is set in application
cms_url=$(getLagoonUrl nginx)
if [ -z "$cms_url" ]; then
echo "Error: Unable to determine CMS URL"
exit 1
fi


export NEXT_PUBLIC_APP_URL="$app_url"
export NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS="$cms_url/graphql"
3 changes: 3 additions & 0 deletions lagoon/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# cd /app
# npm run dev
# fi

source set-env-variables.sh

printenv

cd /app
Expand Down
3 changes: 0 additions & 3 deletions lib/config/resolvers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const app = {
if (process.env.NEXT_PUBLIC_APP_URL) {
return process.env.NEXT_PUBLIC_APP_URL
}
if (process.env.NEXT_PUBLIC_LAGOON_ROUTES) {
return getLagoonUrl("node")
}
},
}

Expand Down
4 changes: 1 addition & 3 deletions lib/graphql/fetchers/dpl-cms.fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { getDplCmsGraphqlEndpoint } from "@/lib/helpers/dpl-cms.graphql"

export function fetcher<TData, TVariables>(
query: string,
variables?: TVariables,
options?: RequestInit["headers"]
) {
const dplCmsGraphqlEndpoint = getDplCmsGraphqlEndpoint()
const dplCmsGraphqlEndpoint = process.env.NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS
const dplCmsGraphqlBasicToken = process.env.NEXT_PUBLIC_GRAPHQL_BASIC_TOKEN_DPL_CMS

if (!dplCmsGraphqlEndpoint || !dplCmsGraphqlBasicToken) {
Expand Down
12 changes: 0 additions & 12 deletions lib/helpers/dpl-cms.graphql.ts

This file was deleted.

0 comments on commit d0182c9

Please sign in to comment.