mifi / instauto

Instagram bot / automation library written in Javascript for Node.js
797 stars 145 forks source link

Feature/adding docker support #141

Closed maxxxdj closed 1 year ago

maxxxdj commented 1 year ago

@mifi rebased and added your requested changes https://github.com/mifi/instauto/pull/141/

mifi commented 1 year ago

I updated and merged the original PR, closing this. thanks!

thegreenmilecornant commented 1 year ago

Looks promising! Thank you for doing this!

I have only deployed containers based on images available on a hub.

But I tried creating the image and running it locally.

The steps I tried to take;

  1. Pulled the repository to /opt/instauto
  2. Modified the docker-compose.yaml env variables to my username and password
  3. Ran docker-compose --profile instauto up -d
  4. Checked Portainer and can see that the image is created and the container started (and then stopped). The logs looks like this;
node:internal/modules/cjs/loader:936

  throw err;
  ^
Error: Cannot find module 'puppeteer'
Require stack:
- /app/instauto/example.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/instauto/example.js:3:19)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/instauto/example.js' ]
}
Node.js v17.9.1
mifi commented 1 year ago

do you see if the CMD yarn gets run?

thegreenmilecornant commented 1 year ago

It doesn't run.

When building the image I get this output:

Building instauto
[+] Building 0.0s (10/10) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 580B                                                                               0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/node:17-slim                                                    0.0s
 => [1/5] FROM docker.io/library/node:17-slim                                                                      0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 2.49kB                                                                                0.0s
 => CACHED [2/5] RUN apt-get update                                                                                0.0s
 => CACHED [3/5] RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3  0.0s
 => CACHED [4/5] WORKDIR /app/instauto                                                                             0.0s
 => CACHED [5/5] COPY . /app/instauto                                                                              0.0s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:28872982a7c2b0d50bc9d0c48a4de16606b2a0dea50c9749488377d76110f0e8                       0.0s
 => => naming to docker.io/library/instauto_instauto                                                               0.0s
WARNING: buildx: failed to read current commit information with git rev-parse --is-inside-work-tree
WARNING: Image for service instauto was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating instauto_instauto_1 ... done
mifi commented 1 year ago

oh. unfortunately docker experience is limited. reading their docs it seems that CMD shouldn't contain build steps. I changed that now, can you try again: https://github.com/mifi/instauto/blob/master/Dockerfile

thegreenmilecornant commented 1 year ago

Thank you for trying!

Now it's running the yarn command, see below.

Building instauto
[+] Building 0.0s (11/11) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 618B                                                                               0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/node:17-slim                                                    0.0s
 => [1/6] FROM docker.io/library/node:17-slim                                                                      0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 2.49kB                                                                                0.0s
 => CACHED [2/6] RUN apt-get update                                                                                0.0s
 => CACHED [3/6] RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3  0.0s
 => CACHED [4/6] WORKDIR /app/instauto                                                                             0.0s
 => CACHED [5/6] COPY . /app/instauto                                                                              0.0s
 => CACHED [6/6] RUN yarn                                                                                          0.0s
 => exporting to image                                                                                             0.0s
 => => exporting layers                                                                                            0.0s
 => => writing image sha256:8c9df67a3c882df2addce0c2c6a3551d85c4b41c0703d312c6fc9bdf2f08afc0                       0.0s
 => => naming to docker.io/library/instauto_instauto                                                               0.0s
WARNING: buildx: failed to read current commit information with git rev-parse --is-inside-work-tree
WARNING: Image for service instauto was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating instauto_instauto_1 ... done

But the log stays the same:

node:internal/modules/cjs/loader:936

  throw err;
  ^
Error: Cannot find module 'instauto'
Require stack:
- /app/instauto/example.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/instauto/example.js:5:18)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/instauto/example.js' ]
}
Node.js v17.9.1
mifi commented 1 year ago

ok i made another change

thegreenmilecornant commented 1 year ago

It's running 🥳

The timezone is off. Tried adding a TZ-env-variable without luck.

And I didn't manage to log in.

And the language selector failed.

No followed database found
No unfollowed database found
No likes database found
2023-03-08T14:11:14.346Z No cookies found
2023-03-08T14:11:14.346Z Setting language to English (en)
2023-03-08T14:11:14.346Z Waiting 1.00 sec
2023-03-08T14:11:34.003Z Waiting 3.89 sec
2023-03-08T14:11:37.948Z Found language selector
2023-03-08T14:11:37.951Z Already English language
2023-03-08T14:11:54.467Z Waiting 1.08 sec
2023-03-08T14:11:55.557Z Pressing button: Accept cookies dialog 2 button 1
2023-03-08T14:11:55.558Z Waiting 11.86 sec
2023-03-08T14:12:07.427Z No login page button, assuming we are on login form
2023-03-08T14:12:10.297Z Waiting 1.89 sec
2023-03-08T14:12:18.308Z Waiting 1.76 sec
2023-03-08T14:12:33.448Z Still not logged in, trying to reload loading page
2023-03-08T14:12:56.845Z Waiting 8.84 sec
2023-03-08T14:13:05.852Z Setting language to English (en)
2023-03-08T14:13:05.852Z Waiting 1.44 sec
2023-03-08T14:13:37.289Z Failed to set language, trying fallback (cookie) TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
    at /app/instauto/node_modules/puppeteer/lib/LifecycleWatcher.js:142:21
  -- ASYNC --
    at Frame.<anonymous> (/app/instauto/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.goto (/app/instauto/node_modules/puppeteer/lib/Page.js:674:49)
    at Page.<anonymous> (/app/instauto/node_modules/puppeteer/lib/helper.js:112:23)
    at gotoUrl (/app/instauto/src/index.js:186:39)
    at setLang (/app/instauto/src/index.js:931:15)
    at async Instauto (/app/instauto/src/index.js:1062:5)
    at async /app/instauto/example.js:103:22
TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
    at /app/instauto/node_modules/puppeteer/lib/LifecycleWatcher.js:142:21
  -- ASYNC --
    at Frame.<anonymous> (/app/instauto/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.goto (/app/instauto/node_modules/puppeteer/lib/Page.js:674:49)
    at Page.<anonymous> (/app/instauto/node_modules/puppeteer/lib/helper.js:112:23)
    at gotoUrl (/app/instauto/src/index.js:186:39)
    at goHome (/app/instauto/src/index.js:919:30)
    at setLang (/app/instauto/src/index.js:967:13)
    at async Instauto (/app/instauto/src/index.js:1062:5)
    at async /app/instauto/example.js:103:22
Closing browser
mifi commented 1 year ago

at least it's something 😅 i'm not so experienced with docker but if someone wants to take over and fix it, feel free to open a PR