vuestorefront / storefront-api

Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends

Home Page:https://storefrontapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Launching sfa_app don't work

Abdoul19 opened this issue · comments

Hi,
Unable to launch the container correctly, package problem with yarn.
Here is what is displayed after a docker-compose up.

root@ip-XX-XX-XX-XX:/var/www/storefront-api# docker-compose -f docker-compose.yml up -d
Building app
Step 1/9 : FROM node:10-alpine
---> 955e0e1f1a41
Step 2/9 : ENV VS_ENV prod
---> Using cache
---> f0662d5d6ca5
Step 3/9 : WORKDIR /var/www
---> Using cache
---> 4fbd3d19fdd7
Step 4/9 : RUN apk add --no-cache curl git
---> Using cache
---> c20adfc485a4
Step 5/9 : COPY package.json ./
---> Using cache
---> 373136d9f3cc
Step 6/9 : COPY yarn.lock ./
---> Using cache
---> 327f2f1f48ce
Step 7/9 : RUN apk add --no-cache --virtual .build-deps ca-certificates wget && yarn install --no-cache && apk del .build-deps
---> Running in a01da6e43b48
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/2) Installing wget (1.20.3-r0)
(2/2) Installing .build-deps (20200212.020116)
Executing busybox-1.31.1-r9.trigger
OK: 24 MiB in 25 packages
yarn install v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz: Request failed "404 Not Found"".
info If you think this is a bug, please open a bug report with the information provided in "/var/www/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
warning url-loader@1.1.2: Invalid bin field for "url-loader".
warning sha.js@2.4.11: Invalid bin entry for "sha.js" (in "sha.js").
ERROR: Service 'app' failed to build: The command '/bin/sh -c apk add --no-cache --virtual .build-deps ca-certificates wget && yarn install --no-cache && apk del .build-deps' returned a non-zero code: 1

Hey,
That looks like a problem with yarns Package registry and I just have tested the URL and it works for me.
So is it still a problem for you or is it gone?

Still a problem, but not with the link anymore.
Now the container is build without some packages, "url-loader" and "sha.js"
here is the error in build process.

yarn install v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
warning url-loader@1.1.2: Invalid bin field for "url-loader".
warning sha.js@2.4.11: Invalid bin entry for "sha.js" (in "sha.js").
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 38.15s.
WARNING: Ignoring APKINDEX.70f61090.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.ca2fea5b.tar.gz: No such file or directory
(1/2) Purging .build-deps (20200212.100841)
(2/2) Purging wget (1.20.3-r0)
Executing busybox-1.31.1-r9.trigger
OK: 24 MiB in 23 packages
Removing intermediate container 44e48cdd9f50
---> 7cd2729fa70a
Step 8/9 : COPY docker/storefront-api/storefront-api.sh /usr/local/bin/
---> 44e3f1c5cbe7
Step 9/9 : CMD ["storefront-api.sh"]
---> Running in 519a59ad9759
Removing intermediate container 519a59ad9759
---> 40c6848e58da
Successfully built 40c6848e58da
Successfully tagged sfa_app:latest
WARNING: Image for service app was built because it did not already exist. To rebuild this image you must use docker-compose build or docker-compose up --build.
Creating elasticsearch ... done
Creating sfa_redis_1 ... done
Creating sfa_app_1 ... done

The warnings are normal due to a new version of yarn and can be ignored according to yarnpkg/yarn#7803

It says that all the images have been built successfully.
Try looking at the logs via docker logs sfa_app_1 to see if there are additional errors.

the error is coming when I want to empty the default index.

node scripts/db.js new
internal/modules/cjs/loader.js:796
throw err;
^

Error: Cannot find module '/var/www/storefront-api/scripts/db.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

the error is coming when I want to empty the default index.

node scripts/db.js new
internal/modules/cjs/loader.js:796
throw err;
^

Error: Cannot find module '/var/www/storefront-api/scripts/db.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

I found db.js in src/, and I modify the command like that
node src/db.js new

import config from 'config'
^^^^^^

SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:891:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11

Now, that is actually a bug.
We used to have a db.js in the vue-storefront-api project, but it is now replaced by db7.ts.

@ResuBaka Since we're starting out this project with ES7, how about we keep using db.js/db.ts without the 7 to avoid future version problems?

@Abdoul19 That file just shares a similar name and is actually different in code.
The file that the script is trying to refer to is https://github.com/DivanteLtd/vue-storefront-api/blob/master/scripts/db.js which was built for ES5, but now we're using ES7, so we need to fix it.

Ok, but how can I empty the default index without that ?

You can still use db7.ts, it's just that you need to run a specific command to transpile it from TypeScript to JavaScript.

See the command used here: https://github.com/DivanteLtd/storefront-api/blob/bbf2ebf6979102aaafd0bf64fc2168af393030b2/docs/guide/modules/tutorial.md

@themreza yea we should move the script for such cases back to .js and look that they work with calling them from node directly.
Here we need to even look into it a bit as we want in the feature that developer don't use this Repository directly. So we need to thing about moving these scripts to a @storefront-api/cli package maybe?

In develop branch most packages are already moved to there own packages. So you can just install them them when you need them.

@Abdoul19 to run the db7.ts you can just call yarn db7. That will run the scripts/db7.ts

/var/www/storefront-api# yarn db7
yarn run v1.21.1
$ export TS_NODE_PROJECT="tsconfig.json" && ts-node -r tsconfig-paths/register scripts/db7.ts
/bin/sh: 1: ts-node: not found
error Command failed with exit code 127.

Do you have the devDependencies installed?

I have npm, yarn, git, docker & docker-compose installed

Do you have an node_modules/ts-node folder?

Do you have an node_modules/ts-node folder?

Don't see that anywhere

Can you try if that works for you docker-compose exec app yarn db7.

As the node_modules with the docker setup are all installed in the docker container that is running.

Can you try if that works for you docker-compose exec app yarn db7.

As the node_modules with the docker setup are all installed in the docker container that is running.

$ export TS_NODE_PROJECT="tsconfig.json" && ts-node -r tsconfig-paths/register scripts/db7.ts

this work for empty the default index

docker exec -it sfa_app_1 yarn restore7