Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide a Dockerfile for a development environment to make it easier to get up and running #490

Open
robertselberg opened this issue Dec 13, 2024 · 12 comments

Comments

@robertselberg
Copy link

I'm new to Ruby and the experience of setting up Ruby and the dependencies for getting CMock up and running in a container sucks! I didn't even manage to evaluate CMock because of Ruby. I guess I'm alone with this experience and it's sad that CMock doesn't even get a chance of being used because of this.

Please provide a Dockerfile for building a complete development environment for testing the project using the latest standard Ubuntu/Debian image.

@Letme
Copy link

Letme commented Dec 13, 2024

Can you explain what is wrong?
You install ruby (2.7x atm) then you go to folder where you cloned CMock and write bundler install if you want to make sure all ruby dependencies are installed. But I did not see any of that in our dockers, so I assume package already has all the gems installed.

So in reality all you need is:

FROM debian:bookworm
RUN apt-get update && apt-get install -y --allow-unauthenticated \
		ruby=1:2.7+2 \
	&& rm -rf /var/lib/apt/lists/*

@Letme
Copy link

Letme commented Dec 13, 2024

Urgh, I jumped the gun a bit (seems like we are on old CMock version). Nowadays you can use Ruby3 based on github actions: https://github.com/ThrowTheSwitch/CMock/blob/master/.github/workflows/main.yml#L17-L22

So that's about what you need: a ruby3 container.

@robertselberg
Copy link
Author

robertselberg commented Dec 13, 2024

I meant something like this Dockerfile:

FROM ubuntu:24.04
RUN apt update
RUN apt install -y ruby git
RUN git clone https://github.com/ThrowTheSwitch/CMock.git /cmock
RUN cd /cmock && bundle install
RUN cd /cmock/test && rake

I'm new to Ruby and followed the "Getting Started" section of /README.md. The instructions fails on "bundle: not found" since I don't have the "bundle" program installed and I don't know what that program is or where to get it from..

That's why a Dockerfile that automates the whole process would be nice.

Then it is also possible to repeat the steps from the Docker file manually on the workstation for those that don't want to use a containerized environment.

@Letme
Copy link

Letme commented Dec 13, 2024

Uh, if you clone it in docker container, then you will lose the progress once container is shut down. Also without a key linked into it there is no way to commit nicely. So what you usually do you map the folder to inside the container and then inside the container you need to run bundle install and other commands

Maybe we should have rather use docker-compose for your example?

Here is docker command to map and run tests (copied from Ruby Dockerhub page):

docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app ruby:3.3 bundle install && cd test && rake

Docker compose would be something like:

compose.yml

services:
  test:
    image: ruby:3
    volumes:
      - .:/usr/src/app
    working_dir: /usr/src/app
    command:
      - bundle install
      - cd test && rake

And you run that with docker-compose run --rm test . Hope this gets you started and I think docker-compose contribution will be accepted.

@robertselberg
Copy link
Author

The Dockerfile above is just an example of what's happening if you follow the README.md instructions on a computer with a newly installed Ubuntu. So don't focus on the docker-related stuff.

I use Ubuntu on my workstation and the instructions in the README.md didn't work.

@Letme
Copy link

Letme commented Dec 13, 2024

Thats then different discussion. What was missing? ruby-bundler?

@robertselberg
Copy link
Author

I guess so. It's some program called bundle.

 => ERROR [5/6] RUN cd /cmock && bundle install                                                                                        0.3s
------                                                                                                                                      
 > [5/6] RUN cd /cmock && bundle install:
0.279 /bin/sh: 1: bundle: not found

@Letme
Copy link

Letme commented Dec 16, 2024

add apt install -y ruby-bundler to your environment (if you still use the same docker example as above add ruby-bundler next to ruby in that same command - it is also advised to remove apt cache to reduce the size of the docker container).

@robertselberg
Copy link
Author

Thank you for your quick response, it is much appreciated!

FROM ubuntu:24.04
RUN apt update
RUN apt install -y ruby git
RUN git clone https://github.com/ThrowTheSwitch/CMock.git /cmock
RUN apt install -y ruby-bundler
RUN cd /cmock && bundle install
RUN cd /cmock/test && rake
 => [6/7] RUN cd /cmock && bundle install                                                                                              9.2s
 => ERROR [7/7] RUN cd /cmock/test && rake                                                                                             0.5s 
------                                                                                                                                      
 > [7/7] RUN cd /cmock/test && rake:                                                                                                        
0.423 rake aborted!                                                                                                                         
0.439 LoadError: cannot load such file -- ../vendor/unity/auto/generate_test_runner (LoadError)                                             
0.439 <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:86:in `require'                                              
0.439 <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:86:in `require'
0.439 /cmock/test/rakefile_helper.rb:9:in `<top (required)>'
0.439 <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:86:in `require'
0.439 <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:86:in `require'
0.439 /cmock/test/rakefile:11:in `<top (required)>'
0.439 /var/lib/gems/3.2.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
0.439 (See full trace by running task with --trace)
------
Dockerfile:7
--------------------
   5 |     RUN apt install -y ruby-bundler
   6 |     RUN cd /cmock && bundle install
   7 | >>> RUN cd /cmock/test && rake
   8 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c cd /cmock/test && rake" did not complete successfully: exit code: 1

@Letme
Copy link

Letme commented Dec 16, 2024

FROM ubuntu:24.04
RUN apt update
RUN apt install -y ruby ruby-bundler git
RUN git clone --recursive https://github.com/ThrowTheSwitch/CMock.git /cmock
RUN cd /cmock && bundle install
RUN cd /cmock/test && rake

I added clone --recursive as you did not fully clone the cmock (and added ruby-bundler to the top apt install invocation).

Disclamer again: This above example includes a bunch of bad practices for active development and running of the build (rake) inside the Docker containers.

@robertselberg
Copy link
Author

I don't know if it worked for you, but for me it didn't. :(

 => CACHED [1/6] FROM docker.io/library/ubuntu:24.04                                                                                   0.0s
 => [2/6] RUN apt update                                                                                                               7.9s
 => [3/6] RUN apt install -y ruby ruby-bundler git                                                                                    21.5s
 => [4/6] RUN git clone --recursive https://github.com/ThrowTheSwitch/CMock.git /cmock                                                 9.6s 
 => [5/6] RUN cd /cmock && bundle install                                                                                              8.0s 
 => ERROR [6/6] RUN cd /cmock/test && rake                                                                                             0.5s 
------                                                                                                                                      
 > [6/6] RUN cd /cmock/test && rake:                                                                                                        
0.410 rake aborted!                                                                                                                         
0.410 Psych::AliasesNotEnabled: Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`. (Psych::AliasesNotEnabled)                                                                                                                    
0.410 /cmock/test/rakefile_helper.rb:24:in `load_configuration'                                                                             
0.410 /cmock/test/rakefile_helper.rb:34:in `configure_toolchain'
0.410 /cmock/test/rakefile:32:in `<top (required)>'
0.410 /var/lib/gems/3.2.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
0.410 (See full trace by running task with --trace)
------
Dockerfile:6
--------------------
   4 |     RUN git clone --recursive https://github.com/ThrowTheSwitch/CMock.git /cmock
   5 |     RUN cd /cmock && bundle install
   6 | >>> RUN cd /cmock/test && rake
   7 |     
   8 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c cd /cmock/test && rake" did not complete successfully: exit code: 1

@Letme
Copy link

Letme commented Dec 16, 2024

Sorry, I am not testing commands, I am just putting suggestions of what could be wrong based on error message. Maybe you need before 5/6 command (bundle install)

RUN gem install rspec
RUN gem install rubocop -v 0.57.2

Not sure (taken from the .github/workflows/main.yml).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants