NPM & Docker Build - gitlab-ci

I want to "build" my npm build and create a docker image with it. That means I need a docker image that is able to a) run npm and b) run docker.
Currently I struggle in finding / creating such a docker image. How can I solve my problem?
Thanks!
Edit:
I managed to have a combined container, but my build is not able to find a running docker instance:
Post http:///var/run/docker.sock/v1.20/build?cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=registry.gitlab.com%2Ftss-repocar%2Fapp&ulimits=null: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?
Post http:///var/run/docker.sock/v1.20/images/registry.gitlab.com/tss-repocar/app/push?tag=: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

Use Packer. You run commands in Packer to do all of your NPM setup, and it will spit out a Docker container.
Here is packer
https://www.packer.io/docs/
And then I found this
https://www.npmjs.com/package/node-packer

To build docker images your build container must have access to /var/run/docker.sock (or you have to use Docker in Docker).
Assuming you have your gitlab-ci-multi-runner in a Docker Container itself, change /etc/gitlab-runner/config.toml to look like this:
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

Related

Using docker to run a react native app, using expo

I have a small react native app, and I'm trying to run it using docker. I believe I know what my problem is, but I really can't solve it. My Dockerfile is as such:
FROM node:12
WORKDIR /client
COPY package*.json ./
RUN yarn install
RUN yarn global add expo-cli
COPY . .
ENV PORT=8080
EXPOSE 8080
CMD ["yarn", "start"]
I built my image, and then tried to run it using: docker run -p 19002:8080 53abf08beb39. Everything looks ok, expo tells me it is running in localhost:19002, and that the app is running in localhost:19000. Despite this, when i try to access these ports, I only see a "this site can't be reached" page. I was told this was because expo is exposing the port, but since it's running in docker, it can only be accessed from inside the container, so I need a way to expose this out of the container to be able to run it on my laptop. How can I achieve this?
Also, if anyone knows how should I create a docker-compose file to run all this, it would be great.

How we could dockerizing a Proton-Native App and see the GUI?

I'm trying to dockerize a Proton-Native App, buy i'am not able of see the basic proyect
This is my Dockerfile
FROM node:13
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
RUN npm install
COPY . ./
RUN npx proton-native-cli init .
CMD ["npm", "start"]
Then I run
docker build -t sample:dev .
and
docker run sample:dev
Assuming that is posible see the GUI, not only access the docker image. What would be the correct way to complete the configuration?
Thanks for read! :)
This idea, dockerizing a Proton-Native App for see the gui, is not a simple task, requires "a lot of extra work to get the display to show up at all (including installing extra host software on non-Linux hosts) and even more work to get access to user preferences and data files", like #DavidMaze explains

How to resolve clipboard error while deploying vuejs app on ubuntu server

I am deploying a vuejs app on my server.we have EC2 instance with ubuntu 16.04,As of now I am just deploying my test project but when I go running serve command like sudo serve -s dist but it is throwing an error which is: ERROR: Cannot copy to clipboard: Command failed: xsel --clipboard --input
xsel: Can't open display: (null)
: Inappropriate ioctl for device
I don't know this error is caused by ubuntu or vuejs please help me solve it.
I have followed these cammands so far.
First installed vue cli using
npm install -g #vue/cli
Then created a hello world app using
vue create helloWorld
Now run serve command
npm run serve
It was showing me a message like:
App running at:
- Local: http://localhost:8081/
- Network: http://172.31.16.66:8081/
Now i have created a build to run an app on the production server
npm run build
So my build was created successfully
i run command to run the app on the live server
serve -s dist
And it is throwing an error which is not solving by me so far
WARNING: Checking for updates failed (use--debugto see full error)
ERROR: Cannot copy to clipboard: Command failed: xsel --clipboard --input
xsel: Can't open display: (null)
: Inappropriate ioctl for device
I am also attaching screenshot below.
As you can see, there is an X11 dependency with the serve module - which means you need an xserver(display) for it to work.
Alternatively, (highly recommended) you could use a high performance HTTP server like nginx, apache etc. instead.
All you need is to copy your dist folder to your instance, and point your virtual server block to the dist dir, and restart your HTTP server - BAM! you're up and running.
Cheers!
I had the same issue and I solved it by adding "-n" option to serve.
"-n, --no-clipboard Do not copy the local address to the clipboard"

npm 3.10.10 install socket hang up error

I am using Node 6.10.1 and npm 3.10.10 on a Dell XPS 15 running Ubuntu 16.04 with Kernel 4.13.0.0-36-generic.
I am behind a corporate proxy which is configured through cntlm.
When I run an npm install -d on a project It works from a short time, and after a while I get Error: socket hang up.
I have found numerous questions about my problem but no solution seemed to work.
Here is an extract of a npm config list :
; cli configs
user-agent = "npm/3.10.10 node/v6.10.1 linux x64"
; userconfig /home/msb/.npmrc
https-proxy = "http://localhost:3128/"
registry = "http://urlTocorporateRegistryWhichWorksOnOtherComputers"
strict-ssl = false
; node bin location = /home/msb/.nvm/versions/node/v6.10.1/bin/node
; cwd = /home/msb
; HOME = /home/msb
; "npm config ls -l" to show all defaults.
I cannot change the registry since we are using some internal modules, and I have to keep the current versions of node/npm.
I have already tried :
Using the proxy directly in npm config rather than through cntlm
Limiting my upload/download capabilities with trickle through the command trickle -s -d 100 -u 100 npm install -d
Another indication : It works on Windows, and I have a collegue running Ubuntu 17.04 on a slower pc and it works for him. We think my machine might be a bit too brutal when requesting the registry. Does anyone know a way to slow npm requests ?
It used to work through yarn but some new developments have forced me to go back to npm.
Has anyone encountered and corrected this problem ?
Thanks for your help.
I experimented the same problem, with no apparent reason, on Ubuntu 18.04.
I finally used docker with bind mounts to solve it. The steps are the following:
Create a dockerfile with the following elements (you can also directly run with the used image if you don't need to configure a proxy like me)
FROM node:6.10.1
ENV HTTPS_PROXY "http://yourproxy:yourport/"
# Different RUN commands to configure npm and git corporate proxy
WORKDIR /home/root/
Build the image (from the dockerfile's folder): docker image build -f npm-installer/Dockerfile -t custom-npm-installer .
Go inside the project folder where you would normally run npm install
Run the following command to run the container interactively: docker container run -it --network host -v </host/path/to/pj>:/home/root/pj-to-install --name custom-npm-installer custom-npm-installer bash
You can now run the npm install command from the container. Careful however, you'll then need to use chmod on the node_modules folder recursively since the container uses root by default.
Another thing, if you're using node-sass, it is most of the time compiled on the fly when npm installing, and matches your OS current version/architecture. So if your linux distribution is not exactly the same than the container's you might need to recompile node-sass on your host after running npm install on the container. No worries though, node-sass will give you the command to run the moment you launch your application.

How to run integration test inside a docker container in drone pipeline

I have a docker image built up for mongodb test. You can be found from zhaoyi0113/mongo-uat. When start a docker container from this image, it will create a few mongodb instances which will take a few minutes to startup. Now I want to run my integration test cases inside this container by drone CI. Below is my .drone.yml file:
pipeline:
build:
image: node:latest
commands:
- npm install
- npm test
- npm run eslint
integration:
image: zhaoyi0113/mongo-uat
commands:
- npm install
- npm run integration
There are two steps in this pipeline, the first is to run unit test in a nodejs project. The second one integration is used to run integration test cases in the mongodb docker image.
when I run drone exec it will get an error failed to connect to mongo instance. I think that because the mongodb instance needs a few minutes to startup. The commands npm install and npm run integration should be run after the mongodb instance launched. How can I delay the build commands?
EDIT1
The image zhaoyi0113/mongo-uat has mongodb environment. It will create a few mongodb instances. I can run this command docker run -d zhaoyi0113/mongo-uat to launch this container after that I can attach to this container to see the mongodb instances. I am not sure how drone launch the docker container.
The recommended approach to integration testing is to place your service containers in the service section of the Yaml [1][2]
Therefore in order to start a Mongo service container I would create the below Yaml file. The Mongo service will start on the default port at 127.0.0.1 and be accessible from your pipeline containers.
pipeline:
test:
image: node
commands:
- npm install
- npm run test
integration:
image: node
commands:
- npm run integration
services:
mongo:
image: mongo:3.0
This is the recommended approach for testing services like MySQL, Postgres, Mongo and more.
[1] http://readme.drone.io/usage/getting-started/#services
[2] http://readme.drone.io/usage/services-guide/
As a short addendum to Brads answer: While the mongo service will run on 127.0.0.1 on the drone host machine - it will not be possible to reach the service from this IP within the node app. To access the service you would reference its service name (here: mongo).