wercker for sails +mongo db - mongodb

i'm try to use wercker,
but i don't know my testing can't connect into my mongodb.
i'm using sails + sails mongo, and when npm test...i'm always get error can connect into mongo db, this is my wercker.yml :
box: nodesource/trusty:0.12.7
services:
- id: mongo:2.6
# Build definition
build:
# The steps that will be executed on build
steps:
- script:
name: set NODE_ENV
code: export NODE_ENV=development
# A step that executes `npm install` command
- npm-install
# A step that executes `npm test` command
- npm-test
# A custom script step, name value is used in the UI
# and the code value contains the command that get executed
- script:
name: echo nodejs information
code: |
echo "node version $(node -v) running"
echo "npm version $(npm -v) running"
this is my error message :
warn: `sails.config.express` is deprecated; use `sails.config.http` instead.
Express midleware for passport
error: A hook (`orm`) failed to load!
1) "before all" hook
2) "after all" hook
0 passing (2s)
2 failing
1) "before all" hook:
Uncaught Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?
Error details:
{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }
at net.js:459:14
2) "after all" hook:
Uncaught Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?
Error details:
{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }
at net.js:459:14

While out of the box, MongoDB has no authentication so you just have to provide to sails the right host and port.
Define a new connection in your sails app in config/connection.js:
mongodbTestingServer: {
adapter: 'sails-mongo',
host: process.env.MONGO_PORT_27017_TCP_ADDR,
port: process.env.MONGO_PORT_27017_TCP_PORT
},
Concerning MONGO_PORT_27017_TCP_ADDR and MONGO_PORT_27017_TCP_PORT, these 2 environment variable are created by Wercker when you declared a mongo service. Like That, you will be able to connected your application to your database with the right host and port.
Add a new environment in your sails sails app in config/env/testing.js. It will be used by Wercker :
module.exports = {
models: {
connection: 'mongodbTestingServer'
}
};
In your wercker file wercker.yml. I recommend you to use the ewok stack (based on Docker), you can active it in the settings of your application. Here is some useful informations concerning migration to Ewok stack. My example use a box based on a Docker image.
# use the latest official stable node image hosted on DockerHub
box: node
# use the mongo (v2.6) image hosted on DockerHub
services:
- id: mongo:2.6
# Build definition
build:
steps:
# Print node and npm version
- script:
name: echo nodejs information
code: |
echo "node version $(node -v) running"
echo "npm version $(npm -v) running"
- script:
name: set NODE_ENV
code: |
export NODE_ENV=testing
# install npm dependencies of your project
- npm-install
# run tests
- npm-test
To see all environment variables in your Wercker build, add this line :
- script:
name: show all environment variables
code: |
env
It should work.

Related

Unable to view the contents of file in ansible managed nodes

I'm trying to view the contents of a file from managed node and control node, here I see the syntax works fine for localhost (172.17.254.200) but not for the remote hosts. Below is the task I have written using lookup / query plugin, can you please suggest the fix:
---
- name: Report Test
hosts: all
roles:
- patching
tasks:
- name: Display the Pre and Post check Differences
debug:
msg: "{{ query('file', '/tmp/check/{{ inventory_hostname }}_Comparison') }}"
Below is the output
TASK [patching : Display the Pre and Post check Differences] ***********************************************************************************************************
ok: [172.17.254.200] =>
msg:
- |-
free_m - YES
sysctl_all - YES
uptime - YES
[WARNING]: Unable to find '/tmp/check/172.17.254.207_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.207]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.207_Comparison'
[WARNING]: Unable to find '/tmp/check/172.17.254.208_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.208]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.208_Comparison'
Lookups are executed on Ansible controller (as pointed out by #Vladimir Botka). If you just want to view the contents of a file on remote hosts, you can cat the file through ansible and debug the stdout_lines.
- command: "cat /tmp/check/{{ inventory_hostname }}_Comparison"
register: file_cat
changed_when: false
- debug:
var: file_cat.stdout_lines
lookup and query "execute and are evaluated on the Ansible control machine."
Use slurp. Quoting:
This module returns an ‘in memory’ base64 encoded version of the file, take into account that this will require at least twice the RAM as the original file size.
For larger files use fetch. Quoting:
It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.

How to use Kubectl commands to Acess a Rancher Cluster through Ansible

I am currently developing a project where I need to get the pod names of a Kubernetes Cluster running on Rancher using Ansible. The main thing here is that I have a couple of problems that are preventing me from advance.
I am currently executing a playbook to try to retrieve this information, instead of running a CLI command, because I want to manipulate those Rancher machines later one (e.g. install an rpm file).
Here is the playbook that I am executing tot try to retrieve the pods' names from Rancher:
---
- hosts: localhost
connection: local
remote_user: root
roles:
- role: ansible.kubernetes-modules
- role: hello-world
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
collections:
- community.kubernetes
tasks:
-
name: Gather openShift Dependencies
python_requirements_facts:
dependencies:
- openshift
-
name: Get the pods in the specific namespace
k8s_info:
kubeconfig: '/etc/ansible/RCCloudConfig'
kind: Pod
namespace: redmine
register: pod_list
-
name: Print pod names
debug:
msg: "pod_list: {{ pod_list | json_query('resources[*].status.podIP') }} "
- set_fact:
pod_names: "{{pod_list|json_query('resources[*].metadata.name')}}"
The problem is that I am getting a Kubernetes module error each time I am trying to run the playbook:
ERROR! the role 'ansible.kubernetes-modules' was not found in community.kubernetes:ansible .legacy:/etc/ansible/roles:/home/jcp/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/ roles:/etc/ansible
The error appears to be in '/etc/ansible/GetKubectlPods': line 7, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- role: ansible.kubernetes-modules
^ here
If I remove that line on the code, Where I try to retrieve that role, I still get a similar error:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'kubernetes'
fatal: [localhost]: FAILED! => {"changed": false, "error": "No module named 'kubernetes'", "msg": "Failed to import the required Python library (openshift) on localhost.localdomain's Python /usr/bin/python3.6. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}
I have already tried to install ansible-galaxy kubernetes module on the machine and openshift.
Not sure what I am doing wrong since there are so many possibilities for what could be going wrong here.
Ansible Version Output:
ansible 2.9.9
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/jcp/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jcp/.local/lib/python3.6/site-packages/ansible
executable location = /home/jcp/.local/bin/ansible
python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]
I've debugged my python_required_info output from openshift dependencies and this is what I have:
ok: [localhost] => {
"openshift_dependencies": {
"changed": false,
"failed": false,
"mismatched": {},
"not_found": [],
"python": "/usr/bin/python3.6",
"python_system_path": [
"/tmp/ansible_python_requirements_info_payload_5_kb4a7s/ansible_python_requirements_info_payloa d.zip",
"/usr/lib64/python36.zip",
"/usr/lib64/python3.6",
"/usr/lib64/python3.6/lib-dynload",
"/home/jcp/.local/lib/python3.6/site-packages",
"/usr/local/lib/python3.6/site-packages",
"/usr/local/lib/python3.6/site-packages/openshift-0.10.0.dev1-py3.6.egg",
"/usr/lib64/python3.6/site-packages",
"/usr/lib/python3.6/site-packages"
],
"python_version": "3.6.8 (default, Nov 21 2019, 19:31:34) \n[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]" ,
"valid": {
"openshift": {
"desired": null,
"installed": "0.10.0.dev1"
}
}
}
}
Thanks for your help in advance!
Edit: The below answer was given for OP's specific Ansible version (i.e. 2.9.9) and is still valid if you still use it. Since version 2.10, you also need to install the relevant ansible collection if not already present
ansible-galaxy collection install kubernetes.core
See the latest module documentation for more information
In Ansible 2.9.9, you're not supposed to do anything special to use the module except installing the needed python dependencies. See the module documentation for your Ansible version
remove the line - role: ansible.kubernetes-modules, unless it is a module of yours in which case you have to tell us more because this is not a correct declaration.
remove the collection declaration
Add the following task somewhere before using the module:
- name: Make sure python deps are installed
pip:
name: openshift
Your actual python_requirement_facts task is doing nothing else than reporting the dependency is not found. Register the result and debug it to see for yourself.
Now use the k8s_info module normally.

Cloud Code for VisualStudio Code Errors on Cloud Code: Deploy

I've been trying to setup Cloud Code with VSCode and I've been running in to problems when starting the deploy process with Cloud Code: Deploy.
I've tried deploying the samples, python-hello-world-1 as well as the go-hello-world-1, to my kubernetes cluster on GKE but always end up getting errors when the deploy process starts package downloading:
Go Output
Running: skaffold run --enable-rpc -v info --rpc-http-port 49869 --filename skaffold.yaml --default-repo gcr.io/abx-lernende
starting gRPC server on port 50051
starting gRPC HTTP server on port 49869
Using kubectl context: gke_abx-lernende_europe-west4-a_joshu-test-cluster
Generating tags...
- go-hello-world -> gcr.io/abx-lernende/go-hello-world:latest
Checking cache...
- go-hello-world: Not found. Building
Building [go-hello-world]...
Sending build context to Docker daemon 57.86kB
Step 1/8 : FROM golang:1.13
---> 6586e3d10e96
Step 2/8 : RUN go get -u -v github.com/go-delve/delve/cmd/dlv
---> Running in b75ce8e5dae9
[91mgithub.com/go-delve/delve (download)
[0m[91m# cd .; git clone -- https://github.com/go-delve/delve /go/src/github.com/go-delve/delve
Cloning into '/go/src/github.com/go-delve/delve'...
fatal: unable to access 'https://github.com/go-delve/delve/': Failed to connect to github.com port 443: Connection refused
package github.com/go-delve/delve/cmd/dlv: exit status 128
[0mfailed to build: build failed: building [go-hello-world]: build artifact: unable to stream build output: The command '/bin/sh -c go get -u -v github.com/go-delve/delve/cmd/dlv' returned a non-zero code: 1
Exited with code 1.
Python Output
Running: skaffold run --enable-rpc -v info --rpc-http-port 50185 --filename
skaffold.yaml --default-repo gcr.io/abx-lernende
starting gRPC server on port 50051
starting gRPC HTTP server on port 50185
Skaffold &{Version:v1.3.1 ConfigVersion:skaffold/v2alpha3 GitVersion: GitCommit:6ba887a42438d1da578a005cf550e618fee6dfb8 GitTreeState:clean BuildDate:2020-01-31T19:55:18Z GoVersion:go1.13.4 Compiler:gc Platform:windows/amd64}
Using kubectl context: gke_abx-lernende_europe-west4-a_joshu-test-cluster
Generating tags...
- python-hello-world -> Tags generated in 0s
gcr.io/abx-lernende/python-hello-world:latest
Checking cache...
- python-hello-world: Cache check complete in 6.0001ms
Not found. Building
Building [python-hello-world]...
Sending build context to Docker daemon 4.608kB
Step 1/7 : FROM python:3.8
---> efdecc2e377a
Step 2/7 : WORKDIR /app
---> Using cache
---> a131b81cad66
Step 3/7 : COPY requirements.txt .
---> Using cache
---> 4625ef1862bd
Step 4/7 : RUN pip install --trusted-host pypi.python.org -r requirements.txt
---> Running in 4da23a158ae3
[91mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17ba9c9d60>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/flask/
Im assuming this is due to me being behind a corporate proxy. As counter measures I have explicitly configured VSCode, Git, pip, go and google cloud sdk all to use said proxy. On top of that I set the Windows ENV variables for the proxy. sadly without success.
Thanks!
You can configure docker to pass through proxy information into the containers by adding something like the following to your ~/.docker/config.json:
{
"proxies": {
"default": {
"httpProxy": "http://192.168.1.12:3128",
"httpsProxy": "http://192.168.1.12:3128"
}
}
}
Docker will set the HTTP_PROXY/HTTPS_PROXY environment variables within the container which is picked up by many tools.

docker-compose gives error "cant access the file because it is being used by another process". Not same with docker vanilla

Im running my docker container with
Docker run kalle:anka -p 8888:80 -p 5045:5045 -p 5672:5672
without any problem. But when I try to achieve the same thing with docker-compose I get the error
ERROR: for myapp.api_1 Cannot start service myapp.api: failed to
create endpoint myapp.api_1 on network nat: hnsCall failed in Win32:
The process cannot access the file because it is being used by another
process. (0x20)
The error above seems to have something to do with the port mapping. (When I remove those I get passed that problem.)
... I'll keep this question short, please ask if yo miss any details
Relevant part of my docker-compose.yaml
> version: '3.4'
>
> services: myapp.api:
> image: ${DOCKER_REGISTRY-}myappapi
> ports:
> - "8888:80"
> - "5045:5045"
> - "5672:5672"

Running Meteor on localhost fails with RangeError: port should be >= 0 and < 65536: NaN

I am running a project on localhost using node and Mongodb, but it fails with an error as soon as I try to create a collection on the database.
I am building the project with this script:
cd ~/Meteor/daily-reminder
meteor build ~/build-output-daily-reminder --server=http://localhost
cd ~/build-output-daily-reminder
tar -xvzf daily-reminder.tar.gz
rm daily-reminder.tar.gz
cd ~/build-output-daily-reminder/bundle
(cd programs/server && npm install)
export MONGO_URL='mongodb://username:password#http://localhost:27017/daily-reminder'
export ROOT_URL='http://localhost/'
export PORT='3000'
echo "now run node main.js"
node main.js
(I use my actual mongodb username and password in the real code).
The project builds fine, but node won't run. It generates this error:
now run node main.js
/home/shelagh/build-output-daily-reminder/bundle/programs/server/node_modules/fibers/future.js:245
throw(ex);
^
RangeError: port should be >= 0 and < 65536: NaN
at Socket.connect (net.js:917:13)
at Object.exports.connect.exports.createConnection (net.js:92:35)
at [object Object].Connection.start (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:173:29)
at _connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:211:16)
at [object Object].ConnectionPool.start (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:231:3)
at Server.connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/server.js:708:18)
at Db.open (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/db.js:281:23)
at connectFunction (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:275:67)
at Function.MongoClient.connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/mongo_client.js:345:5)
at Function.Db.connect (/home/shelagh/build-output-daily-reminder/bundle/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/db.js:2094:23)
If I use a newly-created Meteor project then node runs ok. But it fails as soon as I add this line to start of my js file:
Tasks = new Mongo.Collection("tasks");
It seems like there is some problem as soon as the server tries to communicate with the database. But I can't see anything wrong with my MONGO_URL: port is specified as 27017. From the error, it looks like the port isn't even being passed in.
I am using node v0.12.7 and MongoDB shell version: 2.4.9. I have started mongo by typing 'mongo' in a separate terminal window.
Your MONGO_URL is wrong, it redefines the protocol where you specify the host.
Change
export MONGO_URL='mongodb://username:password#http://localhost:27017/daily-reminder'
to
export MONGO_URL='mongodb://username:password#localhost:27017/daily-reminder'