Installing bundler within Jenkins Docker image - ruby

Is it possible to install Ruby within a docker image, specifically Jenkins?
I can see from the docs that you can attach to a container or use docker exec -i -t 4e2bf4128e3e bash. This will log me in as jenkins#4e2bf4128e3e.
But if I try and install anything
apt-get install ruby 2.0.0 # Yes will install rvm, this is just an example
I get
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
And when I try
sudo apt-get install ruby 2.0.0
Then I get sudo command not found.

The problem you have is that, as you can see here, the jenkins docker images executes commands as the jenkins user which is forbidden to use apt.
On https://hub.docker.com/_/jenkins/ you have some documentation, namely the "Installing more tools" section which advise you to do this:
FROM jenkins
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y ruby make more-thing-here
USER jenkins # drop back to the regular jenkins user - good practice

You could create your own image, that layers those two images
Dockerfile
FROM jenkins
FROM ruby
...
Now you have a docker container of your own that has both ruby AND jenkins.

Related

Gitlab-Runner doesn't have sudo access on OSX

I have installed gitlab-runner on a new OSX device. My runner is register and launch correctly.
But when i start a job, I have this error
sudo gem install fastlane
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
What can I do avoid this error and let gitlab-runner have sudo access to execute anything ?
Most probably you granted the sudo permission to your gitlab-runner user, but you did not remove the password restriction for sudo for the gitlab-runner user. Here you can find how to do it.
However I would not recommend using sudo. You could use Bundler and then install fastlane with bundler for this project and not globally.
gem install bundler -> you will get a Gemfile for the current directory (root of the project)
put gem "fastlane" into the Gemfile
install it with bundle install (you can run this command with your gitlab-runner user in jobs)
For running fastlane lanes use: bundle exec fastlane <name_of_the_lane>.

AWS EC2 : sudo: apt-get: command not found error

I have installed Amazon Linux 2 AMI (HVM), SSD Volume Type second number of os in list (AWS console) in my instance.
It connect to putty successfully.
Now I want to install node in my server.
For that I go to /var folder. Then I run this command.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
And then I got error this.
## Populating apt-get cache...
+ apt-get update
bash: apt-get: command not found
Error executing command, exiting
To fixed this I have fire follow commands.
1) apt-get update
2) sudo apt-get update
3) yum update
4) sudo yum update
Still I have same issue. Anyone can help me.
Install node version manager (nvm) by typing the following at the command line.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
Use nvm to install Node.js because nvm can install multiple versions of Node.js and allow you to switch between them.
Activate nvm by typing the following at the command line.
. ~/.nvm/nvm.sh
Use nvm to install the version of Node.js you intend to use by typing the following at the command line.
nvm install 4.4.5
Installing Node.js also installs the Node Package Manager (npm) so you can install additional modules as needed.
Test that Node.js is installed and running correctly by typing the following at the command line.
node -e "console.log('Running Node.js ' + process.version)"
This should display the following message that confirms the installed version of Node.js running.
Running Node.js v4.4.5
More Info : https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

extend jenkins image to install maven

I'm using the jenkins/jenkins:lts image at the moment. It runs fine and does everything I want to expect one thing. I want it to run Maven goals in the build steps. The problem is that there is not maven installed in the jenkins container environment.
So I want to extend the mentioned image to run an apt-get install maven.
My solution:
FROM "jenkins/jenkins:lts
USER root
RUN /bin/bash -c "apt-get install maven"
Will this be enough? I assume that all RUN and ENTRYPOINT steps of the jenkins image will run by itself and I do not need to re-execute them in my Dockerfile right?
According to the documentation, this would be in your dockerfile
FROM jenkins/jenkins:lts
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y maven
# drop back to the regular jenkins user - good practice
USER jenkins
Assuming your docker file is in your current directory this is how you would build the image and install in your local docker repo
docker build -t jenkins-maven .
For more information
https://github.com/jenkinsci/docker
After installing maven this way, the mvn version will probably be older than what you need. When I ran this, it was Apache Maven 3.3.9
you need to update package cache before install, and don't miss -y for apt-get install.
FROM jenkins/jenkins:lts
RUN apt-get update && apt-get install -y maven
Here is the simplest way to install maven into docker:
Connect to docker with root privilages
sudo docker exec -u root -t -i [container-id] bash
update and install maven
apt-get update & apt-get install
That's it.
Works file for me
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y maven

Could not execute command lessc' while running odoo (any version) in eclipse mac

After a thorough analysis of 'Could not execute command lessc' i've successfully ran odoo (any version) on my command line with python virtual env. Am doing this to run odoo in command line
$ . {PATH_TO_VIRTUAL_ENV}/bin/activate (Running the script in the current shell)
$ cd {PATH_TO_ODOO_SOURCE}
$ ./odoo.py -c setup.cfg
And the above runs with proper UI.
Now when trying to run the same from eclipse throws me 'Could not execute command lessc'. I did the below to run code from eclipse
Installed pydev plugin in eclipse Mars
Configured Python interpreter (Given the virtual env python path here. i.e {PATH_TO_VIRTUAL_ENV}/bin/python)
Setup odoo source
Specified the new python interpreter on the project properties -> python interpretor
Created a new Run Configuration to run the source with the custom setup file and with the new interpretor
Kindly throw me light on places where i miss. Also i've gone through links on setting up python virtual env in eclipse. They all say the same thing still this lessc dependency is somehow not linked. Please comment if you require more info to identify the error. Thanks for your help! :)
FYI am using mac.
Update
For Shikhar (based on his answer)
This problem is related to your bad configuration of Nodejs and less on system.
Use commands below to resolve this -
wget -qO- https://deb.nodesource.com/setup | sudo bash -
then
brew install node
and finally
sudo npm install -g less less-plugin-clean-css
This will resolve the lessc command issue.
try this
sudo apt-get install node-clean-css
sudo apt-get install node-less
The solution:
sudo apt-get install node-clean-css
sudo apt-get install node-less
may work for Global system installation but if you are working within a virtualenv you may try this.
If somebody had the issue inside PyCharm wich was my case and nothing else works...
I leave my solution here:
First: I tried to check if node and npm exist inside my virtualenv: node -v and npm -v, not any of them... Second: I was using virtualenv, also when I ask inside my virtualenv with: which lessc . I didn't receive any response neither, so... I keep googling and found this post: How to install lessc and nodejs in a Python virtualenv?
In any case this was what I did on my virtualenv and the problem was solved:
MYVIRTUALENV/bin/activate # switch to my Python virtualenv first
pip3.7 install nodeenv # install nodeenv nodeenv was installed, in case you are using python 2.x use pip instead pip3
nodeenv --python-virtualenv # Use current python virtualenv
npm install -g less # install lessc in the virtualenv
npm install -g less-plugin-clean-css # also install this less-plugin...
then if I check with node -v and npm -v I get a proper response...
also get good response on: which lessc
After that no more nightmare with lessc execution in pycharm

Errors while trying to use pip on OpenShift

I am getting the following error both when using git and when logging in via rhc and try to install the requirements file:
The directory '/var/lib/openshift/***/.cache/pip/http' or its parent
directory is not owned by the current user and the cache has been disabled.
Please check the permissions and owner of that directory.
If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
I am not trying to install with sudo.
What I am trying to do is:
Log into via rhc and and ssh: rhc ssh 'app'
activate venv: source $OPENSHIFT_PYTHON_DIR/virtenv/bin/activate
pip install -r "$OPENSHIFT_REPO_DIR" requirements.txt
Note that $OPENSHIFT_PYTHON_DIR and $OPENSHIFT_REPO_DIR are the environment variables given by OpenShift to access the relevant folders.
Any ideas? I am on a Python 2.7 cartridge.
Openshift will automatically install your dependencies based on a requirements.txt file. So you shouldn't ssh into your app and do that yourself.
You can find more information about it on the developer center pages. [1]

Resources