DEV Community

dala00
dala00

Posted on • Originally published at crieit.net

4

Dockerでdev.toのLocal環境構築を試した(途中止め)

先日dev.toがGitHubに公開され、オープンソース化されました。ローカル環境の構築方法も公開されていたため、実際に試してみました。あまりPCを汚したくないので今回はdocker-composeを利用して、Dockerで環境を構築してみました。

設定

docker-compose.yml

  • gemとDBのデータはvolumeに保存して永続化
  • DockerHubにあったyarnが入っているrubyの適当なDockerイメージを使った
  • Algolia関連の環境変数は適当に入れておく
version: '2'
volumes:
  bundle:
    driver: local
  db_data:
    driver: local
services:
  db:
    image: postgres
    volumes:
      - db_data:/var/lib/postgresql/data
    expose:
      - 5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
  app:
    image: electrotumbao/ruby-yarn:2.5.1
    volumes:
      - bundle:/usr/local/bundle
      - .:/app
    working_dir: /app
    ports:
      - 3000:3000
    depends_on:
      - db
    environment:
      RAILS_ENV: development
      GITHUB_KEY: aaaa
      GITHUB_SECRET: bbbb
      ALGOLIASEARCH_APPLICATION_ID: 1111
      ALGOLIASEARCH_SEARCH_ONLY_KEY: awefawf
      ALGOLIASEARCH_API_KEY: awefawfe
    tty: true
    stdin_open: true
Enter fullscreen mode Exit fullscreen mode

database.yml

うまいやり方があるのかちょっと分からなかったので、とりあえず直接書き換えておきます。セットアップ時にtestもマイグレーションしているっぽいのでtestも同様の設定をしておく必要があります。

host: db
username: postgres
password: postgres
Enter fullscreen mode Exit fullscreen mode

手順

Dockerコンテナを起動

docker-composeしてDockerコンテナを起動し、中に入ります。

docker-compose up -d
docker-compose exec app bash
Enter fullscreen mode Exit fullscreen mode

色々インストール

gem install bundler
gem install foreman
bundle install
bin/yarn
bin/setup
Enter fullscreen mode Exit fullscreen mode

Algoliaは有料なので、設定に適当な値を入れているのですが、bin/setupの際のSeedの実行でエラーになるっぽいです。ただ、マイグレーションは完了するっぽいので、無視しています。

起動

とりあえずここまでで一応最低限の設定は一通り行っていると思いますので、試しに起動してみます。専用の起動スクリプトがあるようなのでそれを使います。

bin/startup
Enter fullscreen mode Exit fullscreen mode

動いたっぽいのでlocalhost:3000にアクセスしてみます。

You are not connected to the Internet.png

なんか変な画面が出てきました。

良いニュースと悪いニュースがあるんだ。悪いニュースはあんたがオフラインってことさ。いいニュースはここでは絵を書けるんだぜ

というよく分からないメッセージが出てきます。原因はよく分からないのですが、どうもserviceworkerあたりが関係あるかも知れません。

仕方がないので、とりあえずはrailsのサーバーで起動してみます。

bin/rails s
Enter fullscreen mode Exit fullscreen mode

ダウンロード.png

初回は表示までに時間がかかる(?)ようですが一応dev.toっぽい画面が表示されるっぽいです。

まとめ

とりあえずなんとなくdev.toの画面が表示されるところまで試してみました。是非色々な方法でローカル環境を構築してdev.toのcontributeまで試してみてください!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay