Skip to content

Instantly share code, notes, and snippets.

@fanktom
Last active September 6, 2019 09: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 fanktom/a0aab94043697f8d9f37d914edd0783f to your computer and use it in GitHub Desktop.
Save fanktom/a0aab94043697f8d9f37d914edd0783f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# create project folder
mkdir $1
cd $1
# create dockerfile
cat >Dockerfile <<EOL
FROM ruby:2.6-alpine
RUN apk add --no-cache --update build-base \
linux-headers \
git \
sqlite-dev \
tzdata
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY . /app
EXPOSE 3000
EOL
# create gemfile to install rails into container
cat >Gemfile <<EOL
source 'https://rubygems.org'
gem 'rails', '~>6'
EOL
# create empty Gemfile.lock
touch Gemfile.lock
# docker-compose
cat >docker-compose.yml <<EOL
version: '3'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
EOL
# install rails in container and create rails app
docker-compose build --no-cache
docker-compose run web rails new . --force --no-deps --database=sqlite3 --api
# install rubygems
docker-compose build
# setup helper scripts, all prefixed with container-*
cat >bin/container-update-gems <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
docker-compose run web bundle update --all
docker-compose run web bundle update --ruby
docker-compose build --pull
EOL
chmod +x bin/container-update-gems
cat >bin/container-restart <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
docker-compose up -d --force-recreate
docker-compose logs -f
EOL
chmod +x bin/container-restart
cat >bin/container-stop <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
EOL
chmod +x bin/container-stop
cat >bin/container-rails <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
docker-compose run web rails \$@
EOL
chmod +x bin/container-rails
#!/usr/bin/env bash
# create project folder
mkdir $1
cd $1
# create dockerfile
cat >Dockerfile <<EOL
FROM ruby:2.6-alpine
RUN apk add --no-cache --update build-base \
linux-headers \
git \
sqlite-dev \
nodejs \
yarn \
tzdata
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY . /app
EXPOSE 3000
EOL
# create gemfile to install rails into container
cat >Gemfile <<EOL
source 'https://rubygems.org'
gem 'rails', '~>6'
EOL
# create empty Gemfile.lock
touch Gemfile.lock
# docker-compose
cat >docker-compose.yml <<EOL
version: '3'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
EOL
# install rails in container and create rails app
docker-compose build --no-cache
docker-compose run web rails new . --force --no-deps --database=sqlite3 --skip-coffee
# install rubygems
docker-compose build
# setup helper scripts, all prefixed with container-*
cat >bin/container-update-gems <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
docker-compose run web bundle update --all
docker-compose run web bundle update --ruby
docker-compose build --pull
EOL
chmod +x bin/container-update-gems
cat >bin/container-restart <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
docker-compose up -d --force-recreate
docker-compose logs -f
EOL
chmod +x bin/container-restart
cat >bin/container-stop <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
EOL
chmod +x bin/container-stop
cat >bin/container-rails <<EOL
#!/usr/bin/env bash
set -xe
docker-compose down
docker-compose run web rails \$@
EOL
chmod +x bin/container-rails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment