mirror of
https://github.com/chubin/wttr.in
synced 2024-12-24 10:53:07 +00:00
Initial import of the salt state to deploy wttr.in
This commit is contained in:
parent
9a72e04ec7
commit
bc6e4a4f13
6 changed files with 204 additions and 0 deletions
11
share/salt/README.md
Normal file
11
share/salt/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Opinionated example of deployment via Salt Stack
|
||||
|
||||
## Assumptions:
|
||||
* user & group srv:srv exist, this is used as a generic service runner
|
||||
* you want to run the service on port 80, directly exposed to the interwebs (you really want to add a reverse SSL proxy in between)
|
||||
* You have, or are willing to deploy Salt Stack.
|
||||
* A bit of assembly is required since you need to move pillar.sls into your saltroot/pillar/ and the rest into saltroot/wttr/
|
||||
* You want metric-sm units. Just roll your own wegorc to change this
|
||||
|
||||
## Caveats:
|
||||
* Doesn't do enough to make a recent master checkout work, i.e. needs further improvement. Latest known working revision is 0d76ba4a3e112694665af6653040807835883b22
|
112
share/salt/init.sls
Normal file
112
share/salt/init.sls
Normal file
|
@ -0,0 +1,112 @@
|
|||
wttr:
|
||||
service.running:
|
||||
- enable: True
|
||||
- watch:
|
||||
- file: /srv/ephemeral/start.sh
|
||||
- git: wttr-repo
|
||||
- require:
|
||||
- pkg: wttr-dependencies
|
||||
- git: wttr-repo
|
||||
- cmd: wego
|
||||
- archive: geolite-db
|
||||
|
||||
# package names are from Ubuntu 18.04, you may need to adjust if on a different distribution
|
||||
wttr-dependencies:
|
||||
pkg.installed:
|
||||
- pkgs:
|
||||
- golang
|
||||
- gawk
|
||||
- python-setuptools
|
||||
- python-dev
|
||||
- python-dnspython
|
||||
- python-geoip2
|
||||
- python-geopy
|
||||
- python-gevent
|
||||
- python-flask
|
||||
- python-pil
|
||||
- authbind
|
||||
|
||||
wttr-repo:
|
||||
git.latest:
|
||||
- name: https://github.com/chubin/wttr.in
|
||||
- rev: master
|
||||
- target: /srv/ephemeral/wttr.in
|
||||
- require:
|
||||
- /srv/ephemeral
|
||||
|
||||
wttr-start:
|
||||
file.managed:
|
||||
- name: /srv/ephemeral/start.sh
|
||||
- source: salt://wttr/start.sh
|
||||
- mode: '0770'
|
||||
- user: srv
|
||||
- group: srv
|
||||
|
||||
wegorc:
|
||||
file.managed:
|
||||
- name: /srv/ephemeral/.wegorc
|
||||
- user: srv
|
||||
- group: srv
|
||||
- source: salt://wttr/wegorc
|
||||
- template: jinja
|
||||
- context:
|
||||
apikey: {{ pillar['wttr']['apikey'] }}
|
||||
|
||||
geolite-db:
|
||||
archive.extracted:
|
||||
- name: /srv/ephemeral
|
||||
- source: http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
|
||||
- source_hash: http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz.md5
|
||||
- keep_source: True
|
||||
- options: --strip-components=1 # flatten directory structure
|
||||
- enforce_toplevel: False
|
||||
|
||||
# Could benefit from improvement, won't get updated automatically at all
|
||||
wego:
|
||||
cmd.run:
|
||||
- onlyif: 'test ! -e /srv/ephemeral/bin/wego'
|
||||
- env:
|
||||
- GOPATH: /srv/ephemeral
|
||||
- name: go get -u github.com/schachmat/wego && go install github.com/schachmat/wego
|
||||
- cwd: /srv/ephemeral/
|
||||
- require:
|
||||
- pkg: wttr-dependencies
|
||||
- file: wegorc
|
||||
|
||||
/srv/ephemeral:
|
||||
file.directory:
|
||||
- makedirs: True
|
||||
|
||||
{% for dir in '/srv/ephemeral/wttr.in/log','/srv/ephemeral/wttr.in/cache' %}
|
||||
{{ dir }}:
|
||||
file.directory:
|
||||
- user: srv
|
||||
- group: srv
|
||||
- makedirs: True
|
||||
- recurse:
|
||||
- user
|
||||
- group
|
||||
- require_in:
|
||||
- service: wttr
|
||||
{% endfor %}
|
||||
|
||||
/etc/systemd/system/wttr.service:
|
||||
file:
|
||||
- managed
|
||||
- source: salt://wttr/wttr.service
|
||||
- require:
|
||||
- file: wttr-start
|
||||
- file: authbind-80
|
||||
- require_in:
|
||||
- service: wttr
|
||||
|
||||
authbind-80:
|
||||
file:
|
||||
- managed
|
||||
- name: /etc/authbind/byport/80
|
||||
- user: srv
|
||||
- group: srv
|
||||
- mode: 770
|
||||
- replace: False
|
||||
- require:
|
||||
- pkg: wttr-dependencies
|
2
share/salt/pillar.sls
Normal file
2
share/salt/pillar.sls
Normal file
|
@ -0,0 +1,2 @@
|
|||
wttr:
|
||||
apikey: insert-api-key-here-and-make-this-pillar-available-to-salt
|
12
share/salt/start.sh
Executable file
12
share/salt/start.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
export WEGORC="/srv/ephemeral/.wegorc"
|
||||
export GOPATH="/srv/ephemeral"
|
||||
|
||||
export WTTR_MYDIR="/srv/ephemeral/wttr.in"
|
||||
export WTTR_GEOLITE="/srv/ephemeral/GeoLite2-City.mmdb"
|
||||
export WTTR_WEGO="$GOPATH/bin/wego"
|
||||
|
||||
export WTTR_LISTEN_HOST="0.0.0.0"
|
||||
export WTTR_LISTEN_PORT="80"
|
||||
|
||||
python $WTTR_MYDIR/bin/srv.py
|
58
share/salt/wegorc
Normal file
58
share/salt/wegorc
Normal file
|
@ -0,0 +1,58 @@
|
|||
# wego configuration
|
||||
#
|
||||
# This config has https://github.com/schachmat/ingo syntax.
|
||||
# Empty lines or lines starting with # will be ignored.
|
||||
# All other lines must look like "KEY=VALUE" (without the quotes).
|
||||
# The VALUE must not be enclosed in quotes as well!
|
||||
|
||||
# aat-frontend: Show geo coordinates (default false)
|
||||
aat-coords=false
|
||||
|
||||
# aat-frontend: Monochrome output (default false)
|
||||
aat-monochrome=false
|
||||
|
||||
# BACKEND to be used (default forecast.io)
|
||||
backend=forecast.io
|
||||
|
||||
# NUMBER of days of weather forecast to be displayed (default 3)
|
||||
days=3
|
||||
|
||||
# forecast backend: the api KEY to use (default )
|
||||
forecast-api-key={{ apikey }}
|
||||
|
||||
# forecast backend: print raw requests and responses (default false)
|
||||
forecast-debug=false
|
||||
|
||||
# forecast backend: the LANGUAGE to request from forecast.io (default en)
|
||||
forecast-lang=en
|
||||
|
||||
# FRONTEND to be used (default ascii-art-table)
|
||||
frontend=ascii-art-table
|
||||
|
||||
# json frontend: do not indent the output (default false)
|
||||
jsn-no-indent=false
|
||||
|
||||
# LOCATION to be queried (default 40.748,-73.985)
|
||||
location=40.748,-73.985
|
||||
|
||||
# openweathermap backend: the api KEY to use (default )
|
||||
owm-api-key=
|
||||
|
||||
# openweathermap backend: print raw requests and responses (default false)
|
||||
owm-debug=false
|
||||
|
||||
# openweathermap backend: the LANGUAGE to request from openweathermap (default en)
|
||||
owm-lang=en
|
||||
|
||||
# UNITSYSTEM to use for output.
|
||||
# Choices are: metric, imperial, si, metric-ms (default metric)
|
||||
units=metric-ms
|
||||
|
||||
# worldweatheronline backend: the api KEY to use (default )
|
||||
wwo-api-key=
|
||||
|
||||
# worldweatheronline backend: print raw requests and responses (default false)
|
||||
wwo-debug=false
|
||||
|
||||
# worldweatheronline backend: the LANGUAGE to request from worldweatheronline (default en)
|
||||
wwo-lang=en
|
9
share/salt/wttr.service
Normal file
9
share/salt/wttr.service
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Wttr weather service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/authbind --deep /srv/ephemeral/start.sh
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue