Skip to content

Commit d73d43d

Browse files
authored
Build the map locally (#55)
* poc * deploy * oops * oops * oops * clean * safe * fix * clean
1 parent 34188bc commit d73d43d

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

.github/workflows/deploy.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,3 @@ jobs:
2727
secrets: inherit
2828
needs: deploy_to_dev3
2929
if: github.ref == 'refs/heads/main'
30-
31-
deploy_to_prod2:
32-
name: Deploy to prod 2
33-
uses: ./.github/workflows/helm_deploy.yaml
34-
with:
35-
environment: prod2
36-
secrets: inherit
37-
needs: deploy_to_dev3
38-
if: github.ref == 'refs/heads/main'

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
data/
1+
data/
2+
all.yaml

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
helm:
3+
helm template ./website-map/ --set app_namespace=test --set fqdn=map.nycmesh.net --set github_client_id=x --set github_install_id=x --set github_secret=x > all.yaml

website-map/templates/backend.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,19 @@ spec:
9090
secretKeyRef:
9191
name: website-map-secrets
9292
key: github-install-id
93+
- name: BUILD_MAP
94+
value: "true"
9395
volumeMounts:
9496
- name: content-vol
9597
mountPath: /content
9698
- name: map-entrypoint
9799
mountPath: /map.entrypoint.sh
98100
subPath: map.entrypoint.sh
99101
readOnly: true
102+
- name: map-build-zip
103+
mountPath: /map.build.zip.sh
104+
subPath: map.build.zip.sh
105+
readOnly: true
100106
- name: get-content
101107
mountPath: /get_content.py
102108
subPath: get_content.py
@@ -131,6 +137,12 @@ spec:
131137
items:
132138
- key: map.update.sh
133139
path: map.update.sh
140+
- name: map-build-zip
141+
configMap:
142+
name: scripts
143+
items:
144+
- key: map.build.zip.sh
145+
path: map.build.zip.sh
134146
- name: get-content
135147
configMap:
136148
name: get-content

website-map/templates/scripts.yaml

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,59 @@ data:
77
map.entrypoint.sh: |
88
echo "Startup"
99
pip install requests PyJWT cryptography
10-
apk add bash
10+
apk add bash git nodejs npm curl zip jq
11+
echo "Installing hugo"
12+
HUGO_VERSION="0.69.2"
13+
curl -sLo "/tmp/hugo.tgz" "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz"
14+
tar -xzf /tmp/hugo.tgz
15+
chmod a+x /hugo
16+
mv /hugo /usr/bin/hugo
17+
echo "Installing dart-saas"
18+
npm install -g sass
19+
echo "First manual run of update map"
20+
bash /map.update.sh
1121
echo "*/10 * * * * /bin/bash /map.update.sh" >> /etc/crontabs/root
1222
echo "Starting cron"
1323
crond -f -L /proc/1/fd/1 -l 4
1424
echo "Error: Cron exited"
25+
map.build.zip.sh: |
26+
if [ -d /workspace ]; then
27+
rm -rf /workspace
28+
fi
29+
git clone --recursive https://github.com/nycmeshnet/nycmesh.net /workspace
30+
cd /workspace
31+
export STANDALONE_MAP_BUILD="true"
32+
export NODE_OPTIONS='--openssl-legacy-provider'
33+
sh update-map.sh
34+
export HUGO_ENVIRONMENT="production"
35+
export HUGO_CACHEDIR="/tmp/hugo_cache"
36+
hugo --minify --baseURL "https://nycmesh.net/"
37+
echo "Build Map Payload"
38+
mkdir -p public/map/img/
39+
mv public/img/map/ public/map/img/map/
40+
mv public/favicon.ico public/map/favicon.ico
41+
mv public/404.html public/map/
42+
echo "Make zip"
43+
if [ -f "/content/new_content.zip" ]; then
44+
rm /content/new_content.zip
45+
fi
46+
cd public/map
47+
if [ -f "./index.html" ]; then
48+
zip -r /content/new_content.zip .
49+
fi
50+
cd /
51+
rm -rf /workspace
1552
map.update.sh: |
1653
#!/bin/bash
1754
echo "Updating content"
18-
python3 /get_content.py
55+
if [ ! -z "$BUILD_MAP" ]; then
56+
echo "building map"
57+
bash /map.build.zip.sh
58+
else
59+
echo "downloading map"
60+
python3 /get_content.py
61+
fi
62+
content_zip="/content/new_content.zip"
1963
echo "Update counter"
2064
content_dir="/content/current"
2165
counter_file="/content/counter"
@@ -26,14 +70,16 @@ data:
2670
((counter++))
2771
echo "$counter" > "$counter_file"
2872
echo "Counter is $counter"
29-
if [ "$counter" -gt "500" ]; then
73+
if [ "$counter" -gt "500" ] && [ -f "$content_zip" ]; then
3074
echo "Reset counter"
3175
rm -f $counter_file
3276
rm -rf $content_dir
3377
fi
34-
echo "Unpacking content"
35-
content_zip="/content/new_content.zip"
36-
unzip -o $content_zip -d $content_dir
37-
echo "Cleanup"
38-
rm -f $content_zip
39-
# Cleanup downloaded content
78+
if [ -f "$content_zip" ]; then
79+
echo "Unpacking content"
80+
unzip -o $content_zip -d $content_dir
81+
echo "Cleanup"
82+
rm -f $content_zip
83+
else
84+
echo "content zip not found"
85+
fi

0 commit comments

Comments
 (0)