I am using GitLab to host my static page!
every time I am configuring the .gitlab-ci.yml file I am getting the following error: "Could not locate Gemfile"
Here is the output of the cmd
Here id the .gitlab-ci.yml file
image: ruby:2.3
before_script:
- bundle install
job:
script:
- gem install jekyll
- jekyll build
pages:
stage: deploy
script:
- bundle install
- bundle exec jekyll build -d public
artifacts:
paths:
- public
only:
- master
test:
stage: test
script:
- bundle install
- bundle exec jekyll build -d test
artifacts:
paths:
- test
except:
- master
In your configuration I see a mixed of different install instructions:
bundle install (in the before_script)
bundle install (again, in the pages deploy script)
gem install jekyll
The Gemfile is required by the bundle command, and it should specify mainly the dependency on jekyll (so again a duplication)
PROPOSED SOLUTION:
I suggest you to try with the configuration in the gitlab pages sample:
gitlab-ci.yml
image: ruby:2.3
variables:
JEKYLL_ENV: production
before_script:
- bundle install
test:
stage: test
script:
- bundle exec jekyll build -d test
artifacts:
paths:
- test
except:
- master
pages:
stage: deploy
script:
- bundle exec jekyll build -d public
artifacts:
paths:
- public
only:
- master
Gemfile
source "https://rubygems.org"
ruby RUBY_VERSION
# This will help ensure the proper Jekyll version is running.
gem "jekyll", "3.4.0"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Related
I'm trying to deploy my rails app to the Heroku using heroku.yml. This is my yml setup
setup:
addons:
- plan: cleardb-mysql
as: DATABASE
build:
docker:
web: Dockerfile
config:
RAILS_ENV: development
DATABASE_URL: mysql2://abcdef:1234567#somewhere-someplace-123.cleardb.net/heroku_abcdefg123456
run:
web: bin/rails server -p $PORT -b 0.0.0.0
and I'm using MySQL as a database. And here's my Dockerfile that the Heroku is using to build the image.
FROM ruby:2.6.5-alpine
ARG DATABASE_URL
ARG RAILS_ENV
# Adding the required dependencies
# Installing Required Gems
# Other Configs...
# Copying Gem Files
COPY Gemfile Gemfile.lock ./
# Installing Gems
RUN bundle install --jobs=4 --retry=9
# Copying package and package.lock
COPY package.json yarn.lock ./
# Installing node_modules
RUN yarn
# Copy everything to the from current dir to container_root
COPY . ./
#Compiling assets
RUN bundle exec rake assets:precompile # this precompilation step need DATABASE_URL
CMD ["rails", "server", "-b", "0.0.0.0"]
This is working as expected but the problem is I've to pass the database string in the heroku.yml file. Is there a way I can reference the config vars that are declared in the Heroku?
I tried this but it's not working as the docs also saying that the config-vars declared in Heroku are not available at the build time.
setup:
addons:
- plan: cleardb-mysql
as: DATABASE
build:
docker:
web: Dockerfile
config:
RAILS_ENV: $RAILS_ENV
DATABASE_URL: $DATABASE_URL
run:
web: bin/rails server -p $PORT -b 0.0.0.0
What could be the possible workaround for this issue?
Without using the heroku.yml a possible solution is to include the env variable in the Dockerfile.
Example with Java code:
CMD java -Dserver.port=$PORT -DmongoDbUrl=$MONGODB_SRV $JAVA_OPTS -jar /software/myjar.jar
You need to build the image locally, push and release it into the Heroku Registry: when it runs the Config Vars (ie MONGODB_SRV) are injected
I have the gitlab repository setup with the frontend and backend folders inside it. Basically my folder structure is as below,
--repo
- frontend folder
- backend folder
- gitlab-ci.yml
According to the docs, the gitlab-ci.yml file is placed in the root folder as provided in the image.
I am getting the error while running the pipeline. "npm install" command does not gets executed, instead it gets errored out as no such file or directory. The package.json file is placed inside the backend folder.
I would require to change the directory while npm install command and also to deploy.
My gitlab-ci.yml file is as below,
# Node docker image on which this would be run
image: node:8.10.0
cache:
paths:
- node_modules/
stages:
- test
- deploy_production
# Job 1:
Test:
stage: test
script:
- npm install
# Job 2:
# Deploy to staging
Production:
image: ruby:latest
only:
- master
stage: deploy_production
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=XXXXXXX --api-key=XXXXXXXXXXXXXXXXXXXXXXXXXX
Any help would be really appreciated! Thanks
npm install needs to run in a folder containing a package.json file. I suspect this file might be present in your subfolders (frontend and/or backend).
You should add
before_script:
- cd backend # or frontend
to your Test job.
I'm trying to setup a basic pipeline in Gitlab that does the following:
Run tests command, compile the client and deploy the application using docker-compose.
The problem comes when I'm trying to use npm install.
My .gitlab-ci.yml file looks like:
# This file is a template, and might need editing before it works on your
project.
# Official docker image.
image: docker:latest
services:
- docker:dind
stages:
- test
- build
- deploy
build:
stage: build
script:
- cd packages/public/client/
- npm install --only=production
- npm run build
test:
stage: test
only:
- develop
- production
script:
- echo run tests in this section
step-deploy-production:
stage: deploy
only:
- production
script:
- docker-compose up -d --build
environment: production
when: manual
And the error is:
Skipping Git submodules setup
$ cd packages/public/client/
$ npm install --only=production
bash: line 69: npm: command not found
ERROR: Job failed: exit status 1
I'm using the last docker image, so, I'm wondering whether I can define a new service on my build stage or should I use a different image for the whole process?
Thanks
A new service will not help you, you'll need to use a different image.
You can use a node image just for your build-stage like this:
build:
image: node:8
stage: build
script:
- cd packages/public/client/
- npm install --only=production
- npm run build
These days I am struggling with GitLab CI setup for my project. The setup is not as simple as Travis CI. I've spent a whole lot of time debugging this and all I found do not fit my requirements
Context
I have a Rails project which is using rvm and npm and postgresql. I built a custom Docker image with rvm and npm installed. However, before running I have to get the correspond ruby and node version as in my .gitlab-ci.yml :
image: "my-rvm-npm-image"
services:
- postgres:9.3-alpine
variables:
POSTGRES_DB: db
POSTGRES_USER: user
POSTGRES_PASSWORD:
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- node_modules/
stages:
- build
- rspec
- npm
build:
stage: build
script:
- sudo chown -R $(whoami) /cache
- /bin/bash -l -c "rvm install $(cat .ruby-version)
&& rvm use $(cat .ruby-version)
&& gem install bundle && bundle install --jobs $(nproc) --path /cache
&& source ~/.nvm/nvm.sh && nvm install && npm install npm -g && npm install
&& bundle exec rake db:test:prepare"
rspec:
stage: rspec
script:
- bundle exec rake
npm:
stage: npm
script:
- npm test
Please note that this .gitlab-ci.yml file is still failed. bundle install will be in the /cache as in GitLab runner configuration:
[[runners]]
name = "xxxx"
url = "URLabc.com"
token = "myprojectoken"
executor = "docker"
[runners.docker]
tls_verify = false
image = "my-rvm-npm-image"
privileged = true
disable_cache = false
volumes = ["/home/ci/cache:/cache", "/home/ci/builds:/builds"]
[runners.cache]
builds and cache folder are host-bound. So that I can keep the bundle install cache for the next build.
My problem
build job passes, but rspec and npm failed /bin/bash: bundle: command not found. It seems that the bundle is not passed to other jobs. I know I should use artifacts to pass to other job, but I already have it as cache, I should have
I want to achieve these goals:
Cache bundle install for every run, since it take 10 ~ 15 mins to rebuild from scratch, and pass to rspec job to run the test.
Also cache node_modules from npm install and pass to npm job.
Any suggestion for rvm and npm installation, because I do not want the ugly way bash -l -c before every command.
I am trying to setup Gitlab CI for my Ruby on Rails project, but ran into an error that I don't know how to fix.
The application is running on Ruby 2.3.1, Rails 5.0 and is using a postgreSQL database.
My current .gitlab.ci.yml file looks like this:
# https://hub.docker.com/r/library/ruby/tags/
image: "ruby:2.3.0"
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
services:
- redis:latest
- postgres:latest
- node:latest
# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
- gem install bundler # Bundler is not installed with the image
- bundle install -j $(nproc) # Install dependencies
rubocop:
script:
- rubocop
rspec:
script:
- rspec spec
rails:
script:
- rails db:migrate
- rspec spec
So it's supposed to be using NodeJS as runtime. However, I get the following error:
$ rails db:migrate
rails aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'uglifier'.
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
Backtrace for gem load error is:
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `require'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `block in require'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:259:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `require'
/usr/local/bundle/gems/uglifier-3.0.0/lib/uglifier.rb:5:in `<top (required)>'
You need to have a javascript runtime (e.g. nodejs). You can install it by using the following command:
For Ubuntu Users
sudo apt-get install nodejs
For CentOS / RedHat Users
sudo yum install nodejs
In case you can't install nodejs you can install and then use therubyracer gem.
Description from repository:
Embed the V8 JavaScript interpreter into Ruby.
Add this line to your Gemfile
gem 'therubyracer', platforms: :ruby
Gitlab-CI can be configured with the file .gitlab-ci.yml in this case:
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
can be used to install nodejs on the setup stage (source).
A complete before_script with jekyll can look like the following code (for instance, this is required for jekyll-minifier):
image: ruby:latest
variables:
JEKYLL_ENV: production
LC_ALL: C.UTF-8
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler
- bundle install
test:
stage: test
script:
- bundle exec jekyll build -d test
artifacts:
paths:
- test
except:
- master
pages:
stage: deploy
script:
- bundle exec jekyll build -d public
artifacts:
paths:
- public
only:
- master