strapi / documentation

Strapi Documentation
https://docs.strapi.io
Other
1.03k stars 1.12k forks source link

Docker build failed with 4.14.0 #1862

Closed exneval closed 1 year ago

exneval commented 1 year ago

Bug report

Required System information

Describe the bug

"ts-zen@git+https://github.com/strapi/ts-zen.git#66e02232f5997674cc7032ea3ee59d9864863732": version "0.1.7" resolved "git+https://github.com/strapi/ts-zen.git#66e02232f5997674cc7032ea3ee59d9864863732"

the need of using "git" with new deps added in 4.14.0

Steps to reproduce the behavior

  1. Build the image
  2. Error showed

Expected behavior

Just publish the deps in npm

Screenshots

If applicable, add screenshots to help explain your problem.

Code snippets

strapi/strapi#10 [ 6/10] RUN yarn config set network-timeout 600000 -g && yarn install
strapi/strapi#10 0.576 yarn config v1.22.19
strapi/strapi#10 0.602 success Set "network-timeout" to "600000".
strapi/strapi#10 0.602 Done in 0.03s.
strapi/strapi#10 0.869 yarn install v1.22.19
strapi/strapi#10 0.939 [1/5] Validating package.json...
strapi/strapi#10 0.942 [2/5] Resolving packages...
strapi/strapi#10 1.304 error Couldn't find the binary git
strapi/strapi#10 1.304 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
strapi/strapi#10 ERROR: process "/bin/sh -c yarn config set network-timeout 600000 -g && yarn install" did not complete successfully: exit code: 1
------
 > [ 6/10] RUN yarn config set network-timeout 600000 -g && yarn install:
0.576 yarn config v1.22.19
0.602 success Set "network-timeout" to "600000".
0.602 Done in 0.03s.
0.869 yarn install v1.22.19
0.939 [1/5] Validating package.json...
0.942 [2/5] Resolving packages...
1.304 error Couldn't find the binary git
1.304 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
------
Dockerfile:14
--------------------
  12 |     WORKDIR /opt/
  13 |     COPY package.json yarn.lock ./
  14 | >>> RUN yarn config set network-timeout 600000 -g && yarn install
  15 |     
  16 |     WORKDIR /opt/app
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn config set network-timeout 600000 -g && yarn install" did not complete successfully: exit code: 1

Additional context

Add any other context about the problem here.

dashart-ke commented 1 year ago

Same for me. If I add git install command to the Dockerfile, it will fail with

------
 > [build 6/9] RUN yarn config set network-timeout 600000 -g && yarn install --production:
#0 1.654 yarn config v1.22.19
#0 1.843 success Set "network-timeout" to "600000".
#0 1.845 Done in 0.24s.
#0 3.443 yarn install v1.22.19
#0 4.215 [1/5] Validating package.json...
#0 4.242 [2/5] Resolving packages...
#0 10.22 [3/5] Fetching packages...
#0 71.13 error Command failed.
#0 71.13 Exit code: 128
#0 71.13 Command: git
#0 71.13 Arguments: ls-remote --tags --heads ssh://git@github.com/strapi/ts-zen.git
#0 71.13 Directory: /opt
#0 71.13 Output:
#0 71.13 "ssh" -oBatchMode=yes: line 0: ssh: not found
#0 71.13 fatal: Could not read from remote repository.
#0 71.13 
#0 71.13 Please make sure you have the correct access rights
#0 71.13 and the repository exists.
#0 71.13 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Issue occurs after upgrade to 4.14.0 from 4.13.6

seanburlington commented 1 year ago

adding git to my Dockerfile install works for me (on a development build)

rafaelmelope commented 1 year ago

Sep 29 05:02:48 PM ==> Running build command 'yarn; yarn build'... Sep 29 05:02:48 PM yarn install v1.22.5 Sep 29 05:02:48 PM warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. Sep 29 05:02:48 PM [1/5] Validating package.json... Sep 29 05:02:48 PM [2/5] Resolving packages... Sep 29 05:02:50 PM [3/5] Fetching packages... Sep 29 05:03:05 PM error Command failed. Sep 29 05:03:05 PM Exit code: 128 Sep 29 05:03:05 PM Command: git Sep 29 05:03:05 PM Arguments: ls-remote --tags --heads ssh://git@github.com/strapi/ts-zen.git Sep 29 05:03:05 PM Directory: /opt/render/project/src Sep 29 05:03:05 PM Output: Sep 29 05:03:05 PM Host key verification failed. Sep 29 05:03:05 PM fatal: Could not read from remote repository. Sep 29 05:03:05 PM
Sep 29 05:03:05 PM Please make sure you have the correct access rights Sep 29 05:03:05 PM and the repository exists. Sep 29 05:03:05 PM info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. Sep 29 05:03:27 PM yarn run v1.22.5 Sep 29 05:03:27 PM $ strapi build Sep 29 05:03:27 PM /bin/sh: 1: strapi: not found Sep 29 05:03:27 PM info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Sep 29 05:03:27 PM error Command failed with exit code 127. Sep 29 05:03:27 PM ==> Build failed šŸ˜ž

rafaelmelope commented 1 year ago

I just deleted and add to .gitignore yarn.lock and package-lock.json make again the deploy and it works fine.

romatou commented 1 year ago

I ran into same problem with Strapi 4.14 and using Dockerfile from their website

Nova 2023-10-01 10ā€Æ 33 54

aethiss commented 1 year ago

same problem. debian 12, node 18, latest version (seems the same on 4.13.6)

mathieudupoux commented 1 year ago

I manage to solve the issue on 4.14.0 version with installing Git and adding node-gyp package before building :

# Creating multi-stage build for production
FROM node:18-alpine AS build
- RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
+ RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json yarn.lock ./
+ RUN yarn global add node-gyp
RUN yarn config set network-timeout 600000 -g && yarn install --production
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build

# Creating final production image
FROM node:18-alpine
RUN apk add --no-cache vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH

RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]

However, I have no bloody idea why the build now requires node-gyp. I hope this little change helps more than just me

romatou commented 1 year ago

I manage to solve the issue on 4.14.0 version with installing Git and adding node-gyp package before building :

# Creating multi-stage build for production
FROM node:18-alpine AS build
- RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
+ RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json yarn.lock ./
+ RUN yarn global add node-gyp
RUN yarn config set network-timeout 600000 -g && yarn install --production
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build

# Creating final production image
FROM node:18-alpine
RUN apk add --no-cache vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH

RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]

However, I have no bloody idea why the build now requires node-gyp. I hope this little change helps more than just me

I managed to solve it the same way. Strange that adding node-gyp in the first RUN operation does not work. Looking for a way to decrease Docker layers

ITSurgeon commented 1 year ago

You are using the latest version of node 18 in your Dockerfile. And from node version 18.18.0, the string "RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1" is no longer necessary. I believe some libraries have been added to node.

I have removed this string and successfully built the project.

rafaelmelope commented 1 year ago

Try the new version: 4.14.2

derrickmehaffy commented 1 year ago

Hmmmm node-gyp and git both should be coming from the source container so unless node recently changed their container not to include these (though I find that odd since node-gyp comes from the node team as a common build dependency) it's not strictly from us.

:thinking:

derrickmehaffy commented 1 year ago

I'm going to move this issue over to our documentation repo as it's not to do with the main code-base but the example docker file in our docs. If anyone would like to make a PR to the docs, the https://github.com/strapi/documentation repo is included in hacktoberfest and would be included as a repo for qualify for the t-shirt and what not.

dashart-ke commented 1 year ago

Confirming fix: Strapi docker image build (node 18 base image) for production is working as expected again with 4.14.2.

šŸ‘

franckadil commented 1 year ago

I have this error: fatal: unable to access 'https://github.com/strapi/ts-zen/': Could not resolve host: github.com

[+] Building 8.3s (10/18)                                                                                docker:default
 => [strapi-v4 internal] load .dockerignore                                                                        0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [strapi-v4 internal] load build definition from Dockerfile                                                     0.0s
 => => transferring dockerfile: 875B                                                                               0.0s
 => [strapi-v4 internal] load metadata for docker.io/library/node:18-alpine                                        0.7s
 => [strapi-v4 internal] load build context                                                                        1.6s
 => => transferring context: 4.26MB                                                                                1.5s
 => CACHED [strapi-v4 build 1/8] FROM docker.io/library/node:18-alpine@sha256:a315556d82ef54561e54fca7d8ee333382d  0.0s
 => CANCELED [strapi-v4 stage-1 2/7] RUN apk add --no-cache vips-dev                                               7.6s
 => CACHED [strapi-v4 build 2/8] RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev l  0.0s
 => CACHED [strapi-v4 build 3/8] WORKDIR /opt/                                                                     0.0s
 => CACHED [strapi-v4 build 4/8] COPY package.json yarn.lock ./                                                    0.0s
 => ERROR [strapi-v4 build 5/8] RUN yarn config set network-timeout 600000 -g && yarn install --production         5.9s
------
 > [strapi-v4 build 5/8] RUN yarn config set network-timeout 600000 -g && yarn install --production:
0.460 yarn config v1.22.19
0.478 success Set "network-timeout" to "600000".
0.478 Done in 0.02s.
0.639 yarn install v1.22.19
0.693 [1/5] Validating package.json...
0.696 [2/5] Resolving packages...
5.847 error Command failed.
5.847 Exit code: 128
5.847 Command: git
5.847 Arguments: ls-remote --tags --heads https://github.com/strapi/ts-zen
5.847 Directory: /opt
5.847 Output:
5.847 fatal: unable to access 'https://github.com/strapi/ts-zen/': Could not resolve host: github.com
5.847 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
------
failed to solve: process "/bin/sh -c yarn config set network-timeout 600000 -g && yarn install --production" did not complete successfully: exit code: 128
romatou commented 1 year ago

You are using the latest version of node 18 in your Dockerfile. And from node version 18.18.0, the string "RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1" is no longer necessary. I believe some libraries have been added to node.

I have removed this string and successfully built the project.

Please provide your Dockerfile, because I tried both removing the line you mentioned and only node-gyp. In both cases the Image could not be built.