Skip to content

Instantly share code, notes, and snippets.

@alfredorico
Last active October 17, 2023 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredorico/767b06dd35401ec123809eb050e2034a to your computer and use it in GitHub Desktop.
Save alfredorico/767b06dd35401ec123809eb050e2034a to your computer and use it in GitHub Desktop.
Generate a Ruby gem with docker

This is an opinionated gist just to show that it's possible to start a ruby gem development work using Docker (I don't want any ruby installation in my manjaro laptop).

To generate a new gem in linux you can use the following command (if you're using MacOS there is no need to use --user flag):

docker run --rm -it -w /app -v ${PWD}:/app ruby:slim bash -c "bundle gem newgem && chown -R $(id -u):$(id -g) ./newgem" 

Then you can use the following Dockerfile to start the gem development work:

FROM ruby:slim

WORKDIR /app

# Add build-essential if you need some compiled gems
RUN bash -c "set -o pipefail && apt-get update \
  && apt-get install -y --no-install-recommends git build-essential"

RUN git config --global --add safe.directory /app

COPY . .

RUN bin/setup

CMD ["bin/console"]

And the following docker-compose file:

version: '3.4'

services:
  newgem:
    image: newgem
    container_name: newgem    
    build:
      context: ./newgem
      dockerfile: ../Dockerfile
    volumes:
      - ./newgem:/app
      - gems_cache:/usr/local/bundle
volumes:
  gems_cache:

You need to adjust the gemspec file to edit the "TODO" strings and set the URLs required fields (homepage_uri, source_code_uri, changelog_uri) and then make a first commit inside the newgem folder.

Your project structure would be:

image

Then, you need to udpate the newgem.gemspec file setting the proper URLs and removing all TODO text

Then, create the docker image:

docker-compose build

Finally you can start your development work:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment