GitHub Actions: Error when copying generated directory to Docker image - node.js

I am using GitHub Actions to build our NestJS application.
These are some of the steps in the GitHub Actions workflow:
- name: Build Nest application
run: npm run build
- run: ls -al
- name: Build the Docker image
run: docker build . --file github.Dockerfile
github.Dockerfile looks like this:
FROM node:14-alpine as app
WORKDIR /usr/home/app
COPY package.json ./
COPY src ./
COPY node_modules ./
The build fails with this error message:
Step 5/5 : COPY node_modules ./
COPY failed: stat /var/lib/docker/tmp/docker-builder535687818/node_modules: no such file or directory
When listing the directory contents with RUN ls -al, this is the result:
drwxr-xr-x 9 runner docker 4096 Sep 29 12:53 .
drwxr-xr-x 3 runner docker 4096 Sep 29 12:52 ..
-rw-r--r-- 1 runner docker 1541 Sep 29 12:52 .dockerignore
-rw-r--r-- 1 runner docker 663 Sep 29 12:52 .eslintrc.js
-rw-r--r-- 1 runner docker 1300 Sep 29 12:52 .gcloudignore
drwxr-xr-x 8 runner docker 4096 Sep 29 12:52 .git
drwxr-xr-x 3 runner docker 4096 Sep 29 12:52 .github
-rw-r--r-- 1 runner docker 388 Sep 29 12:52 .gitignore
-rw-r--r-- 1 runner docker 51 Sep 29 12:52 .prettierrc
-rw-r--r-- 1 runner docker 3370 Sep 29 12:52 README.md
-rw-r--r-- 1 runner docker 162 Sep 29 12:52 cloudbuild.yaml
drwxr-xr-x 2 runner docker 4096 Sep 29 12:53 dist
-rw-r--r-- 1 runner docker 102 Sep 29 12:52 github.Dockerfile
drwxr-xr-x 2 runner docker 4096 Sep 29 12:52 k8s
-rw-r--r-- 1 runner docker 64 Sep 29 12:52 nest-cli.json
drwxr-xr-x 134 runner docker 4096 Sep 29 12:53 node_modules
-rw-r--r-- 1 runner docker 521420 Sep 29 12:52 package-lock.json
-rw-r--r-- 1 runner docker 1923 Sep 29 12:52 package.json
-rw-r--r-- 1 runner docker 471 Sep 29 12:52 skaffold.Dockerfile
-rw-r--r-- 1 runner docker 446 Sep 29 12:52 skaffold.yaml
drwxr-xr-x 2 runner docker 4096 Sep 29 12:52 src
drwxr-xr-x 2 runner docker 4096 Sep 29 12:52 test
-rw-r--r-- 1 runner docker 97 Sep 29 12:52 tsconfig.build.json
-rw-r--r-- 1 runner docker 339 Sep 29 12:52 tsconfig.json
package.json and src are part of the Git repository. node_modules gets generated in the process of the GitHub Action.
Why can't node_modules be copied to the Docker container, while both package.json and src can?

It turned out node_modules was included in the .dockerignore file. 🤦🏻‍♂️

Related

Execing docker image entrypoint, which is a compiled go app, fails with "not found"

I have built a small Go app and done local testing of it on my Linux VM.
I'm now trying to build a prototype Docker image for it and test running the image. The Dockerfile structure is pretty simple. I base it on Alpine, copy the executable to the root directory and my entrypoint is running the executable.
It fails with "not found".
Now for more details.
Here is the Dockerfile, with some information elided:
FROM <registry>/<namespace>/alpine-base:3.12.3
COPY target/dist/linux-amd64/<appname> /
EXPOSE 8080
RUN echo hello
RUN ls -ltd .
RUN ls -lt
RUN whoami
#ENTRYPOINT ["./<appname>"]
ENTRYPOINT ./<appname>
This is approximately what I do when I build the image:
chmod 777 target/dist/linux-amd64/<appname>
docker build --no-cache -f Dockerfile -t <registry>/<namespace>/<appname>:dev-latest .
This is the output of that:
Sending build context to Docker daemon 14.48MB
Step 1/8 : FROM <registry>/<namespace>/alpine-base:3.12.3
---> d7eec24f3d29
Step 2/8 : COPY target/dist/linux-amd64/<appname> /
---> e056bbe44bd6
Step 3/8 : EXPOSE 8080
---> Running in 921cc1fe8804
Removing intermediate container 921cc1fe8804
---> 00b30c5a2770
Step 4/8 : RUN echo hello
---> Running in 9fb08d924d3c
hello
Removing intermediate container 9fb08d924d3c
---> 6788feafae4b
Step 5/8 : RUN ls -ltd .
---> Running in 78e6d4aea09f
drwxr-xr-x 1 root root 4096 Jan 10 23:02 .
Removing intermediate container 78e6d4aea09f
---> 711f3d247efe
Step 6/8 : RUN ls -lt
---> Running in 32e703a9d480
total 14200
drwxr-xr-x 5 root root 340 Jan 10 23:02 dev
drwxr-xr-x 1 root root 4096 Jan 10 23:02 etc
dr-xr-xr-x 324 root root 0 Jan 10 23:02 proc
dr-xr-xr-x 13 root root 0 Jan 10 23:02 sys
-rwxrwxrwx 1 root root 14480384 Jan 10 22:39 <appname>
drwxr-xr-x 1 root root 4096 Jan 12 2021 home
drwxr-xr-x 1 root root 4096 Jan 12 2021 opt
drwxr-xr-x 2 root root 4096 Dec 16 2020 bin
drwxr-xr-x 2 root root 4096 Dec 16 2020 sbin
drwxr-xr-x 1 root root 4096 Dec 16 2020 lib
drwxr-xr-x 5 root root 4096 Dec 16 2020 media
drwxr-xr-x 2 root root 4096 Dec 16 2020 mnt
drwx------ 2 root root 4096 Dec 16 2020 root
drwxr-xr-x 2 root root 4096 Dec 16 2020 run
drwxr-xr-x 2 root root 4096 Dec 16 2020 srv
drwxrwxrwt 2 root root 4096 Dec 16 2020 tmp
drwxr-xr-x 1 root root 4096 Dec 16 2020 usr
drwxr-xr-x 1 root root 4096 Dec 16 2020 var
Removing intermediate container 32e703a9d480
---> 68871e80b517
Step 7/8 : RUN whoami
---> Running in 40b2460bc349
kube
Removing intermediate container 40b2460bc349
---> 4cf57c0b5f10
Step 8/8 : ENTRYPOINT ./<appname>
---> Running in 3c57717800ab
Removing intermediate container 3c57717800ab
---> eaafc953da46
Successfully built eaafc953da46
Successfully tagged <registry>/<namespace>/<appname>:dev-latest
And this is what I run to test it:
docker rm <appname>-1
docker run -P --name=<appname>-1 -d -t <registry>/<namespace>/<appname>:dev-latest
docker logs <appname>-1
And this is the output:
docker rm <appname>-1
<appname>-1
docker run -P --name=<appname>-1 -d -t <registry>/<namespace>/<appname>:dev-latest
66bb4756783b3ef64d9a4b0d8b7227184ba3b5a3fde25ea0d19b9523285d76b7
docker logs <appname>-1
/bin/sh: ./<appname>: not found
It says "not found". I don't understand that. I showed the contents of the root directory. The file is clearly there. Is this error saying that some OTHER file is not found, like if it thought it was a shell script and the shebang pointed to a shell that doesn't exist?
Update:
So the one tiny little detail that I realized I didn't mention in the original post is that disabling CGO is not going to be possible. The entire reason for this app is to link with a C library and call functions in it, so I have to use Cgo.
What I conclude from these helpful comments and other threads like Go-compiled binary won't run in an alpine docker container on Ubuntu host , is that my "workaround" of changing to an ubuntu base image is actually the only reasonable solution.
If disabling cgo is not an option you can pass "-static" parameter to the linker.
Example:
package main
/*
#include <stdio.h>
void test_puts() {
puts("puts() called");
}
*/
import "C"
func main() {
C.test_puts()
}
Run:
go build --ldflags '-extldflags "-static"'

How to deploy to dedicated server using circleci

I am very new to CircleCi and trying to deploy a node/npm/vue app to plesk on contabo where domain is on a dedicated IP. The error has the following details.
ls -al rsync -a dist/* $SSH_USER#$SSH_HOSTNAME:/var/www/vhosts/mydomain.com/domain.com total 524
drwxrwxr-x 7 circleci circleci 4096 Sep 16 12:50 .
drwxr-xr-x 16 circleci circleci 4096 Sep 16 12:50 ..
-rw-rw-r-- 1 circleci circleci 66 Sep 16 12:50 babel.config.js
drwxrwxr-x 2 circleci circleci 4096 Sep 16 12:50 .circleci
drwxr-xr-x 6 circleci circleci 4096 Sep 16 12:49 dist
drwxrwxr-x 8 circleci circleci 4096 Sep 16 12:50 .git
-rw-rw-r-- 1 circleci circleci 230 Sep 16 12:50 .gitignore
-rw-rw-r-- 1 circleci circleci 107 Sep 16 12:50 jsconfig.json
-rw-rw-r-- 1 circleci circleci 1533 Sep 16 12:50 package.json
-rw-rw-r-- 1 circleci circleci 481935 Sep 16 12:50 package-lock.json
drwxrwxr-x 2 circleci circleci 4096 Sep 16 12:50 public
-rw-rw-r-- 1 circleci circleci 329 Sep 16 12:50 README.md
drwxrwxr-x 8 circleci circleci 4096 Sep 16 12:50 src
-rw-rw-r-- 1 circleci circleci 59 Sep 16 12:50 vue.config.js
ssh: connect to host ************* port 22: Connection timed out rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]
Exited with code exit status 255 CircleCI received exit code 255
Why am I getting this error and how do I resolve it?

AWS CodePipeline missing directories/files after being deployed to Elastic Beanstalk

This is a more-narrowed-down problem stemming from my earlier question.
Here is my buildspec.yml:
version: 0.2
phases:
install:
commands:
# upgrade AWS CLI
- pip install --upgrade awscli
# install Node 12
- curl -sL https://deb.nodesource.com/setup_12.x | bash -
- apt install nodejs
pre_build:
commands:
# install server dependencies
- npm install
build:
commands:
# install client dependencies and build static files
- npm install --prefix client && npm run build --prefix client
post_build:
commands:
# FOR TESTING AND DEBUGGING
- ls -la
- ls client -la
- mkdir client/TEST
- ls client -la
artifacts:
files:
- '**/*'
discard-paths: no
base-directory: '*'
In the post-build phase, I output directories for debugging and this is what they show:
[Container] 2020/07/02 02:36:15 Entering phase POST_BUILD
[Container] 2020/07/02 02:36:15 Running command ls -la
total 132
drwxr-xr-x 11 root root 4096 Jul 2 02:34 .
drwxr-xr-x 3 root root 4096 Jul 2 02:34 ..
-rw-rw-r-- 1 root root 129 Jul 2 02:33 .gitignore
-rw-rw-r-- 1 root root 16 Jul 2 02:33 .npmrc
-rw-rw-r-- 1 root root 34 Jul 2 02:33 README.md
-rw-rw-r-- 1 root root 1737 Jul 2 02:33 app.js
drwxr-xr-x 2 root root 4096 Jul 2 02:34 bin
-rw-rw-r-- 1 root root 655 Jul 2 02:33 buildspec.yml
drwxr-xr-x 6 root root 4096 Jul 2 02:35 client
drwxr-xr-x 2 root root 4096 Jul 2 02:34 config
drwxr-xr-x 2 root root 4096 Jul 2 02:34 graphql
drwxr-xr-x 2 root root 4096 Jul 2 02:34 models
drwxr-xr-x 197 root root 4096 Jul 2 02:34 node_modules
-rw-rw-r-- 1 root root 63888 Jul 2 02:33 package-lock.json
-rw-rw-r-- 1 root root 814 Jul 2 02:33 package.json
drwxr-xr-x 2 root root 4096 Jul 2 02:34 routes
drwxr-xr-x 2 root root 4096 Jul 2 02:34 services
drwxr-xr-x 2 root root 4096 Jul 2 02:34 views
[Container] 2020/07/02 02:36:15 Running command ls client -la
total 748
drwxr-xr-x 6 root root 4096 Jul 2 02:35 .
drwxr-xr-x 11 root root 4096 Jul 2 02:34 ..
drwxr-xr-x 3 root root 4096 Jul 2 02:36 build
drwxr-xr-x 1081 root root 36864 Jul 2 02:35 node_modules
-rw-rw-r-- 1 root root 699332 Jul 2 02:33 package-lock.json
-rw-rw-r-- 1 root root 1212 Jul 2 02:33 package.json
drwxr-xr-x 2 root root 4096 Jul 2 02:34 public
drwxr-xr-x 8 root root 4096 Jul 2 02:34 src
[Container] 2020/07/02 02:36:15 Running command mkdir client/TEST
[Container] 2020/07/02 02:36:15 Running command ls client -la
total 752
drwxr-xr-x 7 root root 4096 Jul 2 02:36 .
drwxr-xr-x 11 root root 4096 Jul 2 02:34 ..
drwxr-xr-x 2 root root 4096 Jul 2 02:36 TEST
drwxr-xr-x 3 root root 4096 Jul 2 02:36 build
drwxr-xr-x 1081 root root 36864 Jul 2 02:35 node_modules
-rw-rw-r-- 1 root root 699332 Jul 2 02:33 package-lock.json
-rw-rw-r-- 1 root root 1212 Jul 2 02:33 package.json
drwxr-xr-x 2 root root 4096 Jul 2 02:34 public
drwxr-xr-x 8 root root 4096 Jul 2 02:34 src
[Container] 2020/07/02 02:36:15 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2020/07/02 02:36:15 Phase context status code: Message:
[Container] 2020/07/02 02:36:15 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2020/07/02 02:36:15 Phase context status code: Message:
Which shows that client/build, client/node_modules, and a test directory client/TEST were all created during the CodeBuild. However when I go to the Beanstalk environment I get the error:
ENOENT: no such file or directory, stat '/var/app/current/client/build/index.html'
When I ssh into Beanstalk and check the /var/app/current/ directory, the node_modules in the root directory was successfully built. However, the client/build, client/node_modules, and client/TEST are all missing:
$ cd /var/app/current
$ ls
app.js buildspec.yml config models package.json Procfile routes views
bin client graphql node_modules package-lock.json README.md services
$ cd client
$ ls
package.json package-lock.json public src
This indicates to me that something messed up in the Deploy stage of the CodePipeline, or maybe the artifacts section of the buildspec.yml. I have been stuck on this issue for so long and have no idea how to go about it.
Based on the comments.
To deploy to ElasticBeanstalk, CodePipepine is using Elastic Beanstalk provider in a Deploy action. As part of setting up this action, input artifacts need to be specified.
The issue was that the input artifacts were set to use Source action, rather then the CodeBuild action.
The solution was to adjust the setting of the the Deploy action to use the CodeBuild artifacts, instead of Source artifacts.

kubernetes giving error,but code works

every time when deploying this images getting this error`
module.js:540
throw err;
^
Error: Cannot find module '/app/index.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
but code works on pc,I hadn't get error for other deployments they was done this way
dockerfile`
FROM node:8.9
ENV port 3000
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["sh", "-c", "node index.js --port=${port}"]
yaml `
output of RUN ls -la after COPY ./app
Step 7/8 : RUN ls -la
---> Running in 9e24667abd49
total 76
drwxr-xr-x 9 root root 4096 Jun 21 07:14 .
drwxr-xr-x 57 root root 4096 Jun 21 07:14 ..
-rw-rw-r-- 1 root root 30 May 31 09:00 .dockerignore
-rw-rw-r-- 1 root root 151 Jun 21 07:14 Dockerfile
-rw-rw-r-- 1 root root 556 Jun 20 15:16 api.yaml
drwxrwxr-x 2 root root 4096 May 23 09:03 controllers
-rw-rw-r-- 1 root root 446 Jun 20 15:18 index.js
drwxrwxr-x 3 root root 4096 May 15 11:27 insert
drwxrwxr-x 3 root root 4096 May 15 11:27 modules
drwxr-xr-x 69 root root 4096 Jun 20 15:07 node_modules
-rw-r--r-- 1 root root 20404 Jun 20 15:07 package-lock.json
-rw-rw-r-- 1 root root 328 May 31 09:02 package.json
drwxrwxr-x 2 root root 4096 May 15 11:27 services
drwxrwxr-x 2 root root 4096 Jun 14 14:56 settings
drwxrwxr-x 2 root root 4096 May 23 09:35 utilities
just forget this!!I've tagged the same container as new version,pushed and its works!
Answered by Grigor:
I've tagged the same container as new version,pushed and its works!

webpack unable to resolve node module in docker image

#Dockerfile
FROM node:alpine
RUN mkdir /morty
ADD . /morty/
WORKDIR /morty/
RUN yarn cache clean && yarn install
RUN ls node_modules | grep autosuggest
RUN find /morty/node_modules/react-autosuggest -ls
CMD npm run dev
This builds as expected, but as soon as I request a page from the dev server, I get an error
ERROR in ./src/components/molecules/AutoSuggest/index.js
web_1 | Module not found: Error: Can't resolve 'react-autosuggest' in '/morty/src/components/molecules/AutoSuggest'
web_1 | #
which would suggest to me that for some reason, the react-autosuggest module was not installed; however, the output of step 6 & 7 in my Dockerfile seems to invalidate that hypothesis.
Step 6/7 : RUN ls node_modules | grep autosuggest
---> Running in 0c87c4318a6f
react-autosuggest
Step 7/9 : RUN find /morty/node_modules/react-autosuggest -ls
---> Running in 498c6b9080c7
12042711 4 drwxr-xr-x 3 root root 4096 Mar 6 16:40 /morty/node_modules/react-autosuggest
12042729 4 drwxr-xr-x 3 root root 4096 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist
521128 4 -rw-r--r-- 1 root root 1735 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/theme.js
12042731 4 drwxr-xr-x 2 root root 4096 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/standalone
521127 36 -rw-r--r-- 1 root root 33193 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/standalone/autosuggest.min.js
521126 112 -rw-r--r-- 1 root root 113248 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/standalone/autosuggest.js
521123 28 -rw-r--r-- 1 root root 27217 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/Autosuggest.js
521124 4 -rw-r--r-- 1 root root 65 Mar 6 16:40 /morty/node_modules/react-autosuggest/dist/index.js
521121 24 -rw-r--r-- 1 root root 24423 Mar 6 16:40 /morty/node_modules/react-autosuggest/README.md
521129 8 -rw-r--r-- 1 root root 4195 Mar 6 16:40 /morty/node_modules/react-autosuggest/package.json
521120 4 -rw-r--r-- 1 root root 1088 Mar 6 16:40 /morty/node_modules/react-autosuggest/LICENSE
package.json does contain the entry "react-autosuggest": "^9.3.4", in dependencies and the app performs as expected in its un-containerized form.
also, possibly relevant is that the base config for this project came from
the Arc project
I also faced this issue while trying to build my npm project using a container which had WORKDIR as a mounted volume. I resolved this issue by removing the mounted volume by name.
docker volume ls to list the volumes
DRIVER VOLUME NAME
local myproject_named_volume
docker volume rm -f myproject_named_volume to remove the volume
Hope this helps.

Resources