Skip to content

Commit

Permalink
Changing to new gcp2 projects and removing old terraform env
Browse files Browse the repository at this point in the history
  • Loading branch information
tysseng committed Jan 23, 2024
1 parent c220655 commit 1f66b5d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
8 changes: 0 additions & 8 deletions .env.terraform

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"build:staging": "tsc && npm run populate-env-vars staging",
"build:prod": "tsc && npm run populate-env-vars prod",
"build:beta": "tsc && npm run populate-env-vars beta",
"build:terraform": "tsc && npm run populate-env-vars terraform",
"deploy": "./scripts/deploy.sh",
"ts": "tsc --noEmit",
"transpile": "tsc",
Expand Down
17 changes: 16 additions & 1 deletion scripts/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ set -e

ENV="${1:-dev}"

if ! [[ "$ENV" =~ ^(dev|staging|prod|beta)$ ]]; then
echo -e "🙈 Invalid ENV: $ENV\n"
exit 1
fi

if [[ $ENV = "dev" ]]; then
PROJECT="ent-enturapp-dev"
elif [[ $ENV = "staging" ]]; then
PROJECT="ent-enturapp-tst"
elif [[ $ENV = "beta" ]]; then
PROJECT="ent-enturbeta-prd"
elif [[ $ENV = "prod" ]]; then
PROJECT="entur-prod"
fi

# path to environment specific credential keys used when looking up secrets
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/serviceAccountKeys/entur-$ENV.json"
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/serviceAccountKeys/$PROJECT.json"

# Run transpile in a forked process
npm run transpile -- --watch &
Expand Down
18 changes: 11 additions & 7 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ fi
function deploy {
ENV="${1:-dev}"

if ! [[ "$ENV" =~ ^(dev|staging|prod|beta|terraform)$ ]]; then
if ! [[ "$ENV" =~ ^(dev|staging|prod|beta)$ ]]; then
echo -e "🙈 Invalid ENV: $ENV\n"
exit 1
fi

if [[ $ENV = "terraform" ]]; then
PROJECT="ent-selvbet-terraform-dev"
else
PROJECT="entur-$ENV"
if [[ $ENV = "dev" ]]; then
PROJECT="ent-enturapp-dev"
elif [[ $ENV = "staging" ]]; then
PROJECT="ent-enturapp-tst"
elif [[ $ENV = "beta" ]]; then
PROJECT="ent-enturbeta-prd"
elif [[ $ENV = "prod" ]]; then
PROJECT="entur-prod"
fi

echo " 🧵 Linting ..."
Expand All @@ -38,15 +42,15 @@ function deploy {
KEEPALIVE_JOB="bff-kafka-keepalive"
if gcloud scheduler jobs list --project=$PROJECT | grep -c $KEEPALIVE_JOB; then
echo " 🗑️ Deleting existing keep-alive cron job $HAS_KAFKA_KEEPALIVE..."
gcloud scheduler jobs delete $KEEPALIVE_JOB --quiet --location="us-central1" --project=$PROJECT
gcloud scheduler jobs delete $KEEPALIVE_JOB --quiet --location="europe-west1" --project=$PROJECT
fi
echo " 👷🏻‍♀️ Creating keep-alive cron job ..."
gcloud scheduler jobs create app-engine $KEEPALIVE_JOB --service="bff-kafka" --schedule="every 5 mins" --relative-url="/bff-kafka/keepalive" --http-method=GET --description="Tic, toc, I'm a clock. I prevent bff-kafka from idle timeouts." --project=$PROJECT

HEARTBEAT_JOB="bff-kafka-heartbeat"
if gcloud scheduler jobs list --project=$PROJECT | grep -c $HEARTBEAT_JOB; then
echo " 🗑️ Deleting existing heartbeat cron job ..."
gcloud scheduler jobs delete $HEARTBEAT_JOB --quiet --location="us-central1" --project=$PROJECT
gcloud scheduler jobs delete $HEARTBEAT_JOB --quiet --location="europe-west1" --project=$PROJECT
fi
echo " 👷🏻‍♀️ Creating heartbeat cron job ..."
gcloud scheduler jobs create app-engine $HEARTBEAT_JOB --service="bff-kafka" --schedule="every 1 mins" --relative-url="/bff-kafka/heartbeat" --http-method=GET --description="Can you feel a heartbeat, Doctor? No, he's dead, Jim." --project=$PROJECT
Expand Down
6 changes: 3 additions & 3 deletions serviceAccountKeys/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Put the Google Service Account Keys json files for entur-staging and entur-dev in this folder (serviceAccountKeys).
Put the Google Service Account Keys json files for ent-enturapp-tst and ent-enturapp-dev in this folder (serviceAccountKeys).

Do NOT check in files (they are by default ignored by git).

Files must be named

`entur-<environment>.json`
`<environment>.json`

for example `entur-staging.json`
for example `ent-enturapp-dev.json`

For Entur employees, see the following page for more detailed setup instructions:
https://enturas.atlassian.net/wiki/spaces/DK/pages/2704048286/Bff-kafka
12 changes: 7 additions & 5 deletions src/utils/project.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ENVIRONMENT } from '../config.js'

export const getProjectId = (): string => {
if (ENVIRONMENT === 'nordic-dev') {
return 'ent-clients-nordic-dev'
} else if (ENVIRONMENT === 'terraform') {
return 'ent-selvbet-terraform-dev'
if (ENVIRONMENT === 'staging') {
return 'ent-enturapp-tst'
} else if (ENVIRONMENT === 'beta') {
return 'ent-enturbeta-prd'
} else if (ENVIRONMENT === 'prod') {
return 'entur-prod'
} else {
return `entur-${ENVIRONMENT}`
return 'ent-enturapp-dev'
}
}

0 comments on commit 1f66b5d

Please sign in to comment.