shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

Production deployment with nextjs Dockerfile

Open ahmed-adly-khalil opened this issue 4 years ago • 3 comments
trafficstars

Issue summary

I'm trying to deploy my app created using this template to a k8s cluster using nextjs docker file here https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile however i'm getting this error API key must be provided I have checked the pod and it's running correctly..

Screen Shot 2021-08-09 at 1 30 22 AM

ahmed-adly-khalil avatar Aug 09 '21 16:08 ahmed-adly-khalil

Maybe this was solved but Id like to noticed:

  1. Your .env file should have SHOPIFY_API_KEY=........
  2. Your server.js: Shopify.Context.initialize({ API_KEY: process.env.SHOPIFY_API_KEY, ........
  3. Your _app.js: config={{ apiKey: API_KEY, .......
  4. your next.config.js:
const { parsed: localEnv } = require("dotenv").config();

const webpack = require("webpack");
const apiKey = JSON.stringify(process.env.SHOPIFY_API_KEY);

module.exports = {
	webpack: (config) => {
		const env = { API_KEY: apiKey };
		config.plugins.push(new webpack.DefinePlugin(env));

		// Add ESM support for .mjs files in webpack 4
		config.module.rules.push({
			test: /\.mjs$/,
			include: /node_modules/,
			type: "javascript/auto",
		});

		return config;
	},
};

rodrigograca31 avatar Dec 17 '21 12:12 rodrigograca31

But! I was unable to deploy anywhere else other than Heroku.... so, good luck trying to use docker.........

rodrigograca31 avatar Dec 17 '21 12:12 rodrigograca31

I also faced this issue while deploying the nextjs app to a k8 cluster. The problem was that the API_KEY was not getting injected into the docker image during the build phase and thus not available to nextjs build.

So, I added the Api key to the docker image with

docker build --build-arg NEXT_PUBLIC_SHOPIFY_API_KEY=<api-key>

and then used it in the nextjs build using the docker ARG

ARG NEXT_PUBLIC_SHOPIFY_API_KEY

RUN npm run build 

mkamalkayani avatar Feb 01 '22 18:02 mkamalkayani

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

github-actions[bot] avatar Oct 22 '22 02:10 github-actions[bot]