Last active
February 25, 2020 02:41
-
-
Save patorash/8b137745037a25f8d86c3956983c51c0 to your computer and use it in GitHub Desktop.
Macの開発環境をDockerにした際のファイル達
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
.circleci | |
.docker | |
.idea | |
.git | |
.github | |
doc | |
.env* | |
.gitignore | |
.ruby-version | |
.slugignore | |
*.dump* |
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
-- .dockerdev/.psqlrc | |
-- 見やすいプロンプトに変更 | |
\set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]%# ' | |
\set PROMPT2 '[more] %R > ' | |
-- Don't display the "helpful" message on startup. | |
\set QUIET 1 | |
-- Show how long each query takes to execute | |
\timing | |
-- デフォルトでは、NULLはスペースとして表示される | |
-- 空白なのかnullなのか?これで違いが見えるようになる | |
\pset null '[NULL]' | |
-- デフォルトでは表形式のフォーマット(1行目がヘッダ)になるが、 | |
-- データが多い時はより読みやすいように拡張テーブル形式で表示 | |
\x auto | |
-- 詳しいエラー表示 | |
\set VERBOSITY verbose | |
-- データベースごとにヒストリファイルを作る | |
\set HISTFILE ~/.psql_history- :DBNAME | |
-- 1行で複数回コマンドが実行されたら、1回だけヒストリに保存 | |
\set HISTCONTROL ignoredups | |
-- キーワード(SELECTなど)を、小文字で入力し始めたとしても | |
-- 大文字に自動変換 | |
\set COMP_KEYWORD_CASE upper | |
\unset QUIET |
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
vim | |
imagemagick | |
ghostscript | |
fontconfig | |
fonts-migmix |
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
# spec/support/capybara.rb | |
Capybara.register_driver :selenium do |app| | |
options = Selenium::WebDriver::Chrome::Options.new | |
options.headless! | |
options.add_argument '--disable-gpu' | |
options.add_argument '--window-size=1680,1050' | |
options.add_argument '--blink-settings=imagesEnabled=false' | |
options.add_argument '--lang=ja' | |
driver = Capybara::Selenium::Driver.new(app, | |
url: ENV.fetch('SELENIUM_DRIVER_URL'), | |
browser: :remote, | |
options: options, | |
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome( | |
login_prefs: { browser: 'ALL' }, | |
loggingPrefs: { browser: 'ALL' }, | |
), | |
) | |
bridge = driver.browser.send(:bridge) | |
path = "session/#{bridge.session_id}/chromium/send_command" | |
bridge.http.call(:post, path, cmd: 'Page.setDownloadBehavior', | |
params: { | |
behavior: 'allow', | |
downloadPath: WaitForDownload::PATH, | |
}) | |
driver | |
end | |
Capybara.configure do |config| | |
config.server_host = "test" | |
config.server_port = 9887 + ENV['TEST_ENV_NUMBER'].to_i | |
config.app_host = "http://#{config.server_host}:#{config.server_port}" | |
config.javascript_driver = :selenium | |
config.default_max_wait_time = ENV['CI'].present? ? 15 : 15 | |
config.ignore_hidden_elements = true | |
config.server = :puma, { Silent: true } | |
end |
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.3' | |
services: | |
app: &app | |
build: | |
context: . | |
dockerfile: ./.dockerdev/Dockerfile | |
args: | |
RUBY_VERSION: '2.6.3' | |
PG_MAJOR: '11' | |
NODE_MAJOR: '13' | |
YARN_VERSION: '1.21.1' | |
BUNDLER_VERSION: '1.17.3' | |
image: app-dev:1.0.0 | |
tmpfs: | |
- /tmp | |
backend: &backend | |
<<: *app | |
stdin_open: true | |
tty: true | |
volumes: | |
- .:/app:cached | |
- rails_cache:/app/tmp/cache | |
- bundle:/bundle | |
- node_modules:/app/node_modules | |
- packs:/app/public/packs | |
- data:/app/data | |
- coverage:/app/coverage | |
- .dockerdev/.psqlrc:/root/.psqlrc:ro | |
environment: | |
TZ: "/usr/share/zoneinfo/Asia/Tokyo" | |
NODE_ENV: ${NODE_ENV:-development} | |
RAILS_ENV: ${RAILS_ENV:-development} | |
BOOTSNAP_CACHE_DIR: /bundle/bootsnap | |
WEBPACKER_DEV_SERVER_HOST: webpacker | |
HISTFILE: /app/log/.bash_history | |
PSQL_HISTFILE: /app/log/.psql_history | |
EDITOR: vi | |
MALLOC_ARENA_MAX: 2 | |
WEB_CONCURRENCY: ${WEB_CONCURRENCY:-1} | |
depends_on: | |
- postgres | |
- redis | |
- elasticsearch | |
- minio | |
- memcached | |
- mailhog | |
runner: | |
<<: *backend | |
command: /bin/bash | |
rails: | |
<<: *backend | |
command: ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] | |
ports: | |
- '3000:3000' | |
test: | |
<<: *backend | |
command: /bin/bash | |
environment: | |
TZ: "/usr/share/zoneinfo/Asia/Tokyo" | |
NODE_ENV: ${NODE_ENV:-development} | |
RACK_ENV: ${RACK_ENV:-test} | |
RAILS_ENV: ${RAILS_ENV:-test} | |
BOOTSNAP_CACHE_DIR: /bundle/bootsnap | |
WEBPACKER_DEV_SERVER_HOST: webpacker | |
HISTFILE: /app/log/.bash_history | |
PSQL_HISTFILE: /app/log/.psql_history | |
SELENIUM_DRIVER_URL: http://chrome:4444/wd/hub | |
depends_on: | |
- postgres | |
- redis | |
- elasticsearch | |
- memcached | |
- chrome | |
resque: | |
<<: *backend | |
command: ["bundle", "exec", "rake", "environment", "resque:work"] | |
environment: | |
TERM_CHILD: 1 | |
QUEUE: "*" | |
postgres: | |
image: mdillon/postgis:11-alpine | |
volumes: | |
- .dockerdev/.psqlrc:/root/.psqlrc:ro | |
- pg_data:/var/lib/postgresql/data | |
- ./log:/root/log:cached | |
environment: | |
PSQL_HISTFILE: /root/log/.psql_history | |
ports: | |
- "5432:5432" | |
healthcheck: | |
test: ["CMD", "pg_isready", "-U", "postgres", "-h", "127.0.0.1"] | |
interval: 5s | |
elasticsearch: | |
image: patorash/elasticsearch-kuromoji:5.6.14-alpine | |
ports: | |
- "9200:9200" | |
- "9300:9300" | |
volumes: | |
- elasticsearch_data:/usr/share/elasticsearch/data | |
environment: | |
ES_JAVA_OPTS: "-Xms512m -Xmx512m" | |
healthcheck: | |
test: ["CMD", "curl --silent --fail localhost:9200/_cluster/health || exit 1"] | |
interval: 60s | |
timeout: 30s | |
retries: 3 | |
redis: | |
image: redis:3.2.12-alpine | |
volumes: | |
- .docker/redis/data:/data | |
ports: | |
- 6379 | |
healthcheck: | |
test: redis-cli ping | |
interval: 10s | |
timeout: 3s | |
retries: 30 | |
minio: | |
image: minio/minio:RELEASE.2020-02-07T23-28-16Z | |
ports: | |
- "9000:9000" | |
command: [server, /data] | |
volumes: | |
- .docker/minio/data:/data | |
environment: | |
MINIO_ACCESS_KEY: access_key | |
MINIO_SECRET_KEY: access_secret | |
healthcheck: | |
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] | |
interval: 30s | |
timeout: 20s | |
retries: 3 | |
memcached: | |
image: memcached:1.5.12-alpine | |
ports: | |
- "11211:11211" | |
healthcheck: | |
test: echo stats | nc 127.0.0.1 11211 | |
interval: 10s | |
retries: 60 | |
mailhog: | |
image: mailhog/mailhog:v1.0.0 | |
ports: | |
- '8025:8025' | |
environment: | |
MH_STORAGE: maildir | |
MH_MAILDIR_PATH: /tmp | |
volumes: | |
- mail_dir:/tmp | |
chrome: | |
image: selenium/standalone-chrome:latest | |
ports: | |
- '4444:4444' | |
webpacker: | |
<<: *app | |
command: ./bin/webpack-dev-server | |
ports: | |
- '3035:3035' | |
volumes: | |
- .:/app:cached | |
- bundle:/bundle | |
- node_modules:/app/node_modules | |
- packs:/app/public/packs | |
environment: | |
NODE_ENV: ${NODE_ENV:-development} | |
RAILS_ENV: ${RAILS_ENV:-development} | |
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0 | |
volumes: | |
postgres: | |
redis: | |
bundle: | |
node_modules: | |
rails_cache: | |
packs: | |
data: | |
coverage: | |
pg_data: | |
mail_dir: | |
elasticsearch_data: |
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
ARG RUBY_VERSION | |
FROM ruby:$RUBY_VERSION | |
ARG PG_MAJOR | |
ARG NODE_MAJOR | |
ARG BUNDLER_VERSION | |
ARG YARN_VERSION | |
# ソースリストにPostgreSQLを追加 | |
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -\ | |
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list | |
# ソースリストにNodeJSを追加 | |
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash - | |
# ソースリストにYarnを追加 | |
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -\ | |
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list | |
# 依存関係をインストール | |
COPY .dockerdev/Aptfile /tmp/Aptfile | |
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade &&\ | |
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends\ | |
build-essential\ | |
postgresql-client-$PG_MAJOR\ | |
nodejs\ | |
yarn=$YARN_VERSION-1\ | |
$(cat /tmp/Aptfile | xargs) &&\ | |
apt-get clean &&\ | |
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* &&\ | |
truncate -s 0 /var/log/*log | |
# bundlerとPATHを設定 | |
ENV LANG=C.UTF-8\ | |
GEM_HOME=/bundle\ | |
BUNDLE_JOBS=4\ | |
BUNDLE_RETRY=3 | |
ENV BUNDLE_PATH $GEM_HOME | |
ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH\ | |
BUNDLE_BIN=$BUNDLE_PATH/bin | |
ENV PATH /app/bin:$BUNDLE_BIN:$PATH | |
# RubyGemsをアップグレードして必要なバージョンのbundlerをインストール | |
RUN gem update --system &&\ | |
gem install bundler:$BUNDLER_VERSION | |
# appコードを置くディレクトリを作成 | |
RUN mkdir -p /app | |
WORKDIR /app | |
COPY .dockerdev/entrypoint.sh /usr/bin/ | |
RUN chmod +x /usr/bin/entrypoint.sh | |
ENTRYPOINT ["entrypoint.sh", "postgres"] |
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/bash | |
set -e | |
# Then exec the container's main process (what's set as CMD in the Dockerfile). | |
host="$1" | |
shift | |
cmd="$@" | |
until pg_isready -h "$host" -U "postgres"; do | |
>&2 echo "Postgres is unavailable - sleeping" | |
sleep 5 | |
done | |
>&2 echo "Postgres is up -executing command" | |
exec $cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment