Skip to content

Commit

Permalink
chore: add seed script
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmaynes committed Jan 9, 2024
1 parent 74f725d commit 7656c08
Show file tree
Hide file tree
Showing 16 changed files with 3,927 additions and 17 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -42,10 +42,15 @@ deploy_cloudflare_page:

deploy: install build ensure_cloudflare_infra_exists deploy_cloudflare_page

seed:
node ./script/seed.js \
--cloudflare-kv-binding-id "5df82e748f494385a2aeaf2912cbb359" \
--seed-file "./data/seed.json"

clean:
rm -rf .next/ .vercel/ build/

define add_cloudflare_secret
chmod +x ./script/cloudflare/ensure-cloudflare-secret-exists.sh
./script/cloudflare/ensure-cloudflare-secret-exists.sh "$(1)" "$(2)" "$(3)"
endef
endef
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -26,4 +26,9 @@ make test
To deploy the application, run the following command:
```bash
make deploy
```

To seed the database, run the following command:
```bash
make seed
```
2,646 changes: 2,646 additions & 0 deletions data/seed.json

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -20,7 +20,6 @@
"@tensorflow-models/mobilenet": "^2.1.1",
"@tensorflow/tfjs": "^4.13.0",
"next": "^14.0.3",
"openai": "^4.19.1",
"react": "^18",
"react-dom": "^18"
},
Expand All @@ -37,6 +36,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-next-on-pages": "^1.8.2",
"eslint-plugin-prettier": "^5.0.1",
"openai": "^4.24.1",
"prettier": "^3.1.1",
"sass": "^1.69.6",
"sharp": "^0.32.6",
Expand Down
40 changes: 40 additions & 0 deletions script/cloudflare/add-cloudflare-kv-value.sh
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e

CLOUDFLARE_KV_BINDING_ID=$1
CLOUDFLARE_KV_KEY=$2
CLOUDFLARE_KV_VALUE=$3

function check_requirements() {
if [[ -z "$(command -v node)" ]]; then
echo "Please install 'node' program before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_ACCOUNT_ID" ]]; then
echo "Please ensure environment variable 'CLOUDFLARE_ACCOUNT_ID' exists before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_API_TOKEN" ]]; then
echo "Please ensure environment variable 'CLOUDFLARE_API_TOKEN' exists before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_KV_BINDING_ID" ]]; then
echo "Arg 1 for script 'CLOUDFLARE_KV_BINDING_ID' was not given..."
exit 1
elif [[ -z "$CLOUDFLARE_KV_KEY" ]]; then
echo "Arg 2 for script 'CLOUDFLARE_KV_KEY' was not given..."
exit 1
elif [[ -z "$CLOUDFLARE_KV_VALUE" ]]; then
echo "Arg 3 for script 'CLOUDFLARE_KV_VALUE' was not given..."
exit 1
fi
}

function main() {
check_requirements

if ! ./node_modules/.bin/wrangler kv:key get "$CLOUDFLARE_KV_KEY" --namespace-id="$CLOUDFLARE_KV_BINDING_ID" > /dev/null 2>&1; then
echo "Adding Cloudflare KV key '$CLOUDFLARE_KV_KEY' and value '$CLOUDFLARE_KV_VALUE' to KV '$CLOUDFLARE_KV_NAME'..."
./node_modules/.bin/wrangler kv:key put "$CLOUDFLARE_KV_KEY" "$CLOUDFLARE_KV_VALUE" --namespace-id="$CLOUDFLARE_KV_BINDING_ID"
fi
}

main
2 changes: 1 addition & 1 deletion script/cloudflare/cloudflare-page-deploy.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion script/cloudflare/ensure-cloudflare-kv-exists.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion script/cloudflare/ensure-cloudflare-pages-exists.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion script/cloudflare/ensure-cloudflare-secret-exists.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down

0 comments on commit 7656c08

Please sign in to comment.