-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.py
More file actions
83 lines (71 loc) · 3.29 KB
/
release.py
File metadata and controls
83 lines (71 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# MIT License
#
# Copyright (c) 2022 Daniel C. Brotsky
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
import os
import sqlalchemy as sa
import alembic.config
from sqlalchemy.future import Connection
import stv_services.airtable.bulk as at_bulk
from stv_services.core import Configuration
from stv_services.core.logging import logging, init_logging
from stv_services.data_store import Postgres, model
def run_release_process():
# initialize the database
alembic_args = ["--raiseerr", "upgrade", "head"]
alembic.config.main(argv=alembic_args)
# reset logging now that alembic is done
init_logging()
# exit if no configuration data is loaded
config = Configuration.get_global_config()
if not config.get("airtable_stv_base_name"):
logging.error(
"No configuration data: "
"Execute the stv.py command `load-config`"
)
return
# make sure our endpoint matches our configuration
url: str = config.get("stv_api_base_url", "")
env = Configuration.get_env()
print(f"Environment is '{env}'")
if not url or url.find("stv-services") < 0:
assert env == "DEV", "DEV webserver but not in DEV"
assert not os.getenv("DATABASE_URL"), "DEV builds must use the local database"
elif url.find("stv-services-") >= 0:
assert env == "STG", "STG webserver but not in STG"
assert os.getenv("DATABASE_URL"), "STG builds require a DATABASE_URL"
assert os.getenv("REDIS_URL"), "STG builds require a REDIS_URL"
else:
assert env == "PRD", "PRD webserver but not in PRD"
assert os.getenv("DATABASE_URL"), "PRD builds require a DATABASE_URL"
assert os.getenv("REDIS_URL"), "PRD builds require a REDIS_URL"
# make sure the Airtable schema validates
at_bulk.verify_schemas(verbose=True)
# final check on configuration
with Postgres.get_global_engine().connect() as conn: # type: Connection
rows = conn.execute(sa.select(model.external_info)).first()
if not rows:
logging.error("There is no external spreadsheet data loaded!!")
logging.error("Execute the stv.py command `import-from-local`")
else:
logging.info("Local data has been loaded: ready to run services")
if __name__ == "__main__":
run_release_process()