├── .env.development ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── database.yml.example └── docker-compose-local.yml /.env.development: -------------------------------------------------------------------------------- 1 | # .env.development 2 | POSTGRES_USER=db_user 3 | POSTGRES_PASSWORD=123qweasd 4 | DATABASE_HOST=127.0.0.1 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.1.2-alpine 2 | 3 | ENV BUNDLER_VERSION=2.2.27 4 | 5 | RUN apk --update add --no-cache build-base \ 6 | postgresql-dev \ 7 | postgresql-client \ 8 | libxml2-dev \ 9 | libxslt-dev \ 10 | libpq-dev \ 11 | libffi-dev \ 12 | tzdata 13 | RUN gem install bundler -v "$BUNDLER_VERSION" 14 | 15 | WORKDIR /app 16 | 17 | COPY Gemfile* ./ 18 | 19 | RUN bundle check || bundle install 20 | 21 | COPY . . 22 | 23 | CMD ["rails", "server", "-b", "0.0.0.0"] 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Fedor Koshel 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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | SHELL := /bin/zsh # could be changed to your shell 4 | 5 | # All tasks should be added here, otherwise Make tries to create the folder with the same name and skip the task if the folder exists 6 | .PHONY: env db dev console stop server prepare test yarn front 7 | 8 | dev: env db 9 | 10 | prepare: env db yarn 11 | bundle install 12 | bundle exec rake db:prepare 13 | bundle exec rake webpacker:install 14 | bundle exec rake assets:clobber 15 | - bundle exec rake webpacker:compile 16 | 17 | yarn: 18 | yarn add bootstrap@5.0.0-beta2 19 | yarn add @popperjs/core@2.0.0-alpha.1 20 | yarn add chart.js 21 | 22 | env: 23 | source ./.env.development 24 | 25 | db: 26 | docker-compose -f docker-compose-local.yml up -d db redis 27 | 28 | console: 29 | bundle exec rails c 30 | 31 | server: 32 | bundle exec rails s 33 | 34 | docker_server: 35 | docker-compose -f docker-compose-local.yml up -d web 36 | 37 | test: 38 | bundle exec rspec 39 | 40 | stop: 41 | docker-compose -f docker-compose-local.yml down 42 | 43 | front: 44 | bundle exec ./bin/webpack-dev-server 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This is a small template that I use for creating new Ruby projects. It helps setting up database, redis and sidekiq in Docker using docker-compose. 4 | Make is used as an aliases list for the project. For example `make dev` calls related tasks `env` that exports ENV variables for further tasks and `db` that calls `docker-compose` with a specific file. You can add new tasks or remove not required. 5 | Unfortunately, Make can't save ENV variables for the parent process (your shell), so the `source .env.development` call is required to have the same variables in your own shell. Another way is using [dotenv gem](https://github.com/bkeepers/dotenv) or any autoenv plugin for your shell. 6 | 7 | ## Setup 8 | 9 | 1. Fetch 10 | 2. Creaate rails project 11 | 3. Copy files to the project folder (`database.yml.example` should change `config/database.yml`) 12 | 4. Adjust settings 13 | 5. Use 14 | 15 | ## Usage 16 | 17 | - `make dev` - setup docker containers 18 | - `make prepare` - call bundle and yarn install, creates database. 19 | - `make yarn` - add bootstrap to yarn. It's an example task, if you don't need a bootstrap, you can remove it. 20 | - `make env` - setup ENV variables for other tasks. Does nothing when called alone. 21 | - `make db` - start database in the docker container (partial task without `env` can be broken, should be used as a part of `dev` task) 22 | - `make console` - starts rails console 23 | - `make server` - starts rails server locally. 24 | - `make docker_server` - starts rails server in the docker container. 25 | - `make test` - starts rspec 26 | - `make stop` - stops docker containers 27 | - `make front` - starts webpacker dev server locally. 28 | 29 | Keep in mind, that these files are just a template that should be adjusted for your needs. If you use another shell than `zsh`, it should be changed in the `Makefile`. Also, you can update ruby, rails and bundler versions in the Dockerfile, ad additional packages, commands, e.t.c. It also makes sense to remove not required commands from the `Makefile` and add your own. In other words, change everything and don't expect a silver bullet for any needs. 30 | -------------------------------------------------------------------------------- /database.yml.example: -------------------------------------------------------------------------------- 1 | # database.yml.example 2 | 3 | default: &default 4 | adapter: postgresql 5 | encoding: unicode 6 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 7 | port: 5432 8 | 9 | local_default: &local_default 10 | <<: *default 11 | user: <%= ENV.fetch("POSTGRES_USER", 'postgres') %> 12 | password: <%= ENV.fetch("POSTGRES_PASSWORD", '') %> 13 | host: <%= ENV.fetch("DATABASE_HOST", 'localhost') %> 14 | 15 | development: 16 | <<: *local_default 17 | database: 18 | 19 | test: 20 | <<: *local_default 21 | database: 22 | 23 | production: 24 | <<: *default 25 | database: 26 | username: 27 | password: 28 | -------------------------------------------------------------------------------- /docker-compose-local.yml: -------------------------------------------------------------------------------- 1 | # docker-compose-local.yml 2 | --- 3 | version: "3.9" 4 | services: 5 | redis: 6 | image: 'redis:alpine' 7 | ports: 8 | - '6379:6379' 9 | db: 10 | image: 'postgres' 11 | env_file: 12 | - .env.development 13 | volumes: 14 | - db-data:/var/lib/postgresql/data/ 15 | ports: 16 | - '5432:5432' 17 | # web: 18 | # build: 19 | # context: . 20 | # environment: 21 | # - DB_HOST=db 22 | # ports: 23 | # - 3000:3000 24 | # depends_on: 25 | # - db 26 | # - redis 27 | # sidekiq: 28 | # depends_on: 29 | # - 'db' 30 | # - 'redis' 31 | # build: . 32 | # command: bundle exec sidekiq 33 | # volumes: 34 | # - '.:/project' 35 | # - '/project/tmp' # don't mount tmp directory 36 | # environment: 37 | # - REDIS_URL_SIDEKIQ=redis://redis:6379/1 38 | 39 | volumes: 40 | db-data: 41 | --------------------------------------------------------------------------------