Last active
November 10, 2023 13:45
-
-
Save kubicek/58f2dddc7b8f823ba73923693efa64c1 to your computer and use it in GitHub Desktop.
bullettrain with docker-compose with fresh rails in new repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '3.1' | |
| services: | |
| db: | |
| image: postgres:alpine | |
| restart: always | |
| environment: | |
| - POSTGRES_USER=postgres | |
| - POSTGRES_PASSWORD=postgres | |
| ports: | |
| - '5432:5432' | |
| volumes: | |
| - postgres:/var/lib/postgresql/data | |
| redis: | |
| image: redis:6.2-alpine | |
| restart: always | |
| ports: | |
| - '6379:6379' | |
| command: redis-server --save 20 1 --loglevel warning | |
| volumes: | |
| - redis:/data | |
| web: | |
| build: . | |
| tty: true | |
| environment: | |
| - REDIS_URL=redis://redis:6379 | |
| - DATABASE_URL=postgres://postgres:postgres@db:5432/web | |
| volumes: | |
| - .:/myapp | |
| ports: | |
| - "3000:3000" | |
| depends_on: | |
| - db | |
| - redis | |
| volumes: | |
| postgres: | |
| driver: local | |
| redis: | |
| driver: local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ruby:3 | |
| # based on https://github.com/timbru31/docker-ruby-node/blob/master/3.1/16/Dockerfile | |
| RUN curl -sL https://deb.nodesource.com/setup_17.x | bash -\ | |
| && apt-get update -qq && apt-get install -qq --no-install-recommends \ | |
| postgresql-client nodejs redis-tools \ | |
| && apt-get upgrade -qq \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/*\ | |
| && npm install -g yarn | |
| RUN mkdir /myapp | |
| WORKDIR /myapp | |
| COPY Gemfile /myapp/Gemfile | |
| COPY Gemfile.lock /myapp/Gemfile.lock | |
| RUN bundle install | |
| COPY . /myapp | |
| RUN yarn install | |
| EXPOSE 3000 | |
| CMD "bin/dev" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This template: | |
| # * commits new generated rails skeleton, | |
| # * fetches latest bullettrain template sources and stores | |
| # it in separate commit | |
| # * sets up docker-compose | |
| # Usage: rails new myapp -m https://gist.githubusercontent.com/kubicek/58f2dddc7b8f823ba73923693efa64c1/raw/template.rb | |
| # template source based on: https://github.com/mattbrictson/rails-template | |
| def rails_version | |
| @rails_version ||= Gem::Version.new(Rails::VERSION::STRING) | |
| end | |
| def rails_7_0_0? | |
| Gem::Requirement.new("= 7.0.0").satisfied_by? rails_version | |
| end | |
| unless rails_7_0_0? | |
| puts "Please use Rails 7.0.0 by executing rails _7.0.0_ new" | |
| end | |
| def commit_skeleton | |
| git add: "." | |
| # git commit will fail if user.email is not configured | |
| begin | |
| git commit: %( -m 'Rails 7.0.0 generated skeleton' ) | |
| rescue StandardError => e | |
| puts e.message | |
| end | |
| end | |
| def commit_bullettrain | |
| git clone: "--depth 1 "+ | |
| "https://github.com/bullet-train-co/bullet_train origin" | |
| # create folders | |
| run "git --git-dir origin/.git diff --name-only | xargs -n 1 dirname | xargs mkdir -p" | |
| # copy files | |
| run "git --git-dir origin/.git diff --name-only | xargs -L1 -I % cp ./origin/% ./%" | |
| run "rm -rf origin" | |
| git add: "." | |
| git commit: '-m "Added bullet_train based on #`git --git-dir origin/.git rev-parse --short HEAD`"' | |
| end | |
| def configure_bullettrain | |
| # from bullettrains bin/configure | |
| require "active_support/inflector" | |
| human = ask "What is the name of your new application in title case? (e.g. \"Some Great Application\")" | |
| variable = ActiveSupport::Inflector.parameterize(human, separator: '_') | |
| environment_variable = ActiveSupport::Inflector.parameterize(human, separator: '_').upcase | |
| class_name = variable.classify | |
| kebab_case = variable.tr("_", "-") | |
| puts "" | |
| say "Replacing instances of \"Untitled Application\" with \"#{human}\" throughout the codebase.", :green | |
| gsub_file("./.circleci/config.yml", "untitled_application", variable) | |
| gsub_file("./config/database.yml", "untitled_application", variable) | |
| gsub_file("./config/database.yml", "UNTITLED_APPLICATION", environment_variable) | |
| gsub_file("./config/cable.yml", "untitled_application", variable) | |
| gsub_file("./config/initializers/session_store.rb", "untitled_application", variable) | |
| gsub_file("./config/environments/production.rb", "untitled_application", variable) | |
| gsub_file("./config/application.rb", "UntitledApplication", class_name) | |
| # TODO: gsub_file("./config/locales/en/application.en.yml", "Untitled Application", human, /name/) | |
| gsub_file("./config/locales/en/application.en.yml", "untitled_application", variable) | |
| # TODO: gsub_file("./config/locales/en/application.en.yml", "untitled application", human.downcase, /keywords/) | |
| gsub_file("./config/locales/en/user_mailer.en.yml", "Untitled Application", human) | |
| say | |
| say "Moving `./README.example.md` to `./README.md`.", :green | |
| run "mv ./README.example.md ./README.md" | |
| # We can only do this after the README is moved into place. | |
| gsub_file("./README.md", "Untitled Application", human) | |
| git add: "." | |
| git commit: %( -m 'Configured bullettrain' ) | |
| end | |
| def commit_docker | |
| get "https://gist.githubusercontent.com/kubicek/58f2dddc7b8f823ba73923693efa64c1/raw/Dockerfile", "Dockerfile" | |
| get "https://gist.githubusercontent.com/kubicek/58f2dddc7b8f823ba73923693efa64c1/raw/docker-compose.yml", "docker-compose.yml" | |
| say "Applying changes for docker" | |
| gsub_file("Procfile.dev","-p 3000","-p 3000 -b 0.0.0.0") | |
| insert_into_file "config/cable.yml", " url: <%= ENV.fetch(\"REDIS_URL\") %>\n", :after => "adapter: redis\n" | |
| git add: "." | |
| git commit: %( -m 'Added docker' ) | |
| end | |
| after_bundle do | |
| git :init | |
| commit_skeleton | |
| commit_bullettrain | |
| configure_bullettrain | |
| commit_docker | |
| say | |
| say "Bullettrain app successfully created!", :blue | |
| say | |
| say "To get started with your new app:", :green | |
| say " cd #{original_app_name}" | |
| say | |
| say " docker compose build" | |
| say " docker compose run web bin/setup" | |
| say " docker compose up" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also noticed the following in the logs:
DEBUG [1f77a6d4] #9 [linux/arm64 2/9] RUN curl -sL https://deb.nodesource.com/setup_17.x | bash - && apt-get update -qq && apt-get install -qq --no-install-recommends postgresql-client nodejs redis-tools && apt-get upgrade -qq && apt-get clean && rm -rf /var/lib/apt/lists/* && npm install -g yarn
DEBUG [1f77a6d4] #9 22.17
DEBUG [1f77a6d4] #9 22.18 ================================================================================
DEBUG [1f77a6d4] #9 22.18 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
DEBUG [1f77a6d4] #9 22.18 ================================================================================
DEBUG [1f77a6d4] #9 22.18
DEBUG [1f77a6d4] #9 22.18 SCRIPT DEPRECATION WARNING
DEBUG [1f77a6d4] #9 22.18
DEBUG [1f77a6d4] #9 22.18
DEBUG [1f77a6d4] #9 22.18 This script, located at https://deb.nodesource.com/setup_X, used to
DEBUG [1f77a6d4] #9 22.19 install Node.js is deprecated now and will eventually be made inactive.
DEBUG [1f77a6d4] #9 22.19
DEBUG [1f77a6d4] #9 22.19 Please visit the NodeSource distributions Github and follow the
DEBUG [1f77a6d4] #9 22.19 instructions to migrate your repo.
DEBUG [1f77a6d4] #9 22.19 https://github.com/nodesource/distributions
DEBUG [1f77a6d4] #9 22.19
DEBUG [1f77a6d4] #9 22.19 The NodeSource Node.js Linux distributions GitHub repository contains
DEBUG [1f77a6d4] #9 22.19 information about which versions of Node.js and which Linux distributions
DEBUG [1f77a6d4] #9 22.19 are supported and how to install it.
DEBUG [1f77a6d4] #9 22.19 https://github.com/nodesource/distributions
DEBUG [1f77a6d4] #9 22.19
DEBUG [1f77a6d4] #9 22.19
DEBUG [1f77a6d4] #9 22.19 SCRIPT DEPRECATION WARNING
DEBUG [1f77a6d4] #9 22.19
DEBUG [1f77a6d4] #9 22.19 ================================================================================
DEBUG [1f77a6d4] #9 22.19 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
DEBUG [1f77a6d4] #9 22.19 ================================================================================
DEBUG [1f77a6d4] #9 22.19
DEBUG [1f77a6d4] #9 22.19 TO AVOID THIS WAIT MIGRATE THE SCRIPT
DEBUG [1f77a6d4] #9 22.19 Continuing in 60 seconds (press Ctrl-C to abort) ...