Microsoft-Rewards-Farmer icon indicating copy to clipboard operation
Microsoft-Rewards-Farmer copied to clipboard

Docker implementation

Open belgio99 opened this issue 1 year ago • 6 comments

Wrote a plain and simple first Docker implementation, built with GitHub Actions, to resolve #240.

The image is live on Docker Hub for linux/amd64 and linux/arm64 at supercar99/ms-rewards.

To use, you'll have to mount your accounts.json at /app/accounts.json using Docker volumes (-v)

Currently it supports two environmental variables:

  • RUN_ONCE: if set to true, runs the script once and then quits
  • CRON_SCHEDULE: you can supply a valid cron schedule, or by default it will just run daily at 4 AM.

TODO:

  • [x] Add versioning to the image based on the project version (now it's always pushing as latest)
  • [ ] Pass command line options to the script
  • [x] 2FA Support
  • [ ] ??? (Suggestions are very much welcomed!)

belgio99 avatar Jan 25 '24 17:01 belgio99

Thanks for making this. 2FA is a problem. When running locally it waits for the user to press ENTER once they've approved the number printed in the output in their 2FA app. When trying this in the docker container it bugs out (container exits). Here's a log:

[ERROR] [LOGIN] 2FA required !
[ERROR] [LOGIN] 2FA code: **
[INFO] [LOGIN] Press enter when confirmed...
[ERROR] EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/app/src/login.py", line 59, in executeLogin
    self.enterPassword(self.browser.password)
  File "/app/src/login.py", line 83, in enterPassword
    self.utils.waitUntilClickable(By.NAME, "passwd", 10)
  File "/app/src/utils.py", line 30, in waitUntilClickable
    WebDriverWait(self.webdriver, timeToWait).until(
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/support/wait.py", line 105, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
#0 0x556057017de3 <unknown>
#1 0x556056d0b6b7 <unknown>
#2 0x556056d4f999 <unknown>
#3 0x556056d4fac1 <unknown>
#4 0x556056d91ef4 <unknown>
#5 0x556056d7294d <unknown>
#6 0x556056d8fdb0 <unknown>
#7 0x556056d726a3 <unknown>
#8 0x556056d43ebd <unknown>
#9 0x556056d44c72 <unknown>
#10 0x556056fec3d6 <unknown>
#11 0x556056fef6b9 <unknown>
#12 0x556056fef18f <unknown>
#13 0x556056fefb35 <unknown>
#14 0x556056fde58f <unknown>
#15 0x556056fefebe <unknown>
#16 0x556056fc81d6 <unknown>
#17 0x556057008bc5 <unknown>
#18 0x556057008dab <unknown>
#19 0x55605701736f <unknown>
#20 0x1552578a8044 <unknown>


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/main.py", line 24, in main
    executeBot(currentAccount, notifier, args)
  File "/app/main.py", line 128, in executeBot
    accountPointsCounter = Login(desktopBrowser).login()
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/src/login.py", line 37, in login

I'd suggest just having it wait x seconds for the user to approve the 2FA. Obviously this is non-trivial as it'd mean a change to the script itself instead of just packaging it..

seffyroff avatar Jan 29 '24 22:01 seffyroff

@seffyroff Thanks for the bug report! Just now, I pushed a new version that waits for a timeout (only if running in Docker). The timeout is set to 15s.

The new version is tagged in Docker Hub as v3.0-b2 (and latest), while the old one is still available at v3.0-b1.

Let me know if this fixes the 2FA!

belgio99 avatar Jan 31 '24 17:01 belgio99

Hey, thanks so much for this especially with the in-built scheduling. I’ll test on my end as well. FYI I’m not sure if this repo is still in active development, if not, this fork has been more active -> https://github.com/klept0/MS-Rewards-Farmer - might be worth checking out their fixes, updates, etc. as well.

mgrimace avatar Feb 01 '24 23:02 mgrimace

@mgrimace Thank you for letting me know! There is however an already Dockerized version of that fork: https://github.com/LtCMDstone/MS-Rewards-Farmer-Docker/tree/main

Still, there are some things I don't like about that fork:

  1. Builds are manually triggered via workflow_dispatch and not auto-triggered via new commits in the project
  2. Builds are hardly reproducible since the repo's latest version is always pulled at image build time
  3. There is no built-in scheduling

So I'm questioning myself if it still makes sense moving the PR to the @klept0 fork, or discarding the work altogether.

belgio99 avatar Feb 14 '24 12:02 belgio99

@mgrimace Thank you for letting me know! However there is already a Dockerized version of that fork: https://github.com/LtCMDstone/MS-Rewards-Farmer-Docker/tree/main

Still, there are some things I don't like about that fork:

  1. Builds are manually triggered via workflow_dispatch and not auto-triggered via new commits in the project
  2. Builds are hardly reproducible since the repo's latest version is always pulled at image build time
  3. There is no built-in scheduling

So I'm questioning myself if it still makes sense moving the PR to the @klept0 fork, or discarding the work altogether.

For what it’s worth, I share the same concerns, and would much rather see your implementation. IMO there’s no point to a dockerized container if it doesn’t have built-in scheduling, and doesn’t integrate new commits (as the scripts can routinely break, most commits are needed to keep it running smooth).

That being said, there’s an alternative script I’m using now that’s working much better (e.g., clusters for multiple simultaneous accounts, running consistently) and has some preliminary docker work in place that might be a better fit for a PR with your skills: https://github.com/TheNetsky/Microsoft-Rewards-Script

mgrimace avatar Feb 14 '24 13:02 mgrimace

@mgrimace Thank you for letting me know! There is however an already Dockerized version of that fork: https://github.com/LtCMDstone/MS-Rewards-Farmer-Docker/tree/main

Still, there are some things I don't like about that fork:

  1. Builds are manually triggered via workflow_dispatch and not auto-triggered via new commits in the project
  2. Builds are hardly reproducible since the repo's latest version is always pulled at image build time
  3. There is no built-in scheduling

So I'm questioning myself if it still makes sense moving the PR to the @klept0 fork, or discarding the work altogether.

Feel free to make a PR on my repo - anything that helps is appreciated and be included (if beneficial)

klept0 avatar Feb 16 '24 15:02 klept0

Hey @belgio99 Are there any news for the PR to the fork of @klept0 ? :)

SebastianGode avatar Jun 07 '24 11:06 SebastianGode

Hey @belgio99 Are there any news for the PR to the fork of @klept0 ? :)

Yup, thanks for the bump! University was a bit getting in the way in the past months so I couldn't work on this, but I'll resume the work asap!

belgio99 avatar Jun 08 '24 09:06 belgio99

Finally moved the PR to the @klept0 fork.

Everybody is much welcomed to join the discussion at https://github.com/klept0/MS-Rewards-Farmer/pull/114!

See you there!

belgio99 avatar Jun 08 '24 10:06 belgio99