rvm: how do I really know it works - jruby

I installed rvm successfully and then installed ruby 1.8.7, ruby 1.9.2, and jruby 1.6.0. I currently use 1.8.7 for all of my rails projects, but I would like to experiment with 1.9.2, and I would also like to deploy jruby on those environments which are Java-specific.
So, I used rvm to select jruby and then I ran my current rails app on mongrel # localhost:3000. It worked great. Then, I ran a Linux process command and looked at the names of the processes running and I found ruby1.8. Does that mean that the Mongrel instance loaded ruby 1.8, but rails is using jruby-1.6.0? I don't know. Who can tell me how to determine that I really am running jruby?

type rvm | head -1
The above line should say that RVM is a function and confirms it was installed correctly.
Did you have trouble with instructions on entering the line
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
into your bash profile? That was a little unclear in my opinion. If it's that, you need to go to your home directory and make a .bash_profile (source: http://donovan.covblogs.com/archives/027838.html)
The above needs to be done before you can rly ensure ruby 1.9.2 is installed, else it'll be forgotten/lost once you close your shell.
Regarding the version of ruby you're using, make sure you're setting the default version. Below was taken from the Ruby on Rails 3 tutorial so feel free to change some naming conventions:
$ rvm --create 1.8.7-p174#rails2tutorial
$ rvm --create use 1.9.2#rails3tutorial
then
$ rvm --default use 1.9.2#rails3tutorial
Finall, type $ ruby -v and you should get ruby 1.9.2
Source: http://ruby.railstutorial.org/chapters/beginning#sec:install_ruby

I found this very helpful after starting to use rvm: i added this to the end of my .bashrc file: it puts the currently selected rvm and gemset at the start of the command prompt, in red: most of the following script is taken up with defining colors - you could delete the ones you don't need once you choose the colors you want.
##################################################
### RVM-specific command line (PS1): show current rvm and gemset
function __my_rvm_ruby_version {
local gemset=$(echo $GEM_HOME | awk -F'#' '{print $2}')
[ "$gemset" != "" ] && gemset="#$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
local full="$version$gemset"
[ "$full" != "" ] && echo "$full "
}
bash_prompt() {
local NONE="\[\033[0m\]" # unsets color to term's fg color
# regular colors
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
local G="\[\033[0;32m\]" # green
local Y="\[\033[0;33m\]" # yellow
local B="\[\033[0;34m\]" # blue
local M="\[\033[0;35m\]" # magenta
local C="\[\033[0;36m\]" # cyan
local W="\[\033[0;37m\]" # white
# emphasized (bolded) colors
local EMK="\[\033[1;30m\]"
local EMR="\[\033[1;31m\]"
local EMG="\[\033[1;32m\]"
local EMY="\[\033[1;33m\]"
local EMB="\[\033[1;34m\]"
local EMM="\[\033[1;35m\]"
local EMC="\[\033[1;36m\]"
local EMW="\[\033[1;37m\]"
# background colors
local BGK="\[\033[40m\]"
local BGR="\[\033[41m\]"
local BGG="\[\033[42m\]"
local BGY="\[\033[43m\]"
local BGB="\[\033[44m\]"
local BGM="\[\033[45m\]"
local BGC="\[\033[46m\]"
local BGW="\[\033[47m\]"
local UC=$W # user's color
[ $UID -eq "0" ] && UC=$R # root's color
PS1="$R\$(__my_rvm_ruby_version)$Y\h$W:$EMY\W${NONE}$ "
}
bash_prompt
unset bash_prompt
############## PS1 editing section ends

Related

Install MySQL on Windows Docker Image

Anyone had success adding MySQL to a Windows docker image? I tried two different ways of deploying MySQL to my image.
I tried using the msi from MySQL in non-interactive mode. Does not work at all in a container.
While Installing Mysql.msi through powershell getting below error
I tried extracting the zip to set things up manually using the mysqld commands does nothing at all. Literally nothing, the exectutables behave as if they just run and exit (no output, nothing):
https://github.com/Somesh-K/Automation-Mysql/blob/main/1.mysql_setup_v2.ps1
Something is very weird about all of this.
Yes, I know that there's a perfectly good MySQL docker linux container published by Oracle to Docker hub. This works. The problem is that running a Windows container and Linux container that need to interact creates a really unnecessary frustration for the user in terms of networking between the two.
Using a different back-end (like SQL server) for our application is not feasible and using .NET core instead of .NET framework is not feasible. To simplify, I'd like to just install MySQL on our windows based webserver docker image. This seems do-able using the two methods described in the links above, but as noted, it does not work and there's very odd behavior from the MySQL binaries when they are run in the container.
Here's an example of the odd behavior:
Install Docker Desktop for Windows
Download the Win32 install zips from MySQL and place in C:\mydata
https://dev.mysql.com/downloads/mysql/
Pull down the ASPNET image from Docker Hub, Run it, and Open up Powershell:
# docker pull mcr.microsoft.com/dotnet/framework/aspnet:4.8
# docker run --name testweb -v C:\mydata:C:\mydata:R -d mcr.microsoft.com/dotnet/framework/aspnet:4.8
# docker exec -it testweb powershell
C:\ > cd C:\mydata
C:\mydata\ > Expand-archive -path .\mysql-5.7.36-winx64.zip .
C:\mydata\ > cd \mysql-5.7.36-winx64\bin
C:\mydata\mysql-5.7.36-winx64\bin\ > .\mysql.exe -version
[zero output, acts like it's an empty executable]
Results
None of the executables/binaries in the extracted mysql bin directory on the container do anything at all. They behave as if someone wrote and executable that just exits. I thought I had a bad install zip so I extracted the same zip on my regular Windows 10 workstation. All of the binaries at least return errors or do something.
This is super odd. Any help would be appreciated.
Downloading this executable and putting it into my container seemed to do the trick:
https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe
Placed this on my container and started it
C:\vcredist.exe /Q
After doing this, the executables starting working:
C:\ > cmd.exe /C "C:\mysql\bin\mysqld" --initialize-insecure
C:\ > cmd.exe /C "C:\mysql\bin\mysqld" --install
C:\ > start-service mysql
C:\ > cmd.exe /C "C:\mysql\bin\mysql" -u root

Openshift 3 - Installing dependency from s2i/bin/assemble

I have the following file in the directory for my Openshift project which uses s2i to create a build image. This script attempts to install the cairo package.
.s2i/bin/assemble
#!/bin/bash
echo "Before assembling"
sudo yum install cairo
/usr/libexec/s2i/assemble
rc=$?
if [ $rc -eq 0 ]; then
echo "After successful assembling"
else
echo "After failed assembling"
fi
exit $rc
However, it fails with a "sudo": command not found.
This isn't a package that can be added in the requirements.txt file, and I need it for use with the WeasyPrint package. I've tried several different approaches, and this is the closest I've been able to get. (and this approach successfully builds despite the error)
Unfortunately you can't use root on open shift by default. You need to add your dependencies to DockerFile

How to install pcre on openshift

Any idea how to get hold of pcre (and pcre-devel) libraries on OpenShift / RHEL? I can't directly install packages via yum.
For context, I am trying to install my Yesod/haskell app on openshift, and running into trouble with this pcre dependency during "cabal install".
remote: Configuring pcre-light-0.4.0.3...
remote: cabal: Missing dependency on a foreign library:
remote: * Missing C library: pcre
remote: This problem can usually be solved by installing the system package that
remote: provides this library (you may need the "-dev" version). If the library is
remote: already installed but in a non-standard location then you can use the flags
remote: --extra-include-dirs= and --extra-lib-dirs= to specify where it is.
remote: cabal: Error: some packages failed to install:
Well, I did essentially answer the question as currently titled. The starting point is the put this file in the pre_build hook of your openshift application's git repo (i.e., .openshift/action_hooks/pre_build).
https://gist.github.com/abn/7480593
I did have to add one line, shown below with the comment #AC
#!/bin/bash
# script to install pcre on openshift
# this can be called in your action_hooks to setup pcre
# useful if you want to use regex in uwsgi, or nginx
#
# NOTE:
# If scaling, make sure you call this in your pre_start* hook,
# ${OPENSHIFT_DATA_DIR} is not copied over for a new gear
PCRE_VERSION="8.33"
PCRE_NAME="pcre-${PCRE_VERSION}"
PCRE_TARBALL=${PCRE_NAME}.tar.gz
PCRE_SRC="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/${PCRE_TARBALL}"
function setup_env()
{
if [ -z $(echo $PATH | grep "$OPENSHIFT_DATA_DIR/bin") ]; then
export PATH=$PATH:${OPENSHIFT_DATA_DIR}/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OPENSHIFT_DATA_DIR}/lib
fi
}
function cleanup()
{
rm -rf ${OPENSHIFT_DATA_DIR}/${PCRE_TARBALL}
rm -rf ${OPENSHIFT_DATA_DIR}/${PCRE_NAME}
}
function install_pcre()
{
cd ${OPENSHIFT_DATA_DIR} #AC
wget ${PCRE_SRC}
tar xvf ${PCRE_TARBALL}
cd ${PCRE_NAME}
./configure --prefix=${OPENSHIFT_DATA_DIR}
make
make install
}
if [ ! -f "$OPENSHIFT_DATA_DIR/bin/pcre-config" ]; then
install_pcre
setup_env
cleanup
fi
So now pcre is successfully installed on my openshift gear. Mission accomplished! Well, mostly. There is still a separate problem with library paths, but I will ask that separately if RedHat/OpenShift support doesn't come back with an answer.

Update composer.phar on Openshift

I have an application written in PHP using Fuelphp 1.6.3 and want to deploy it on Openshift
As the framework required composer, when I access my app at http://audit-manhthang.rhcloud.com/public/, it showed the error
Composer is not installed. Please run "php composer.phar update" in
the root to install Composer
I have Google it and found an article here: https://www.openshift.com/content/support-for-git-clone-on-the-server-aka-support-php-composerphar
I've tried to follow the instruction, create the file name deploy in .openshift/action_hooks folder and added following:
unset GIT_DIR
cd $OPENSHIFT_REPO_DIR/libs
wget -qN http://getcomposer.org/composer.phar
php composer.phar install
But it doesn't work. I have tried to revise install by update
unset GIT_DIR
cd $OPENSHIFT_REPO_DIR/libs
wget -qN http://getcomposer.org/composer.phar
php composer.phar update
But nothing change.
I use PHP 5.3 Cartridge on Openshift
When I did composer update
cd app-root/runtime/repo/php
/usr/bin/php composer.phar update
I received error like this
[RuntimeException]
/var/lib/openshift/52d3b7bd500446f4300001a5/.composer/cache/vcs does not exist and could not be created.
Composer is using $HOME variable to find root path. So to fix that I did.
export HOME=/var/lib/openshift/52d3b7bd500446f4300001a5/app-root/runtime/repo/php
and then
/usr/bin/php composer.phar update
worked.
After update was done I reverted $HOME
export HOME=/var/lib/openshift/52d3b7bd500446f4300001a5
Looks like there have been some changes how openshift works now. I know that this is quite ugly workaround. If I will find something better, I will update this answer. Still, hope this will help someone.
EDIT
Got it! :)
Create new file under .openshift directory:
.openshift/action_hooks/deploy
and mark it as executable.
#!/bin/bash
# Run composer install
cd app-root/runtime/repo/php
export HOME_ORIGIN=$HOME
export HOME=$HOME/app-root/runtime/repo/php
/usr/bin/php composer.phar install
export HOME=$HOME_ORIGIN
After that on every push composer will be updated to current composer.lock place. Perfect! :)
Also make sure vendor/ path is empty. Better add to .gitignore so it not messed up by your local setup.
Here is a slightly better solution than the others mentioned:
http://stanlemon.net/2013/03/22/composer-on-openshift/
The deploy script mentioned in the blog post:
a. downloads composer if not present and stores it in the data directory so that it persists
across git pushes
b. enables composer to use cached versions of packages in the .composer dir stored in the persistent data directory, thus decreasing the time required when doing frequent pushes
There was a small issue with the script - that the php version it was referring to was being complained as being too old by composer
remote: #!/usr/bin/env php
remote: Some settings on your machine may cause stability issues with Composer.
remote: If you encounter issues, try to change the following:
remote:
remote: Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended.
remote: Composer works with 5.3.2+ for most people, but there might be edge case issues.
So I changed the paths to use the latest present on the system
[domain.rhcloud.com action_hooks]\> php --version
PHP 5.4.16 (cli) (built: Dec 6 2013 01:17:01)
[domain.rhcloud.com 5316aa83e0b8cdb61b00023a]\> which php
/opt/rh/php54/root/usr/bin/php
The script in my .openshift/action_hooks/deploy is
#!/bin/bash
# Run composer install
cd app-root/runtime/repo/
export COMPOSER_HOME="$OPENSHIFT_DATA_DIR/.composer"
if [ ! -f "$OPENSHIFT_DATA_DIR/composer.phar" ]; then
curl -s https://getcomposer.org/installer | /opt/rh/php54/root/usr/bin/php -- --install-dir=$OPENSHIFT_DATA_DIR
else
/opt/rh/php54/root/usr/bin/php $OPENSHIFT_DATA_DIR/composer.phar self-update
fi
( unset GIT_DIR ; cd $OPENSHIFT_REPO_DIR ; /opt/rh/php54/root/usr/bin/php $OPENSHIFT_DATA_DIR/composer.phar install )
As the blog post suggests - create an empty hot_deploy file in the markers subdirectory to further speed things up by saying that the servers should not be restarted during a push -
touch .openshift/markers/hot_deploy
git add .openshift/markers/hot_deploy
git add .openshift/action_hooks/deploy
git commit -m "Speeding up composer installs across pushes"
git push origin master
And watch your git pushes be fast even when using composer.
I figure it out. With openshift, I can access via SSH and go to app-root(or something like that)/repo/php and then type /usr/bin/php composer.phar update. That's it.
For reference, OpenShift comes with built-in support for Composer. Adding the use_composer marker file, simply an empty file named use_composer, in your OpenShift project's .openshift/markers directory will automatically enable Composer install/update on deployment.
More specifically, each time you git push to your OpenShift git repo...
When in 'production' mode (default):
echo -n "Checking composer.json for Composer dependency... "
if [ -f ${OPENSHIFT_REPO_DIR}composer.json ]; then
echo
composer install --no-interaction --no-ansi --no-scripts --optimize-autoloader --working-dir=${OPENSHIFT_REPO_DIR} || \
echo -e "\nSkipping Composer errors..\n\n Please, fix the errors either locally or in development mode.\n"
if [ ! -f ${OPENSHIFT_REPO_DIR}composer.lock ]; then
echo -e $composer_lock_msg
fi
else
echo "File not found."
fi
When in 'development' mode:
if [ -f ${OPENSHIFT_REPO_DIR}composer.lock ]; then
echo "Ignoring composer.lock file (development mode)"
fi
echo -n "Checking composer.json for Composer dependency... "
if [ -f ${OPENSHIFT_REPO_DIR}composer.json ]; then
echo
composer update --no-interaction --no-ansi --no-scripts --optimize-autoloader --working-dir=${OPENSHIFT_REPO_DIR}
echo -e $composer_lock_msg
else
echo "File not found."
fi
Check out the code beginning at line #142 of the OpenShift PHP Cartridge.
Check out the Developer Portal article on enabling PHP 'development' mode for more details.
Check out the Laravel 5 QuickStart for example-use or for an easy way to get started.
I do not have enough points to comment on wormhit's answer, so I will append it here:
The zend/php-*/etc/php.ini file needed an update for OpenShift to work with the latest version of composer.phar as described here:
extension=phar.so
extension=ctype.so
Adding these extensions to it fixes PHP's complaints about composer.phar
The next fix required using relative pathing:
php composer.phar install
INSTEAD of absolute pathing:
/usr/bin/php composer.phar install
to allow the extensions to load.

NSIS - jruby fails to access environment variables

I've made a NSIS script to create an installer for a Rails application.
The application uses JRuby and Java.
In the first section of the installer I set the environment variables: I add jruby\bin to PATH and I create JAVA_HOME variable, which points to Java\jre6.
!define JRubyBinPath "$PROGRAMFILES\${PRODUCT_PUBLISHER}\JRuby\jruby-1.6.3\bin"
Function SetEnvVars
# set JAVA_HOME
${EnvVarUpdate} $0 "JAVA_HOME" "A" "HKCU" "C:\Program Files\Java\jre6"
# add jruby to Path
${EnvVarUpdate} $0 "Path" "A" "HKLM" "${JRubyBinPath}"
FunctionEnd
Section "Pre" SEC01
Call SetEnvVars
...
SectionEnd
** All the paths are correct. **
In the second section of the installer, after packing all the application files and JRuby files, I initialize the database using the following commands:
Section "Installer" SEC02
...
SetOutPath $INSTDIR
nsExec::ExecToLog "jruby -S bundle exec rake db:create RAILS_ENV=production"
nsExec::ExecToLog "jruby -S bundle exec rake db:migrate RAILS_ENV=production"
nsExec::ExecToLog "jruby -S bundle exec rake db:seed RAILS_ENV=production"
...
SectionEnd
The problem is that when I run the installer on a clean Windows system, all the code executes correctly, except for the lines that contain commands using "jruby". I get no error in the installer window, it just won't execute those lines.
Anyway, if I manually run those commands in a console right after the installer finishes, everything works as expected.
From what I have seen so far, the problem is that the installer cannot access the environment variables until it finishes.
* What I have done so far to solve this problem is creating the main installer Installer.exe (here I pack all the files and I set the environment variables), and another executable Init.exe which initializes the database.
If I manually run these executables - first Installer.exe then Init.exe - the application installs correctly. But if I try to launch Init.exe from Installer.exe, it won't work.
However, if there would be a way to execute the "jruby" commands in a new/different thread than the one that sets the environment variables, I think the problem would be solved. But I still couldn't find the way to do that.
Thanks.
NSIS doesn't have any threading. Apparently not quite true—but in your own code, you don't get to use threads.
You may need to set PATH for the current process; I'm not familiar with ${EnvVarUpdate}, but looking at its script it doesn't seem to updates the variable in the current process. Try this:
${EnvVarUpdate} $0 PATH A HKLM "${JRubyBinPath}" # The line you already have
System::Call Kernel32::SetEnvironmentVariable(t"PATH",tr0)
Another note: you are hard-coding JRubyBinPath; are you sure you really want to do that?