Skip to content

Instantly share code, notes, and snippets.

@ontouchstart
Created October 19, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ontouchstart/e9f20a0510dded930c1fde7f5d87db51 to your computer and use it in GitHub Desktop.
Save ontouchstart/e9f20a0510dded930c1fde7f5d87db51 to your computer and use it in GitHub Desktop.
up:
docker-compose up -d
down:
docker-compose down
rebuild:
docker-compose run web bundle install
docker-compose build
bootstrap:
bash step1.sh
bash step2.sh
bash step3.sh
bash step4.sh
bash step5.sh
#!/bin/bash
cat > Dockerfile <<EOF
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
EOF
#!/bin/bash
cat > entrypoint.sh <<"EOF"
#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"
EOF
#!/bin/bash
cat > docker-compose.yml <<"EOF"
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
EOF
#!/bin/bash
rm -rf app bin config config.ru db lib log package.json public test tmp vendor Gemfile Gemfile.lock
cat > Gemfile <<"EOF"
source 'https://rubygems.org'
gem 'rails', '~>5'
EOF
touch Gemfile.lock
docker-compose run --no-deps web rails new . --force --database=postgresql
docker-compose build
cat > config/database.yml <<"EOF"
default: &default
adapter: postgresql
encoding: unicode
host: db
username: postgres
password: password
pool: 5
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
EOF
#!/bin/bash
docker-compose up -d
sleep 3
docker-compose run web rake db:create
docker-compose down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment