├── .github └── workflows │ └── docker-publish.yml ├── Dockerfile ├── LICENSE ├── README.md └── bin └── push /.github/workflows/docker-publish.yml: -------------------------------------------------------------------------------- 1 | name: Docker 2 | 3 | on: 4 | push: 5 | branches: main 6 | schedule: 7 | - cron: '0 0 * * *' # once per day 8 | 9 | jobs: 10 | build-and-push-image: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: read 14 | packages: write 15 | steps: 16 | - 17 | name: Checkout 18 | uses: actions/checkout@v3 19 | - 20 | name: Set up QEMU 21 | uses: docker/setup-qemu-action@v2 22 | - 23 | name: Set up Docker Buildx 24 | uses: docker/setup-buildx-action@v2 25 | - 26 | name: Login to GitHub Container Registry 27 | uses: docker/login-action@v2 28 | with: 29 | registry: ghcr.io 30 | username: ${{ github.actor }} 31 | password: ${{ secrets.GITHUB_TOKEN }} 32 | - 33 | name: Build and push 34 | uses: docker/build-push-action@v3 35 | with: 36 | context: . 37 | platforms: linux/amd64,linux/arm64 38 | push: true 39 | tags: ghcr.io/rails/cli:latest 40 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG RUBY_VERSION=3.4.4 2 | 3 | FROM ruby:$RUBY_VERSION-slim 4 | 5 | # Install dependencies 6 | RUN apt-get update -qq && apt-get install -y build-essential libvips gnupg2 curl git libyaml-dev 7 | 8 | # Ensure node.js 20 is available for apt-get 9 | ARG NODE_MAJOR=20 10 | RUN apt-get update && \ 11 | mkdir -p /etc/apt/keyrings && \ 12 | curl --fail --silent --show-error --location https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ 13 | echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list 14 | 15 | # Install node and yarn 16 | RUN apt-get update -qq && apt-get install -y nodejs && npm install -g yarn 17 | 18 | # Mount $PWD to this workdir 19 | WORKDIR /rails 20 | 21 | # Ensure gems are installed on a persistent volume and available as bins 22 | # Make the folder world writable to let the default user install the gems 23 | RUN mkdir /bundle && chmod -R ugo+rwt /bundle 24 | VOLUME /bundle 25 | ENV BUNDLE_PATH='/bundle' 26 | ENV PATH="/bundle/ruby/$RUBY_VERSION/bin:${PATH}" 27 | 28 | # Install Rails 29 | RUN gem install rails 30 | 31 | # Ensure binding is always 0.0.0.0, even in development, to access server from outside container 32 | ENV BINDING="0.0.0.0" 33 | 34 | # Overwrite ruby image's entrypoint to provide open cli 35 | ENTRYPOINT [""] 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 David Heinemeier Hansson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docked Rails CLI 2 | 3 | Setting up Rails for the first time with all the dependencies necessary can be daunting for beginners. Docked Rails CLI uses a Docker image to make it much easier, requiring only Docker to be installed. 4 | 5 | Install [Docker](https://www.docker.com/products/docker-desktop/) (and [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) on Windows). Then copy'n'paste into your terminal: 6 | 7 | ```bash 8 | docker volume create ruby-bundle-cache 9 | alias docked='docker run --rm -it -v ${PWD}:/rails -u $(id -u):$(id -g) -v ruby-bundle-cache:/bundle -p 3000:3000 ghcr.io/rails/cli' 10 | ``` 11 | 12 | Then create your Rails app: 13 | 14 | ```bash 15 | docked rails new weblog 16 | cd weblog 17 | docked rails generate scaffold post title:string body:text 18 | docked rails db:migrate 19 | docked rails server 20 | ``` 21 | 22 | That's it! Your Rails app is running on `http://localhost:3000/posts`. 23 | 24 | ## Sidenote 25 | 26 | `docked` is not intended to replace a full development setup. It is merely a way for newcomers to quickly get started with Rails. The included dependencies stick to what you need when running `rails new` without additional options. It does not include dependencies for running with PostgreSQL or Redis for example. 27 | -------------------------------------------------------------------------------- /bin/push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker buildx create --use 4 | docker buildx build --push --platform=linux/amd64,linux/arm64 -t ghcr.io/rails/cli . 5 | --------------------------------------------------------------------------------