Skip to content

Commit f347d31

Browse files
authored
Merge pull request #651 from acteng/local-secrets
Fetch secrets for local development
2 parents 09c84d1 + 7623fbc commit f347d31

7 files changed

Lines changed: 103 additions & 13 deletions

File tree

.env

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/playwright.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
VITE_MAPTILER_API_KEY: '${{ secrets.MAPTILER_API_KEY }}'
11+
VITE_RESOURCE_BASE: 'https://atip.uk'
1112

1213
jobs:
1314
test:

.github/workflows/web.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
VITE_MAPTILER_API_KEY: '${{ secrets.MAPTILER_API_KEY }}'
11+
VITE_RESOURCE_BASE: 'https://atip.uk'
1112

1213
permissions:
1314
contents: write

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ public/layers
1111
public/private_layers
1212
backend/app.yaml
1313
ctrf
14+
15+
# IDE
16+
.idea
17+
18+
# env
19+
.env

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,89 @@ This repository contains the Scheme Sketcher and Scheme Browser, two tools for m
44

55
(Note this project used to be called ATIP, Active Travel Infrastructure Platform. This repo retains the old name.)
66

7+
## Prerequisites
8+
9+
1. Install Node 22
10+
1. Install [Bitwarden CLI](https://bitwarden.com/help/cli/#download-and-install)
11+
1. Install Google Cloud CLI and authenticate using ADCs:
12+
```bash
13+
gcloud auth application-default login
14+
```
15+
16+
## Setup
17+
18+
If you have an ATE Bitwarden account you'll need to login via the CLI and configure the application's environment
19+
variables by fetching secrets from Bitwarden.
20+
21+
```bash
22+
./get-env.sh
23+
```
24+
25+
You can also configure the application locally by setting the following environment variables:
26+
27+
| Name | Value |
28+
|------------------------|------------------------------------------------------------------------------------------------------------|
29+
| VITE_MAPTILER_API_KEY | Maptiler API key |
30+
| VITE_RESOURCE_BASE | Sets the path for all resource requests. |
31+
| VITE_MIMIC_GCP_LOCALLY | Boolean value that configures whether to show private layers locally if set to true and local files exist. |
32+
33+
## Running locally
34+
35+
### Build svelte app
36+
37+
1. Install dependencies:
38+
39+
```bash
40+
npm install
41+
```
42+
43+
1. Build web assets
44+
45+
```bash
46+
npm run setup-govuk
47+
```
48+
49+
1. Build the svelte app
50+
51+
```bash
52+
npm run build
53+
```
54+
55+
### Run express app
56+
57+
1. With the svelte app built move into the `backend` directory
58+
59+
```bash
60+
cd backend
61+
```
62+
63+
1. Copy over the build svelte app
64+
65+
```bash
66+
cp -r ../dist .
67+
```
68+
69+
1. Install backend dependencies
70+
71+
```bash
72+
npm install
73+
```
74+
75+
1. Authenticate with Google
76+
77+
```bash
78+
gcloud auth application-default login
79+
```
80+
81+
1. Run express app
82+
83+
```bash
84+
GCS_BUCKET=dft-rlg-atip-dev USE_IAP=false npm start
85+
```
86+
87+
1. Open http://localhost:8080
88+
89+
790
## Usage
891

992
The development version is available for use at <https://acteng.github.io/atip>. Note this is not a production service and we make no guarantees about the site's uptime or about backwards compatibility of sketch files.

backend/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ app.get("/data/*", async (req, resp) => {
5757
// Return the whole file?
5858
if (!req.headers.range) {
5959
let stream = storage.bucket(bucket).file(path).createReadStream();
60+
resp.setHeader("Content-Length", metadata.size)
6061
stream.pipe(resp);
6162
return;
6263
}

get-env.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Gets the local environment variables from Bitwarden
4+
5+
set -eo pipefail
6+
7+
cat <<EOF >.env
8+
VITE_MAPTILER_API_KEY=$(bw get password inspectorate-tools-maptiler-api-key-local)
9+
VITE_RESOURCE_BASE=/data
10+
VITE_MIMIC_GCP_LOCALLY=false
11+
EOF

0 commit comments

Comments
 (0)