Executing tests against mongo DB on the CI (circleCI) fails even though they pass locally.
Am installing mongo db and connect the app to the db, here is my circle.yml file
machine:
node:
version: 7.2.1
dependencies:
override:
- sudo apt-get purge mongodb-org*
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
- echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
- sudo apt-get update
- sudo apt-get install -y mongodb-org
- sudo service mongod restart
- npm install
test:
override:
- npm run test
The DataBase URL: mongodb://mongodb:27017/db-name
CircleCI already provides MongoDB 3.0.7 by default
Edit your circle.yml for this:
machine:
node:
version: 7.2.1
dependencies:
override:
- npm install
test:
override:
- npm run test
More information
Related
I have deployed my Angular app using AWS CodeBuild, it was working fine until today morning. All of a sudden the build is failing & throwing this error. I think it has something to do with node.js repo, but not sure how to fix it.
I've also tried these links:
https://deb.nodesource.com/setup_14.x | bash -
http://deb.nodesource.com/setup_12.x | bash -
https://deb.nodesource.com/setup_lts.x | bash -
Also here is my build spec:
phases:
install:
commands:
- echo installing nodejs...
- curl -sL https://deb.nodesource.com/setup_12.x | bash -
- apt-get install -y nodejs
- echo installing yarn...
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- apt install --no-install-recommends yarn
pre_build:
commands:
- echo installing dependencies...
- npm i -g #angular/cli
- npm install
build:
commands:
# - echo testing...
# - echo building...
- ng build --prod
artifacts:
files:
- "**/*"
discard-paths: no
base-directory: 'dist'
My team has deployed an Angular application in AWS. We used json-server for making mock service and database for the application. But, we can't find a way to run json-server in aws. Can anyone help us in this regard?
This is the pipeline code-
version: 0.0
os: linux
version: 0.2
env:
variables:
S3_BUCKET: "initial-codedeploy-bucket-us-east-1-jready"
APP_NAME: "shopping-city"
BUILD_ENV : "prod"
phases:
install:
commands:
# Download and Install NodeJS 10.0
- curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
- sudo apt-get install -y nodejs
- echo Installing source NPM dependencies...
# Install http drivers for node
- sudo apt-get update -y
- sudo apt-get install -y apt-transport-https
# Install Yarn Package Manager (Replace the commands below if you using NPM).
# - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
# - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -y
- sudo apt-get install -y npm
# Install Angular CLI, If you are not using Angular 6, install angular/cli#1.7.0 or lower, confirm by running ng -v inside your project folder
- npm global add #angular/cli#6.0.8
# Install node dependancies.
- npm install
build:
commands:
# Builds Angular application. You can also build using custom environment here like mock or staging
- echo Build started on `date`
- ng build --${BUILD_ENV}
post_build:
commands:
# Clear S3 bucket.
- aws s3 rm s3://${S3_BUCKET} --recursive
- echo S3 bucket is cleared.
# Copy dist folder to S3 bucket, As of Angular 6, builds are stored inside an app folder in distribution and not at the root of the dist folder
- aws s3 cp dist s3://${S3_BUCKET}/${APP_NAME} --recursive
- echo Build completed on `date`
artifacts:
files:
- '/'
discard-paths: yes
base-directory: 'dist*'
If you want to run json-server on the AWS EÇ2, you need to run the following command:
nohup json-server --watch data/store.json --port
Then you can use curl to verify that the json-server is up and can respond to the request correctly.
If you want to use a port lower than 1024, run the command using sudo.
I can't call the api in the public network, maybe the issue of security group or some other permission isn't set properly. But I wish this can help.
In my Ubuntu machine, I am attempting to update my version of Node. I run curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
then I run sudo apt-get install -y nodejs
After this, my version of node remains unchanged:
ubuntu:~$ node -v
v6.10.3
use nvm, a version manager for node
https://github.com/creationix/nvm
To download node you install nvm and type nvm install <version>
This will download both node and npm
To change which node version you want to use you type nvm use <version>
For more detail check out the repo ^^
Running this worked for me finally.
Uninstall:
sudo apt-get purge nodejs
sudo apt-get autoremove
nvm deactivate
nvm uninstall node_version
(Source)
Install the New Version:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
If there are errors here, run these 2:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
wget -qO - https://raw.githubusercontent.com/yarnpkg/releases/gh-pages/debian/pubkey.gpg | sudo apt-key add -
Install New Version of Node:
wget -qO - https://raw.githubusercontent.com/yarnpkg/releases/gh-pages/debian/pubkey.gpg | sudo apt-key add -
I am using Gitlab-CI to build my Middleman application which also uses some node stuff for the front end (Gulp).
Here is my .gitlab-ci.yml (mostly copied from here):
image: ruby:2.3
cache:
paths:
- vendor
- node_modules
before_script:
- apt-get update -yqqq
- apt-get install -y npm
- ln -s /usr/bin/nodejs /usr/bin/node
- npm install
- bundle install --path vendor
test:
script:
- bundle exec middleman build
except:
- master
pages:
script:
- bundle exec middleman build
artifacts:
paths:
- public
only:
- master
Everything goes alright apart from the vital problem that it seems to be using an old version of node when it's npm installing. I'm getting lots of this:
npm WARN engine gulp-babel#7.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
Before finally failing on the "const path" SyntaxError.
I included a line to symlink the new nodejs with the old name (- ln -s /usr/bin/nodejs /usr/bin/node) but it seems to have no effect...?
Been banging my head for long enough, there's got to be someone out there who has made this work?
Debian Jessie ships with a fixed NodeJs major version, follow NodeSource instructions to install a specific version, this would fit in your gitlab-ci.yml like this (you probably need to install curl first since its not installed in the ruby:2.3 image):
before_script:
- apt-get update -q && apt-get -qqy install curl
- curl -sL https://deb.nodesource.com/setup_9.x | bash -
- apt-get update -q && apt-get -qqy install nodejs npm
- ln -s /usr/bin/nodejs /usr/bin/node
- npm install
- bundle install --path vendor
I am trying to create a container for my Node app. This app uses MongoDB to ensure some data persistence.
So I created this Dockerfile:
FROM ubuntu:latest
# --- Installing MongoDB
# Add 10gen official apt source to the sources list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list
# Hack for initctl not being available in Ubuntu
RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -s /bin/true /sbin/initctl
# Install MongoDB
RUN apt-get update
RUN apt-get install mongodb-10gen
# Create the MongoDB data directory
RUN mkdir -p /data/db
CMD ["usr/bin/mongod", "--smallfiles"]
# --- Installing Node.js
RUN apt-get update
RUN apt-get install -y python-software-properties python python-setuptools ruby rubygems
RUN add-apt-repository ppa:chris-lea/node.js
# Fixing broken dependencies ("nodejs : Depends: rlwrap but it is not installable"):
RUN echo "deb http://archive.ubuntu.com/ubuntu precise universe" >> /etc/apt/sources.list
RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y nodejs
# Removed unnecessary packages
RUN apt-get purge -y python-software-properties python python-setuptools ruby rubygems
RUN apt-get autoremove -y
# Clear package repository cache
RUN apt-get clean all
# --- Bundle app source
ADD . /src
# Install app dependencies
RUN cd /src; npm install
EXPOSE 8080
CMD ["node", "/src/start.js"]
Then I build and launch the whole thing through:
$ sudo docker build -t aldream/myApp
$ sudo docker run aldream/myApp
But the machine displays the following error:
[error] Error: failed to connect to [localhost:27017]
Any idea what I am doing wrong? Thanks!
Do you actually docker run aldream/myApp? In that case, with the Dockerfile that you provided, it should run MongODB, but not your app. Is there another CMD command, or another Dockerfile, or are you running docker run aldream/myApp <somethingelse>? In the latter case, it will override the CMD directive and MongoDB will not be started.
If you want to run multiple processes in a single container, you need a process manager (like e.g. Supervisor, god, monit) or start the processes in the background from a script; e.g.:
#!/bin/sh
mongod &
node myapp.js &
wait
Redefine your Dockerfile as follows;
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# ENTRYPOINT should not be used as it wont allow commands from run to be executed
# Define mountable directories.
VOLUME ["/data/db"]
# Expose ports.
# - 27017: process
# - 28017: http
# - 9191: web app
EXPOSE 27017 28017 9191
ENTRYPOINT ["/usr/bin/supervisord"]
supervisord.conf will contain the following;
[supervisord]
nodaemon=true
[program:mongod]
command=/usr/bin/mongod --smallfiles
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log
autorestart=true
[program:nodejs]
command=nodejs /opt/app/server/server.js