-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* big reorg * docker builds db and alembic * alembic and db docker actually builds now also, migrations run * reloaded the crates stuff, and fixed imports * crates image is building and running * crates works * wait on homebrew * monitor service is building * env vars for crates * monitor service is running * delete some old stuff * the scheduler class * remove old scheduler * crates working with docker compose * jq formulae for homebrew * fix packages script * start of orchestrator for homebrew...that works! * jq transforms * volume mapping, docker compose * fix crates import * lint on db.py * config for crates * Dockerfile? * docker compose yml todo * we've got csvs! * everything but load * cleanup * inserting packages works! * all homebrew except dependencies * correctly create homebrew package manager row * yep, much faster * crates fix to create source and package manager * remove sed * config changes to load dependency types * create the data types upfront * get homebrew env vars * remove python * replace sed with jq * jq corrections, pipeline.sh fixes, dockerfile * pipeline.sh improvements * some cleanups --------- Co-authored-by: Jacob Heider <[email protected]>
- Loading branch information
1 parent
189e43c
commit cffd6fb
Showing
37 changed files
with
692 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# directories | ||
data/ | ||
db/ | ||
.venv/ | ||
|
||
# other files | ||
.gitignore | ||
docker-compose.yml | ||
docker-compose.yml | ||
.DS_Store | ||
.git | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- url types | ||
INSERT INTO "url_types" ("name") | ||
VALUES ('source'), ('homepage'), ('documentation'), ('repository') | ||
ON CONFLICT (name) DO NOTHING; | ||
|
||
-- dependency types | ||
INSERT INTO "depends_on_types" ("name") | ||
VALUES | ||
('build'), | ||
('development'), | ||
('runtime'), | ||
('test'), | ||
('optional'), | ||
('recommended'), | ||
('uses_from_macos') | ||
ON CONFLICT (name) DO NOTHING; | ||
|
||
-- sources | ||
INSERT INTO "sources" ("type") | ||
VALUES ('crates'), ('npm'), ('pypi'), ('rubygems'), ('github'), ('homebrew') | ||
ON CONFLICT (type) DO NOTHING; | ||
|
||
INSERT INTO "package_managers" ("source_id") | ||
SELECT id | ||
FROM "sources" | ||
WHERE "type" IN ('crates', 'npm', 'pypi', 'rubygems', 'github', 'homebrew'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ else | |
echo "migrations failed" | ||
exit 1 | ||
fi | ||
|
||
# load values | ||
psql -U postgres -h db -d chai -f load-values.sql -a |
29 changes: 29 additions & 0 deletions
29
alembic/versions/20241021_0803-package_managers_should_be_unique.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""package managers should be unique | ||
Revision ID: 38cc41599874 | ||
Revises: 2481138a729a | ||
Create Date: 2024-10-21 08:03:43.647535 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "38cc41599874" | ||
down_revision: Union[str, None] = "2481138a729a" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_unique_constraint( | ||
op.f("uq_package_managers_source_id"), "package_managers", ["source_id"] | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_constraint( | ||
op.f("uq_package_managers_source_id"), "package_managers", type_="unique" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
from dataclasses import dataclass | ||
from os import getenv | ||
|
||
from core.db import DB | ||
from core.logger import Logger | ||
from core.structs import ( | ||
DependencyTypes, | ||
PackageManager, | ||
PackageManagerIDs, | ||
Sources, | ||
URLTypes, | ||
UserTypes, | ||
) | ||
|
||
logger = Logger("config") | ||
|
||
TEST = getenv("TEST", "false").lower() == "true" | ||
FETCH = getenv("FETCH", "true").lower() == "true" | ||
|
||
|
||
@dataclass | ||
class Config: | ||
file_location: str | ||
test: bool | ||
fetch: bool | ||
package_manager_id: str | ||
url_types: URLTypes | ||
user_types: UserTypes | ||
dependency_types: DependencyTypes | ||
|
||
def __str__(self): | ||
return f"Config(file_location={self.file_location}, test={self.test}, \ | ||
fetch={self.fetch}, package_manager_id={self.package_manager_id}, \ | ||
url_types={self.url_types}, user_types={self.user_types}, \ | ||
dependency_types={self.dependency_types})" | ||
|
||
|
||
def load_url_types(db: DB) -> URLTypes: | ||
logger.debug("loading url types, and creating if not exists") | ||
homepage_url = db.select_url_types_homepage(create=True) | ||
repository_url = db.select_url_types_repository(create=True) | ||
documentation_url = db.select_url_types_documentation(create=True) | ||
source_url = db.select_url_types_source(create=True) | ||
return URLTypes( | ||
homepage=homepage_url.id, | ||
repository=repository_url.id, | ||
documentation=documentation_url.id, | ||
source=source_url.id, | ||
) | ||
|
||
|
||
def load_user_types(db: DB) -> UserTypes: | ||
logger.debug("loading user types, and creating if not exists") | ||
crates_source = db.select_source_by_name("crates", create=True) | ||
github_source = db.select_source_by_name("github", create=True) | ||
return UserTypes( | ||
crates=crates_source.id, | ||
github=github_source.id, | ||
) | ||
|
||
|
||
def load_package_manager_ids(db: DB) -> PackageManagerIDs: | ||
logger.debug("loading package manager ids, and creating if not exists") | ||
crates_package_manager = db.select_package_manager_by_name("crates", create=True) | ||
homebrew_package_manager = db.select_package_manager_by_name( | ||
"homebrew", create=True | ||
) | ||
return { | ||
PackageManager.CRATES: crates_package_manager.id, | ||
PackageManager.HOMEBREW: homebrew_package_manager.id, | ||
} | ||
|
||
|
||
def load_dependency_types(db: DB) -> DependencyTypes: | ||
logger.debug("loading dependency types, and creating if not exists") | ||
build_dep_type = db.select_dependency_type_by_name("build", create=True) | ||
dev_dep_type = db.select_dependency_type_by_name("development", create=True) | ||
runtime_dep_type = db.select_dependency_type_by_name("runtime", create=True) | ||
test_dep_type = db.select_dependency_type_by_name("test", create=True) | ||
optional_dep_type = db.select_dependency_type_by_name("optional", create=True) | ||
recommended_dep_type = db.select_dependency_type_by_name("recommended", create=True) | ||
return DependencyTypes( | ||
build=build_dep_type.id, | ||
development=dev_dep_type.id, | ||
runtime=runtime_dep_type.id, | ||
test=test_dep_type.id, | ||
optional=optional_dep_type.id, | ||
recommended=recommended_dep_type.id, | ||
) | ||
|
||
|
||
def load_sources() -> Sources: | ||
return { | ||
PackageManager.CRATES: "https://static.crates.io/db-dump.tar.gz", | ||
PackageManager.HOMEBREW: ( | ||
"https://github.com/Homebrew/homebrew-core/tree/master/Formula" | ||
), | ||
} | ||
|
||
|
||
def initialize(package_manager: PackageManager, db: DB) -> Config: | ||
url_types = load_url_types(db) | ||
user_types = load_user_types(db) | ||
package_manager_ids = load_package_manager_ids(db) | ||
dependency_types = load_dependency_types(db) | ||
sources = load_sources() | ||
|
||
if package_manager == PackageManager.CRATES: | ||
return Config( | ||
file_location=sources[PackageManager.CRATES], | ||
test=False, | ||
fetch=True, | ||
package_manager_id=package_manager_ids[PackageManager.CRATES], | ||
url_types=url_types, | ||
user_types=user_types, | ||
dependency_types=dependency_types, | ||
) | ||
elif package_manager == PackageManager.HOMEBREW: | ||
return Config( | ||
file_location=sources[PackageManager.HOMEBREW], | ||
test=False, | ||
fetch=True, | ||
package_manager_id=package_manager_ids[PackageManager.HOMEBREW], | ||
url_types=url_types, | ||
user_types=user_types, | ||
dependency_types=dependency_types, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.