Skip to content

Commit d3aaf4a

Browse files
author
Rub21
committed
Add script to overwrite config in taginfo
1 parent 586df00 commit d3aaf4a

File tree

6 files changed

+58
-24
lines changed

6 files changed

+58
-24
lines changed

.env-taginfo.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ INSTANCE_DESCRIPTION="This is a <b>taginfo test instance</b>. Change this text i
99
INSTANCE_ICON=/img/logo/world.png
1010
INSTANCE_CONTACT=Anonymous
1111
TAGINFO_PROJECT_REPO=https://github.com/taginfo/taginfo-projects.git
12-
DOWNLOAD_DB=languages wiki
13-
CREATE_DB=db projects chronology
12+
DOWNLOAD_DB='languages wiki'
13+
CREATE_DB='db projects chronology'

images/taginfo/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ RUN apt-get update && apt-get -y install \
1010
libapache2-mod-passenger \
1111
git
1212

13+
# Commit ae5a950f7aa4c0de4e706839619a1dc05fc4450a, at 2021-10-18
1314
RUN git clone https://github.com/taginfo/taginfo.git $workdir/taginfo
1415
WORKDIR $workdir/taginfo
1516
RUN echo "gem 'thin' " >>Gemfile
@@ -46,6 +47,8 @@ RUN git submodule update --init
4647
RUN mkdir build && cd build && cmake .. && make
4748

4849
RUN apt-get install -y nano vim
50+
COPY overwrite_config.py $workdir/
4951
COPY start.sh $workdir/
52+
5053
WORKDIR $workdir/
5154
CMD $workdir/start.sh

images/taginfo/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ All environment variables are located at [`.env-taginfo.example`](https://github
1616

1717
The following env vars are required in the instance to update the values at: https://github.com/taginfo/taginfo/blob/master/taginfo-config-example.json
1818

19-
- `INSTANCE_URL`: URL prefix for the site.
20-
- `INSTANCE_NAME`: Used in the title of all HTML pages.
21-
- `INSTANCE_DESCRIPTION` : Description of this taginfo instance. Will appear on the home page and about page.
22-
- `INSTANCE_ICON`: URL path to instance icon in the upper left.
23-
- `INSTANCE_CONTACT`: Contact name and email address.
24-
- `TAGINFO_PROJECT_REPO` : If you're implementing your own instances of taginfo with you own data, you need to look into the projects, clone the [taginfo-project ](https://github.com/taginfo/taginfo-projects) repo, and pass it in this env var.
19+
- `OVERWRITE_CONFIG_URL`: config file with the values to update
2520

2621
- `DOWNLOAD_DB`: Taginfo instances need 7 Sqlite databases to start up the web service, all of them can be downloaded from https://taginfo.openstreetmap.org/download. Or if you can download only some of them you can pass herec. e.g DOWNLOAD_DB=`languages wiki`, or DOWNLOAD_DB=`languages wiki projects chronology`.
2722

images/taginfo/overwrite_config.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
""" Script to overwrite values in set config
2+
python3 overwrite_config.py \
3+
-u https://gist.githubusercontent.com/Rub21/1a82fb3e4c0efd15524709a5e2d8ab89/raw/23c399802ba2a01cc30379875ac02a7b1b5ac8e1/taginfo.json\
4+
-f taginfo-config.json
5+
"""
6+
7+
import argparse
8+
import urllib.request
9+
import json
10+
11+
def main(config_file, overwrite_config_url):
12+
with urllib.request.urlopen(overwrite_config_url) as url:
13+
overwrite_values = json.loads(url.read())
14+
with open(config_file) as f:
15+
current_values = json.loads(f.read())
16+
# Hardcode for certain values
17+
if 'instance' in overwrite_values.keys():
18+
current_values['instance'] = overwrite_values['instance']
19+
if 'turbo' in overwrite_values.keys():
20+
current_values['turbo'] = overwrite_values['turbo']
21+
if 'sources' in overwrite_values.keys() and 'master' in overwrite_values['sources'].keys():
22+
current_values['sources']['master'] = overwrite_values['sources']['master']
23+
# Overwrite file
24+
with open(config_file + '.json', 'w') as f:
25+
f.write(json.dumps(current_values))
26+
27+
28+
parser = argparse.ArgumentParser(description='Set config values')
29+
parser.add_argument(
30+
'-u',
31+
type=str,
32+
help='URL of the config to overwrite',
33+
dest='overwrite_config_url')
34+
35+
parser.add_argument(
36+
'-f'
37+
'--config_file',
38+
type=str,
39+
help='Path of the config file',
40+
dest='config_file')
41+
42+
args = parser.parse_args()
43+
44+
if args.config_file and args.overwrite_config_url:
45+
main(args.config_file, args.overwrite_config_url)

images/taginfo/start.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ set_taginfo_config() {
1717
jq '.sources.db.bindir = "'$UPDATE_DIR'/build/src"' |
1818
jq '.paths.data_dir = "'$DATA_DIR'"' \
1919
>$WORKDIR/taginfo-config.json
20-
# Update instance values in taginfo-config.json
21-
[[ ! -z ${INSTANCE_URL+z} ]] && jq --arg a "${INSTANCE_URL}" '.instance.url = $a' $WORKDIR/taginfo-config.json >tmp.json && mv tmp.json $WORKDIR/taginfo-config.json
22-
[[ ! -z $INSTANCE_NAME+z} ]] && jq --arg a "${INSTANCE_NAME}" '.instance.name = $a' $WORKDIR/taginfo-config.json >tmp.json && mv tmp.json $WORKDIR/taginfo-config.json
23-
[[ ! -z $INSTANCE_DESCRIPTION+z} ]] && jq --arg a "${INSTANCE_DESCRIPTION}" '.instance.description = $a' $WORKDIR/taginfo-config.json >tmp.json && mv tmp.json $WORKDIR/taginfo-config.json
24-
[[ ! -z $INSTANCE_ICON+z} ]] && jq --arg a "${INSTANCE_ICON}" '.instance.icon = $a' $WORKDIR/taginfo-config.json >tmp.json && mv tmp.json $WORKDIR/taginfo-config.json
25-
[[ ! -z $INSTANCE_CONTACT+z} ]] && jq --arg a "${INSTANCE_CONTACT}" '.instance.contact = $a' $WORKDIR/taginfo-config.json >tmp.json && mv tmp.json $WORKDIR/taginfo-config.json
20+
2621
# languages wiki databases will be downloaded from OSM
2722
[[ ! -z $DOWNLOAD_DB+z} ]] && jq --arg a "${DOWNLOAD_DB}" '.sources.download = $a' $WORKDIR/taginfo-config.json >tmp.json && mv tmp.json $WORKDIR/taginfo-config.json
23+
24+
# Update instance values in taginfo-config.json
25+
python3 overwrite_config.py -u $OVERWRITE_CONFIG_URL -f $WORKDIR/taginfo-config.json
26+
2827
}
2928

3029
updates_create_db() {

osm-seed/templates/taginfo-deployment.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,8 @@ spec:
5353
value: {{ .Values.taginfo.env.URL_HISTORY_PLANET_FILE_STATE }}
5454
- name: URL_HISTORY_PLANET_FILE
5555
value: {{ .Values.taginfo.env.URL_HISTORY_PLANET_FILE }}
56-
- name: INSTANCE_URL
57-
value: dns
58-
- name: INSTANCE_NAME
59-
value: {{ .Values.taginfo.env.INSTANCE_NAME }}
60-
- name: INSTANCE_DESCRIPTION
61-
value: {{ .Values.taginfo.env.INSTANCE_DESCRIPTION }}
62-
- name: INSTANCE_ICON
63-
value: {{ .Values.taginfo.env.INSTANCE_ICON }}
64-
- name: INSTANCE_CONTACT
65-
value: {{ .Values.taginfo.env.INSTANCE_CONTACT }}
56+
- name: OVERWRITE_CONFIG_URL
57+
value: {{ .Values.taginfo.env.OVERWRITE_CONFIG_URL }}
6658
- name: TAGINFO_PROJECT_REPO
6759
value: {{ .Values.taginfo.env.TAGINFO_PROJECT_REPO }}
6860
- name: DOWNLOAD_DB

0 commit comments

Comments
 (0)