From 3040cc3d5121b49856a35f5666b4e6497e006ca2 Mon Sep 17 00:00:00 2001 From: johannbm Date: Thu, 18 Apr 2024 13:50:55 +0200 Subject: [PATCH] =?UTF-8?q?Oppsett=20for=20=C3=A5=20debugge=20inni=20docke?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/frackend/Dockerfile.dev | 6 +++ apps/frackend/README.md | 31 +++++++++---- apps/frackend/docker-compose.yaml | 4 +- apps/frackend/localenv_setup.py | 75 ------------------------------- apps/frackend/template.localenv | 4 -- 5 files changed, 32 insertions(+), 88 deletions(-) create mode 100644 apps/frackend/Dockerfile.dev delete mode 100644 apps/frackend/localenv_setup.py delete mode 100644 apps/frackend/template.localenv diff --git a/apps/frackend/Dockerfile.dev b/apps/frackend/Dockerfile.dev new file mode 100644 index 000000000..274f4678e --- /dev/null +++ b/apps/frackend/Dockerfile.dev @@ -0,0 +1,6 @@ +FROM gcr.io/distroless/nodejs20-debian12:nonroot +COPY . /app + +WORKDIR /app +EXPOSE 8080 +CMD ["--inspect=0.0.0.0:9229", "dist/index.js"] diff --git a/apps/frackend/README.md b/apps/frackend/README.md index d1a2983e8..bebaaa1f4 100644 --- a/apps/frackend/README.md +++ b/apps/frackend/README.md @@ -1,14 +1,29 @@ -# Frontend for teams +# Frackend for teamkatalogen -### Requires node 16 +### Hent secret -### Set up local env -run python script localenv_setup.py for å få korrekte azure varaiable etc fra k8s secrets +```bash +gcloud auth login -`python3 localenv_setup.py` +# Fra rot kjører du: +python setup_local_azure_secrets.py +``` -### Install deps +### Installer pakker `npm ci` -### Kjør Frackend -`npm run start` +### Bygg Frackend +`npm run build` + +### Kjør docker-compose +`docker-compose up -d --build` +Denne fyrer opp lokal Wonderwall + Frackend + +### Debug Frackend som kjører i Docker +Når Express-serveren kjører lokalt i Docker så eksponerer den port 9229 som du kan koble en debugger til. + +For å få til dette må du lage en debug configuration: +1. Edit configurations +2. Klikk + og velg `attach to Node.js/Chrome` +3. Host: `localhost` port `9229` +4. Kjør så konfigurasjonen og du er klar til å debugge! diff --git a/apps/frackend/docker-compose.yaml b/apps/frackend/docker-compose.yaml index 37dba70f3..dc2a3db13 100644 --- a/apps/frackend/docker-compose.yaml +++ b/apps/frackend/docker-compose.yaml @@ -23,10 +23,12 @@ services: upstream: build: context: . - dockerfile: "Dockerfile" + dockerfile: "Dockerfile.dev" ports: - "8081:8081" + - "9229:9229" environment: + DEBUG: "http-proxy-middleware*" NODE_ENV: "development" EXPRESS_PORT: 8081 EXPRESS_HOST: "::" diff --git a/apps/frackend/localenv_setup.py b/apps/frackend/localenv_setup.py deleted file mode 100644 index 5f01ea2ce..000000000 --- a/apps/frackend/localenv_setup.py +++ /dev/null @@ -1,75 +0,0 @@ -import subprocess as sp -import json -import base64 - -# Setter riktig context for kubectl -sp.run(["kubectl", "config", "use-context", "dev-gcp"]) - -# Henter secretname for frackenden -secretname = sp.getoutput("kubectl get azureapp -n org team-catalog-frackend -o go-template='{{.spec.secretName}}'") -# Henter alle secretene i JSON format -azureInfo = json.loads(sp.getoutput("kubectl -n org get secret " + secretname + " -o json")) - -# Henter og decoder data fra Json variabelen. -# Returnerer en liste med key'en til secreten og selve secreten -def base64Decode(key, url): - if url == True: - x = base64.urlsafe_b64decode(str(azureInfo["data"][key])).decode("utf-8") - else: - x = base64.b64decode(str(azureInfo["data"][key])).decode("utf-8") - - return [key, x] - - - -# Henter secretene vi er ute etter fra azureInfo -# FORMAT - [key, secret] -AZURE_APP_CLIENT_ID=base64Decode("AZURE_APP_CLIENT_ID", False) -AZURE_APP_WELL_KNOWN_URL=base64Decode("AZURE_APP_WELL_KNOWN_URL", True) -AZURE_OPENID_CONFIG_ISSUER=base64Decode("AZURE_OPENID_CONFIG_ISSUER", True) -AZURE_OPENID_CONFIG_TOKEN_ENDPOINT=base64Decode("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT", True) -AZURE_APP_CERTIFICATE_KEY_ID=base64Decode("AZURE_APP_CERTIFICATE_KEY_ID", False) -AZURE_APP_TENANT_ID=base64Decode("AZURE_APP_TENANT_ID", False) -AZURE_APP_CLIENT_SECRET=base64Decode("AZURE_APP_CLIENT_SECRET", False) -AZURE_APP_JWK=base64Decode("AZURE_APP_JWK", False) -AZURE_OPENID_CONFIG_JWKS_URI=base64Decode("AZURE_OPENID_CONFIG_JWKS_URI", True) - -# En liste med alle secretene vi er ute etter -# For å legge til disse i destinasjonsfilen må variabelen leggs til i listen her -kubectlSecrets = [AZURE_APP_CLIENT_ID, AZURE_APP_WELL_KNOWN_URL, AZURE_OPENID_CONFIG_ISSUER, AZURE_OPENID_CONFIG_TOKEN_ENDPOINT, AZURE_APP_CERTIFICATE_KEY_ID, AZURE_APP_TENANT_ID, AZURE_APP_CLIENT_SECRET, AZURE_APP_JWK, AZURE_OPENID_CONFIG_JWKS_URI] - -# Brukes for å huske hvilke linjer i .localenv som skal redigeres -kubectlSecretIndexes = [] - - - -# Filnavn på template fila og på hva navnet på fila skal være -startFile = "template.localenv" -destinationFile = ".env" -sp.run(["cp", startFile, destinationFile]) - -# Redigering av detinationFile -envFile = open(destinationFile) -# Henter innholdet fra fila og lagrer det i en liste -stringList = envFile.readlines() -envFile.close() - -# Må endres på hvis vi endrer på template fila for localenv -lineEnding = "=\n" - -# Finner linjene hvor vi skal sette inn secrets -for key, value in kubectlSecrets: - kubectlSecretIndexes.append(stringList.index(key + lineEnding)) - -#Legger inn secretene i stringList -for index, value in enumerate(kubectlSecretIndexes): - stringList[value] = kubectlSecrets[index][0] + "=" + kubectlSecrets[index][1] + "\n" - - -envFile = open(destinationFile, "w") -# Sletter template kommentaren på toppen -del stringList[0] -# Slår sammen listen med innhold og skriver den til destinationFile -new_StringList = "".join(stringList) -envFile.write(new_StringList) -envFile.close diff --git a/apps/frackend/template.localenv b/apps/frackend/template.localenv deleted file mode 100644 index 9d76c9e8d..000000000 --- a/apps/frackend/template.localenv +++ /dev/null @@ -1,4 +0,0 @@ -NOM_API_SCOPE=api://dev-gcp.nom.nom-api/.default -NOM_API_URL=https://nom-api.intern.dev.nav.no -TEAM_CATALOG_SCOPE=api://dev-gcp.org.team-catalog-backend/.default -TEAM_CATALOG_API_URL=https://teamkatalog-api.intern.dev.nav.no \ No newline at end of file