お疲れ様です!

あまり馴染みのないbunですが、Railsでオプション追加されているので使ってみようという事で使用しています!!理由は、処理速度が早いのでbuildが早いからです。 その他も、カスタムcssを使いやすくる為にscssを使いながらTailwind CSS+DaisyUIを入れています。また、reactも入れる手順も追加してします! 複合的に色々入れたので参考にして下さい! デプロイは、簡単済ませるためにgit 経由でherokに入れます!また、アプリ上で行なっています。

参考記事と公式1.初めにフォルダーの作成と作成フォルダーに移動

簡単CSSアニメーション&デザイン20選(ソースコードと解説付き) | knowledge / baigie

100秒で理解するBun

【Rails + Bun】Rails 7.1.0.beta1でJSのビルドにBunを試してみる - Qiita

Bun — A fast all-in-one JavaScript runtime

React

*日本語での作成はやめてくださいgitが認識しない可能性があります。

mkdir 自分で開発するアプリの名前
cd 自分で開発するアプリの名前

2.Dockerfileの作成

touch Dockerfile

その後、Dockerfile内に

FROM ruby:3.3.1 

# 環境変数の設定
ENV LANG C.UTF-8
ENV TZ Asia/Tokyo

# 必要なパッケージのインストール
RUN apt-get update -qq && apt-get install -y ca-certificates curl gnupg build-essential libpq-dev

# Node.jsとBunのリポジトリと鍵の追加
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && mkdir -p /etc/apt/keyrings \
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
    && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

# Node.jsのインストール
RUN apt-get update && apt-get install -y nodejs

# アプリケーションディレクトリの作成
RUN mkdir /app
WORKDIR /app

# Gemの依存関係の解決
COPY Gemfile* /app/
RUN gem update --system
RUN gem install bundler && bundle install

# Railsのインストール
RUN gem install rails
RUN which rails
RUN echo $PATH

# Railsのバージョンを確認
RUN /usr/local/bundle/bin/rails --version

# Railsがインストールされている場所をパスに追加
ENV PATH="/usr/local/bundle/bin:${PATH}"

# Bunのインストール
RUN curl -fsSL https://bun.sh/install | bash
RUN /root/.bun/bin/bun --version

# Bunがインストールされている場所をパスに追加
ENV PATH /root/.bun/bin:$PATH

# アプリケーションのコピー
COPY . /app

# ポート3000を公開
EXPOSE 3000

# Railsサーバーを起動
CMD ["rails", "server", "-b", "0.0.0.0"]

3.compose.ymlの作成

touch compose.yml

その後、compose.yml内に

postgresの場合は、

services:
  db:
    image: postgres:latest
    platform: linux/amd64
    environment:
      TZ: Asia/Tokyo
      POSTGRES_PASSWORD: password
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - 5432:5432
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    tty: true
    stdin_open: true
    volumes:
      - .:/app
      - bundle_data:/usr/local/bundle:cached
      - node_modules:/app/node_modules
    environment:
      TZ: Asia/Tokyo
      POSTGRES_PASSWORD: password
    ports:
      - "3000:3000"
    depends_on:
      - db
    env_file:
      - .env
volumes:
  postgres_data:
  bundle_data:
  node_modules:

mysqlの場合は、

services:
  db:
    image: mysql:latest
    platform: linux/amd64
    environment:
      TZ: Asia/Tokyo
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: myapp_development
      MYSQL_USER: myapp
      MYSQL_PASSWORD: myapppassword
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - 3306:3306
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    tty: true
    stdin_open: true
    volumes:
      - .:/app
      - bundle_data:/usr/local/bundle:cached
      - node_modules:/app/node_modules
    environment:
      TZ: Asia/Tokyo
      MYSQL_PASSWORD: password
    ports:
      - "3000:3000"
    depends_on:
      - db
    env_file:
      - .env
volumes:
  mysql_data:
  bundle_data:
  node_modules: