Last active
November 12, 2024 09:59
-
-
Save ryochin/66c25c95d277a112feaace0011e1cf28 to your computer and use it in GitHub Desktop.
Rails new env creation
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
#!/bin/sh | |
PROJECT="rails8" | |
set -e | |
rm -rf .bundle .devcontainer .gitignore .github .kamal .rubocop.yml Gemfile* README.md Rakefile app bin compose.yml config* db lib log public script storage test tmp *.js* *.dev *.lock | |
rm -rf .dockerignore .gitattributes .node-version .tool-versions Dockerfile | |
rm -rf .git | |
rm -f Gemfile* | |
asdf local ruby 3.3.2 | |
asdf local nodejs 20.10.0 | |
bundle init | |
# bundle config --local build.mysql2 "--with-ldflags=-L/opt/homebrew/opt/openssl/lib --with-mysql-dir=/opt/homebrew/opt/[email protected]" | |
bundle config --local build.pg "--with-pg-config=/opt/homebrew/opt/postgresql@16/bin/pg_config" | |
echo 'gem "rails", "8.0.0"' >> Gemfile | |
bundle install | |
bundle exec rails new \ | |
--force \ | |
--name=${PROJECT} \ | |
--skip-keeps \ | |
--skip-action-mailbox \ | |
--skip-action-text \ | |
--skip-active-storage \ | |
--skip-hotwire \ | |
--database=postgresql \ | |
--javascript=esbuild \ | |
--css=sass \ | |
--devcontainer \ | |
. | |
rm -f .ruby-version .node-version | |
gibo dump macOS Ruby Rails > .gitignore | |
echo "/app/assets/builds/" >> .gitignore | |
echo "/compose*.yml" >> .gitignore | |
echo "/new-rails*.sh" >> .gitignore | |
perl -pl -i -e "s{#?host: localhost}{host: 127.0.0.1}" config/database.yml | |
sed -i '' "s/#username: /username: /" config/database.yml | |
sed -i '' "s/#password:/password: password/" config/database.yml | |
# echo "db: docker compose up mysql" >> Procfile.dev | |
echo "db: docker compose up postgres" >> Procfile.dev | |
git add . | |
git commit -m "initial import" | |
cat << END > compose.yml | |
version: '3.1' | |
services: | |
# mysql: | |
# image: mysql@sha256:355617769102e9d2ebb7d5879263a12d230badb7271c91748b2c7b0ac6971083 | |
# ports: | |
# - "3306:3306" | |
# environment: | |
# MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' | |
postgres: | |
image: postgres:16-bullseye | |
ports: | |
- "5432:5432" | |
environment: | |
TZ: "Asia/Tokyo" | |
PGTZ: "Asia/Tokyo" | |
POSTGRES_USER: "${PROJECT}" | |
POSTGRES_PASSWORD: "password" | |
PGUSER: "${PROJECT}" | |
END | |
echo "=> setup:" | |
echo " docker compose up postgres (or mysql)" | |
echo " bin/rails db:create" | |
echo "" | |
echo "=> next steps:" | |
echo " bin/dev" | |
echo " bin/rails g scaffold blogs title:string content:text active:boolean" | |
echo " bin/rails db:migrate" | |
echo " open http://localhost:3000/blogs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment