kinngh / shopify-node-express-mongodb-app

An embedded Shopify app starter template made with Node, Express, React and Vite, with all the required stuff hooked up.
https://x.com/kinngh
MIT License
289 stars 98 forks source link

Set ENV in the `Dockerfile` for Fly.io #98

Closed jonasmatuliauskas closed 1 year ago

jonasmatuliauskas commented 1 year ago

Hello, Harshdeep Singh Hura 👋

I want to upload an app to fly.io, but get an error:

...
 => CACHED [base 2/2] WORKDIR /app                                                                                                                                                         0.0s
 => CACHED [build 1/6] RUN apt-get update -qq &&     apt-get install -y build-essential pkg-config python-is-python3                                                                       0.0s
 => CACHED [build 2/6] COPY --link package-lock.json package.json ./                                                                                                                       0.0s
 => CACHED [build 3/6] RUN npm ci --include=dev                                                                                                                                            0.0s
 => [build 4/6] COPY --link . .                                                                                                                                                            0.0s
 => ERROR [build 5/6] RUN npm run build                                                                                                                                                    1.1s
------                                                                                                                                                                                          
 > [build 5/6] RUN npm run build:
#0 0.560 
#0 0.560 > shopify-express-boilerplate@0.0.6 build
#0 0.560 > vite build --config=./client/vite.config.cjs
#0 0.560 
#0 1.072 failed to load config from /app/client/vite.config.cjs
#0 1.073 error during build:
#0 1.073 TypeError: Cannot read properties of undefined (reading 'replace')
#0 1.073     at Object.<anonymous> (/app/client/vite.config.cjs:70:35)
#0 1.073     at Module._compile (node:internal/modules/cjs/loader:1254:14)
#0 1.073     at _require.extensions.<computed> [as .js] (file:///app/node_modules/vite/dist/node/chunks/dep-df561101.js:66253:24)
#0 1.073     at Module.load (node:internal/modules/cjs/loader:1117:32)
#0 1.073     at Module._load (node:internal/modules/cjs/loader:958:12)
#0 1.073     at Module.require (node:internal/modules/cjs/loader:1141:19)
#0 1.073     at require (node:internal/modules/cjs/helpers:110:18)
#0 1.073     at loadConfigFromBundledFile (file:///app/node_modules/vite/dist/node/chunks/dep-df561101.js:66261:21)
#0 1.073     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
#0 1.073     at async loadConfigFromFile (file:///app/node_modules/vite/dist/node/chunks/dep-df561101.js:66086:28)
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c npm run build]: exit code: 1

In the code process.env.<...> can't access values unless I set it in the Dockerfile. Is it safe?

image
kinngh commented 1 year ago

Hey @jonasmatuliauskas !

I don't have enough experience with Docker or Fly.io to comment on that. I can see though that it's having issues at build, so you can use the ARG to pass almost everything except for MONGO_URL and SHOPIFY_APP_SECRET, which isn't required at build time.

Though I did search a little and the recommendation has been to use a docker-compose.yml file, and ChatGPT also seems to be recommending the same. I'm gonna keep this issue open while I play around with this over the weekend, unless you find a setup that works.^

jonasmatuliauskas commented 1 year ago

Where do you recommend deploy an app? Heroku?

kinngh commented 1 year ago

Yep! I've deployed for years on Heroku, behind a Cloudflare cache layer

jonasmatuliauskas commented 1 year ago

It's enough to get success deploy. Thank you!

image

I have one more question about: https://ngrokurl.io/auth?shop=mystorename.myshopify.com https://github.com/kinngh/shopify-node-express-mongodb-app/blob/main/docs/SETUP.md

How it will work in the end? I mean, I will build an app based on your boilerplate and submit it for review and approval for Shopify, to be published and accessible for everyone, and for them (Shopify during review and for everyone), it works normally or will I have to give them information on how to install it? Your approach is not default to start an installation, by default it has to be installed using this button:

image
kinngh commented 1 year ago

So what's broken is the dev mode. In dev mode, Vite and Express run on different ports and using Ngrok you can expose only one. In prod mode, we're only using one port, which is controlled by env's PORT variable, meaning you can do a normal install using select store when running in prod mode by running npm run start, so no, you don't have to provide installation instructions to anyone as long as you're running in production mode^

Hamzakdev112 commented 1 year ago

You need to remove .env from Docker Ignore file