Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the environment variables #46

Merged
merged 4 commits into from
Feb 4, 2024
Merged

Simplify the environment variables #46

merged 4 commits into from
Feb 4, 2024

Conversation

purple-emily
Copy link
Collaborator

Theres still a lot of duplicated variables, these need merging and clarifying.

@iPromKnight
Copy link
Collaborator

iPromKnight commented Feb 2, 2024

There is even more too 👅

For the consumer, after i converted to modules, I moved them all here as modules are instantiated once
https://github.com/Gabisonfire/torrentio-scraper-sh/blob/master/src/node/consumer/src/lib/config.js

For the producer, anything in the json files in the Configuration folders can be an env var.

For jackettio, they are here: https://github.com/Gabisonfire/torrentio-scraper-sh/blob/master/src/node/addon-jackett/src/lib/settings.js

Selfhostio doesn't have them like this yet - trival to produce though

@purple-emily
Copy link
Collaborator Author

@iPromKnight yeah, I am not well versed in JS so it’s a nightmare. I’m almost learning as I’m going lol. Feel free to pull the branch from my fork and push some changes and PR it 😂

I’m done for today. It’s sit on the sofa and watch crappy TV time

@purple-emily
Copy link
Collaborator Author

purple-emily commented Feb 3, 2024

@iPromKnight or @Gabisonfire

Can one of you offer me the way to change:

ScrapeConfiguration__StorageConnectionString=host=postgres;username=postgres;password=postgres;database=selfhostio;

so it will use the

# PostgreSQL
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=selfhostio

variables instead. Ideally I want to strip out all double coded values.

I can see in this file:

https://github.com/Gabisonfire/torrentio-scraper-sh/blob/57f4757541eceda82c553e2a7ca7e7063ffb7ee8/src/producer/Extensions/ServiceCollectionExtensions.cs

and then your comment @iPromKnight:
For the producer, anything in the json files in the Configuration folders can be an env var.

@purple-emily
Copy link
Collaborator Author

I'm going to add comments into the code, if we can make a habit of this going forward I'd be a lot happier.

I can see a few undocumented environment variables, like:

const NO_CACHE = process.env.NO_CACHE || false;

I'm curious what the consequences would be if we disabled the cache, is this a functionality we wish to keep or am I safe in assuming this could be removed.

Can I confirm @iPromKnight that you have no plans to drop a 32k commit completely rewriting the addon or consumer 😂😂😂😂😂😂

If you do please let me know 😋

@purple-emily
Copy link
Collaborator Author

I'm currently changing this to be 1:1 functionality with the old, just a simple rewrite.

    MONGO_URI: process.env.MONGODB_URI || 'mongodb://mongo:mongo@localhost:27017/selfhostio?authSource=admin',

becomes:

    MONGODB_HOST: process.env.MONGODB_HOST || 'mongodb',
    MONGODB_PORT: process.env.MONGODB_PORT || '27017',
    MONGODB_DB: process.env.MONGODB_DB || 'selfhostio',
    MONGO_INITDB_ROOT_USERNAME: process.env.MONGO_INITDB_ROOT_USERNAME || 'mongo',
    MONGO_INITDB_ROOT_PASSWORD: process.env.MONGO_INITDB_ROOT_PASSWORD || 'mongo',

I want to remove the defaults, and set a few variables as necessary. Some others can remain optional, and they all need documenting.

Error handling needs adding.

@purple-emily
Copy link
Collaborator Author

Pausing for a few hours. Haven't tested the latest push yet. It should work.

@iPromKnight
Copy link
Collaborator

@iPromKnight or @Gabisonfire

Can one of you offer me the way to change:


ScrapeConfiguration__StorageConnectionString=host=postgres;username=postgres;password=postgres;database=selfhostio;

so it will use the


# PostgreSQL

POSTGRES_HOST=postgres

POSTGRES_PORT=5432

POSTGRES_USER=postgres

POSTGRES_PASSWORD=postgres

POSTGRES_DB=selfhostio

variables instead. Ideally I want to strip out all double coded values.

I can see in this file:

https://github.com/Gabisonfire/torrentio-scraper-sh/blob/57f4757541eceda82c553e2a7ca7e7063ffb7ee8/src/producer/Extensions/ServiceCollectionExtensions.cs

and then your comment @iPromKnight:

For the producer, anything in the json files in the Configuration folders can be an env var.

Morning Emily
Sorry out this am for a few hours.

Yeah I will sort that out we'd have to introduce new properties for them in the Models/ScraperConfig file and turn the connection string into a computed property. I'll do later 😃

@iPromKnight
Copy link
Collaborator

I'm going to add comments into the code, if we can make a habit of this going forward I'd be a lot happier.

I can see a few undocumented environment variables, like:


const NO_CACHE = process.env.NO_CACHE || false;

I'm curious what the consequences would be if we disabled the cache, is this a functionality we wish to keep or am I safe in assuming this could be removed.

Can I confirm @iPromKnight that you have no plans to drop a 32k commit completely rewriting the addon or consumer 😂😂😂😂😂😂

If you do please let me know 😋

Haha no nothing like that. I'm going to try to see how they run under bun as opposed to nodejs when I get home as it's really gaining traction now

@iPromKnight
Copy link
Collaborator

@iPromKnight yeah, I am not well versed in JS so it’s a nightmare. I’m almost learning as I’m going lol. Feel free to pull the branch from my fork and push some changes and PR it 😂

I’m done for today. It’s sit on the sofa and watch crappy TV time

Me neither really. Not used it in years but it's all been coming back this week lol. I much prefer strongly typed typescript.

I've been a .net dev for 23 years though lol

@purple-emily
Copy link
Collaborator Author

@iPromKnight or @Gabisonfire
Can one of you offer me the way to change:


ScrapeConfiguration__StorageConnectionString=host=postgres;username=postgres;password=postgres;database=selfhostio;

so it will use the


# PostgreSQL

POSTGRES_HOST=postgres

POSTGRES_PORT=5432

POSTGRES_USER=postgres

POSTGRES_PASSWORD=postgres

POSTGRES_DB=selfhostio

variables instead. Ideally I want to strip out all double coded values.
I can see in this file:
https://github.com/Gabisonfire/torrentio-scraper-sh/blob/57f4757541eceda82c553e2a7ca7e7063ffb7ee8/src/producer/Extensions/ServiceCollectionExtensions.cs
and then your comment @iPromKnight:
For the producer, anything in the json files in the Configuration folders can be an env var.

Morning Emily Sorry out this am for a few hours.

Yeah I will sort that out we'd have to introduce new properties for them in the Models/ScraperConfig file and turn the connection string into a computed property. I'll do later 😃

Great! You think it’s worth doing the same with RabbitMQ as well? The service you proposed in #45 will need access to Rabbit as well right? Tidy the Rabbit vars up so it’s easier to switch to an unattached service if the user already has one.

I think Mongo and Postgres are done. Just needs testing to make sure nothing is broken.

I am trying to back edit some of the changes you made into the consumer into the add on.

How much of the code from addon/consumer is reused? Could these two be merged into one folder with a different entrypoint.sh/command.

From my quick perusal a lot of the code is duplicated anyway so all we are doing is doubling the maintenance cost.

@purple-emily
Copy link
Collaborator Author

I'm going to add comments into the code, if we can make a habit of this going forward I'd be a lot happier.
I can see a few undocumented environment variables, like:


const NO_CACHE = process.env.NO_CACHE || false;

I'm curious what the consequences would be if we disabled the cache, is this a functionality we wish to keep or am I safe in assuming this could be removed.
Can I confirm @iPromKnight that you have no plans to drop a 32k commit completely rewriting the addon or consumer 😂😂😂😂😂😂
If you do please let me know 😋

Haha no nothing like that. I'm going to try to see how they run under bun as opposed to nodejs when I get home as it's really gaining traction now

I’ll nod along and trust your judgement. The only bun I’m thinking of is 🧁

@purple-emily
Copy link
Collaborator Author

@iPromKnight

Is this a bug? Addon cache is hard coded as: selfhostio_addon_collection

Consumer cache is using cacheConfig.COLLECTION_NAME which is selfhostio_consumer_collection

Should these be the same value?

@iPromKnight
Copy link
Collaborator

I'm going to add comments into the code, if we can make a habit of this going forward I'd be a lot happier.
I can see a few undocumented environment variables, like:


const NO_CACHE = process.env.NO_CACHE || false;

I'm curious what the consequences would be if we disabled the cache, is this a functionality we wish to keep or am I safe in assuming this could be removed.
Can I confirm @iPromKnight that you have no plans to drop a 32k commit completely rewriting the addon or consumer 😂😂😂😂😂😂
If you do please let me know 😋

Haha no nothing like that. I'm going to try to see how they run under bun as opposed to nodejs when I get home as it's really gaining traction now

I’ll nod along and trust your judgement. The only bun I’m thinking of is 🧁

Haha 👅

Unfortunately Bun is a no go..
For now at least
3 Hours of fixes getting the database to connect only for it to fail on ingestion as bun doesn't currently implement dgram, so the torrent info extracted doesn't work (no UDP support)
Hey-ho - one day ^^. They have it on the backlog

@iPromKnight

Is this a bug? Addon cache is hard coded as: selfhostio_addon_collection

Consumer cache is using cacheConfig.COLLECTION_NAME which is selfhostio_consumer_collection

Should these be the same value?

No no - the consumer one is just for imdbIds - once its found one for a series etc, it keeps it cached for 7 days so that if it finds another episode or another file in the torrent it needs to look up, it can get the id without having to go off and use name-to-imdb, which is rate limited, or the fall-back google search

Should probably be an env var on the addon though - and not hard coded 😄
I'm actually about to push a PR that updates cache-manager to the latest version, and I definitely agree with the reuse issue

I think for lib - it kinda makes sense to create a shared project, and bring it into both the consumer and addon, get rid of all this duplication.

@purple-emily
Copy link
Collaborator Author

Agree with the shared library idea.

addon and consumer.

Todo: producer

Change DATABASE_URI to be generic POSTGRES variables

DOES NOT WORK - First pass at upgrading environment variables

PostgreSQL environment variables have been split for addon and consumer. ENABLE_SYNC hard coded as `true`

MongoDB variables update.

Make the addon code more similar to the consumer code

Get some parity between addon and consumer
@purple-emily purple-emily marked this pull request as ready for review February 4, 2024 08:35
@purple-emily
Copy link
Collaborator Author

purple-emily commented Feb 4, 2024

Just the producer left to tidy up @iPromKnight to get everything on the same level.

The library idea can be done in another request.

Can merge this as is and create a new pr for producer parity, or do it in this PR

@iPromKnight
Copy link
Collaborator

I'll pull down in a few and sort it out cheers Emily

.env Outdated Show resolved Hide resolved
Copy link
Collaborator

@iPromKnight iPromKnight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@iPromKnight iPromKnight merged commit 875d79b into knightcrawler-stremio:master Feb 4, 2024
@purple-emily purple-emily deleted the change-to-single-env-file branch February 4, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants