Docker Ruby Bundle Permissions Error on Build - ruby

Using docker-compose, I'm trying to build a Ruby application (ruby-app). However near the end of the build it errors out:
There was an error while trying to write to `/ruby-app/Gemfile.lock`. It is likely
that you need to grant write permissions for that path.
ERROR: Service 'ruby-app' failed to build: The command '/bin/sh -c bundle install --jobs 4' returned a non-zero code: 23
Not sure why this permissions error is cropping up now, it has been building fine for some time.

The problem was that I modified the Gemfile and I was expecting bundler inside of the container to generate the new Gemfile.lock based on the changes.
To fix the issue, I ran bundle install outside of the container. This generated a new Gemfile.lock on my local filesystem and then I was able to build the container as expected.

Related

How to fix "s3_website" issue while pushing Jekyll site on CloudFront through gitlab CI/CD?

I have created Pipeline in GitLabs and I am using docker as gitlab-runner. I want to push Jekyll website on s3 website. And to do so, I am using s3_website gem. I have 4 stages defined in my pipeline. Where I am building Jekyll, creating Artifacts using Gulp, executing test on my jekyll site and then deploying.
All steps are working fine but while doing deployment, I'm getting following error. And i could not figure it how to get this solve.
[fail] Could not load the site: Failed to parse ERB in /builds/myproject/s3_website.yml:
(SyntaxError) /usr/local/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_warn.rb:15: syntax error, unexpected tLABEL
module_function define_method(:warn) {|*messages, uplevel: nil|
It is working perfectly fine on my local machine when I'm not on Docker. But when I try to do the same thing using docker. It is giving me above error.
I tried it with ruby 2.3, 2.4, 2.5, 2.6 on my docker machine. However no luck.
bundle exec s3_website push
I am expecting this to deploy the site on S3 bucket and corresponding cloudfront.
Any clue would be appreciated.
We ran into this same error on CircleCI. If I understand correctly, the s3_website gem wraps a Java .jar that's using JRuby 1.7, and something must have changed in one of the Docker images or Ruby gems that causes it to start inheriting the system's Ruby 2+ path. As a result, its JRuby 1.7 tries to load Ruby gems that only work in Ruby 2.0 and above, so it runs into errors.
As a workaround, instead of letting the s3_website gem invoke the .jar file itself, I tell the s3_website gem to only download the .jar file, then I manually invoke it:
bundle exec s3_website install
java -cp $(bundle show s3_website)/*.jar s3.website.Push
I reported this on the s3_website project's GitHub page.
Same error message but different solution.
The root of my problem was that the S3_ACCESS_KEY_ID wasn't set properly. I source'd my .env file
source .env
And that loaded the access key variable and the deploy worked.

CircleCI and AWS CodeDeploy: No such file or directory

I've got a Ruby application that has been deployed to an AWS instance using CodeDeploy via CircleCI. I added a gem to the application. All tests are passing both locally and in CircleCI, but the deployment stage fails with this error:
$ create_application_revision /tmp/codedeploy_applications.json /tmp/codedeploy_revisions.json
create_application_revision loaded: {"applications":[{"application_root":"/","region":"us-west-2","revision_location":{"revisionType":"S3","s3Location":{"bucket":"something","key":"etl-scripts-testdeploy-3a050b1"}},"deployment_group":"EtlScriptsFleet","application_name":"EtlScripts"}]}
Bundling EtlScripts from /home/ubuntu/etl-scripts
Unhandled exception
[Errno 2] No such file or directory: '/home/ubuntu/etl-scripts/vendor/bundle/ruby/2.2.0/gems/regexp-examples-1.1.4/db/unicode_ranges_2.1.pstore'
It's true that file doesn't exist. It doesn't exist locally either, but all tests pass. I just can't figure out why the deployment process thinks it needs this file?
I noticed that in the source code for this gem (https://github.com/tom-lord/regexp-examples/tree/master/db) is a symbolic link and that's probably why it's not being created. But I'm still confused about how the deployment bundle process would know about a non-existant symbolic link.
Any help greatly appreciated!
It seems the deployment stage is being handled by the deploy push command from aws CLI, and it cannot handle broken symlinks.
I could reproduce the problem by trying to deploy an app containing a broken symlink using the push command:
(Command - aws deploy push --application-name --s3-location s3:///.zip --source ./)
(Output - [Errno 2] No such file or directory: '/path/to/source/')
I guess you will need to manually remove all broken symlinks for the deployment to succeed.
For what it's worth, this gem was later refactored to not use symbolic links; as of v1.3.0.
Upgrading from your current version (1.1.4) should almost certainly require no code change.

Trouble configuring Jenkins

When I go to run a ruby script as a build task, this is the error I get.
I am not sure what is wrong with the setup.
my RUBY_HOME "/home/bitnami/.rvm/rubies/ruby-1.9.3-p374"
Any Ideas?
Started by user User Name
Building in workspace /opt/bitnami/apps/jenkins/jenkins_home/workspace/Test
[Test] $ ruby -v /opt/bitnami/apache-tomcat/temp/hudson7369076924945073821.rb
FATAL: command execution failed
java.io.IOException: Cannot run program "ruby" (in directory "/opt/bitnami/apps/jenkins/jenkins_home/workspace/Test"): error=2, No such file or directory
To use RVM-managed ruby in Jenkins jobs, you have to source rvm in the build steps, like . /path/to/rvm/scripts/rvm. Then you need to set which ruby to use with rvm use. I use it extensively with no errors.

ROR Error: project directory contains "gemfile" but shows error "could not locate Gemfile" after executing bundle show

I am executing a command rails new sample_app. After creating a project sample_app, I executed bundle show command but it Could not locate Gemfile.
I Google and found stackoverflow solutions 1 2 3 in which they didn't find gemfile whereas in my case i have. Suggest some solutions.
I think you should be in sample_app directory. For this run on command prompt cd sample_appthen execute bundle installthen bundle show

How to build and run a Ruby command-line tool found on github?

Hi cloned a simple app ( https://github.com/cfx/twix) on github that allows me to send Twitter messages from the console, but I'm not sure how to run it.
I now have a folder in my users/name director called Twix. Inside twix, I have these folders created by the app.
README Rakefile bin lib test
The readme doesn't provide a lot of instruction to get things started. It just tells you what to do after the program's running (see below).
Questions: What command do I use to get this started? What folder do I need to be in?
The README
Twix 0.0.1
Simple twitter client for console
Keys:
q - quit
t - write new message
If you want to post your twit, finish you message with !SEND
If you want abort and back to your feed, finish your message with !EXIT
new features soon
This program is packaged as a gem. The following command will install the gem (run it in the Twix directory):
rake package && gem install pkg/twix-0.0.1.gem
You can now run the program from anywhere with the twix command.
Edit
The first thing I saw in the repository was the Rakefile, meaning there were some rake tasks defined. When you find yourself in this case, running rake -T is your best bet as it will show you the rake tasks available. Its output was the following:
(in /home/benoit/code/clones/twix)
rake clobber_package # Remove package products
rake gem # Build the gem file twix-0.0.1.gem
rake package # Build all the packages
rake repackage # Force a rebuild of the package files
I picked the command that would be the most likely to build the gem: the package one. I guess the gem task would have worked as well.
Running rake package gave me the following output:
(in /home/benoit/code/clones/twix)
mkdir -p pkg
WARNING: no homepage specified
Successfully built RubyGem
Name: twix
Version: 0.0.1
File: twix-0.0.1.gem
mv twix-0.0.1.gem pkg/twix-0.0.1.gem
All that was left was to install the pkg/twix-0.0.1.gem created by the previous command:
gem install pkg/twix-0.0.1.gem
There's another case you could have encountered: the presence of a twix.gemspec in the root directory of the application. In this case, running:
gem build twix.gemspec
would have built the gem, the installation step remains the same.
ruby ./bin/twix
or
ruby -I lib ./bin/twix

Resources