Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker-compose environment #149

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerdev/.psqlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\set HISTFILE ~/history/psql_history
56 changes: 56 additions & 0 deletions .dockerdev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION-slim-buster

ARG PG_VERSION
ARG MYSQL_VERSION
ARG NODE_VERSION
ARG BUNDLER_VERSION

RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
gnupg2 \
curl \
git \
imagemagick \
libmariadb-dev \
sqlite3 \
libsqlite3-dev \
chromium \
&& rm -rf /var/cache/apt/lists/*

RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_VERSION > /etc/apt/sources.list.d/pgdg.list

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 8C718D3B5072E1F5 \
&& echo "deb http://repo.mysql.com/apt/debian/ buster mysql-"$MYSQL_VERSION > /etc/apt/sources.list.d/mysql.list

RUN curl -sSL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -

RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
libpq-dev \
postgresql-client-$PG_VERSION \
mysql-client \
nodejs \
&& rm -rf /var/lib/apt/lists/*

ENV APP_USER=solidus_starter_frontend_user \
LANG=C.UTF-8 \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3
ENV GEM_HOME=/home/$APP_USER/gems
ENV APP_HOME=/home/$APP_USER/app
ENV PATH=$PATH:$GEM_HOME/bin

RUN useradd -ms /bin/bash $APP_USER

RUN gem update --system \
&& gem install bundler:$BUNDLER_VERSION \
&& chown -R $APP_USER:$(id -g $APP_USER) /home/$APP_USER/gems

USER $APP_USER

RUN mkdir -p /home/$APP_USER/history

WORKDIR /home/$APP_USER/app
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ spec/examples.txt
.rvmrc
.ruby-version
.ruby-gemset
.env
28 changes: 14 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
gem 'solidus_core', github: 'solidusio/solidus', branch: branch
gem 'solidus_api', github: 'solidusio/solidus', branch: branch
gem 'solidus_backend', github: 'solidusio/solidus', branch: branch
gem 'solidus_sample', github: 'solidusio/solidus', branch: branch
gem 'solidus_i18n', github: 'solidusio/solidus_i18n', branch: branch
solidus_repo = ENV.fetch('SOLIDUS_REPO', 'solidusio/solidus')
solidus_branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
solidus_i18n_repo = ENV.fetch('SOLIDUS_I18N_REPO', 'solidusio/solidus_i18n')
solidus_i18n_branch = ENV.fetch('SOLIDUS_I18N_BRANCH', 'master')
gem 'solidus_core', github: solidus_repo, branch: solidus_branch
gem 'solidus_api', github: solidus_repo, branch: solidus_branch
gem 'solidus_backend', github: solidus_repo, branch: solidus_branch
gem 'solidus_sample', github: solidus_repo, branch: solidus_branch
gem 'solidus_i18n', github: solidus_i18n_repo, branch: solidus_i18n_branch

# Needed to help Bundler figure out how to resolve dependencies,
# otherwise it takes forever to resolve them.
# See https://github.com/bundler/bundler/issues/6677
gem 'rails', '>0.a'

case ENV['DB']
when 'mysql'
gem 'mysql2'
when 'postgresql'
gem 'pg'
else
gem 'sqlite3'
end
gem 'mysql2' if ENV['DB'] == 'mysql' || ENV['DB_ALL']

gem 'pg' if ENV['DB'] == 'postgresql' || ENV['DB_ALL']

gem 'sqlite3' if !%w[mysql postgresql].include?(ENV['DB']) || ENV['DB_ALL']

gemspec

Expand Down
27 changes: 27 additions & 0 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ set -e
case "$DB" in
postgres|postgresql)
RAILSDB="postgresql"
HOST=${DB_POSTGRES_HOST:-${DB_HOST}}
USERNAME=$DB_USERNAME
PASSWORD=$DB_PASSWORD
;;
mysql)
RAILSDB="mysql"
HOST=${DB_MYSQL_HOST:-${DB_HOST}}
USERNAME=$DB_USERNAME
PASSWORD=$DB_PASSWORD
;;
sqlite|'')
RAILSDB="sqlite3"
Expand Down Expand Up @@ -62,6 +68,27 @@ gem '$extension_name', path: '..'
gem 'solidus_auth_devise'
RUBY

replace_in_database_yml() {
if [ $RAILSDB = "postgresql" ]; then
sed -i.bck "/^ adapter:/a \ \ $1: $2" config/database.yml
elif [ $RAILSDB = "mysql" ]; then
sed -i.bck "s/^ $1:.*/\ \ $1: $2/" config/database.yml
fi
if [ -f config/database.yml.bck ]; then
rm -f config/database.yml.bck
fi
}

if [ ${HOST} ]; then
replace_in_database_yml "host" $HOST
fi
if [ ${USERNAME} ]; then
replace_in_database_yml "username" $USERNAME
fi
if [ ${PASSWORD} ]; then
replace_in_database_yml "password" $PASSWORD
fi

unbundled bundle install --gemfile Gemfile

unbundled bundle exec rake db:drop db:create
Expand Down
64 changes: 64 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: '3.7'

services:
mysql:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- mysql:/var/lib/mysql:cached

postgres:
image: postgres:13.2
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: password
POSTGRES_DB: solidus_starter_frontend_solidus_test
volumes:
- postgres:/var/lib/postgresql/data:cached

app:
build:
context: .dockerdev
dockerfile: Dockerfile
args:
RUBY_VERSION: "2.7.2"
PG_VERSION: 13
NODE_VERSION: 14
MYSQL_VERSION: "8.0"
BUNDLER_VERSION: 2
image: solidus_starter_frontend-0.1.0
command: bash -c "(bundle check || bundle) && tail -f /dev/null"
environment:
CAPYBARA_JS_DRIVER: apparition_docker_friendly
DB_USERNAME: root
DB_PASSWORD: password
DB_ALL: "1"
DB_MYSQL_HOST: mysql
DB_POSTGRES_HOST: postgres
HISTFILE: "/home/solidus_starter_frontend_user/history/bash_history"
MYSQL_HISTFILE: "/home/solidus_starter_frontend_user/history/mysql_history"
# TODO: Remove repo/branch config when PR is merged
SOLIDUS_REPO: 'nebulab/solidus'
SOLIDUS_BRANCH: 'docker'
ports:
- "${SANDBOX_PORT:-3000}:${SANDBOX_PORT:-3000}"
volumes:
- .:/home/solidus_starter_frontend_user/app:delegated
- bundle:/home/solidus_starter_frontend_user/gems:cached
- history:/home/solidus_starter_frontend_user/history:cached
- .dockerdev/.psqlrc:/home/solidus_starter_frontend_user/.psqlrc:cached
tty: true
stdin_open: true
tmpfs:
- /tmp
depends_on:
- mysql
- postgres

volumes:
bundle:
history:
postgres:
mysql:
33 changes: 30 additions & 3 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ This document aims to give some extra information for developers that are going
to contribute to our `solidus_starter_frontend` component.

### Testing the extension
First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to
building the dummy app if it does not exist, then it will run specs. The dummy
app can be regenerated by using `bin/rake extension:test_app`.
First bundle your dependencies (or use [docker](#docker-development)), then run
`bin/rake`. `bin/rake` will default to building the dummy app if it does not
exist, then it will run specs. The dummy app can be regenerated by using
`bin/rake extension:test_app`.

```shell
bin/rake
Expand Down Expand Up @@ -84,3 +85,29 @@ The tool internally works in this way:
- remote GIT source is updated using the parameters provided by the config file;
- compare process is executed and a hash for each file is calculated;
- if they match the hashes saved in the configuration there are no differences.

### Docker development

If you are a docker user you can wake up the project as usual with:

```bash
docker-compose up -d
```

Wait for all the dependencies to be installed. You can check progress with `docker-compose logs -f app`.

Then you can dispatch commands to the `app` container:

```bash
docker-compose exec app bin/rake
```

When running the [sandbox application](#running-the-sandbox), take into account
that you need to bind to `0.0.0.0`. By default, port `3000` is exposed but you
can changed it through `SANDBOX_PORT` environment variable:

```bash
SANDBOX_PORT=4000 docker-compose up -d
docker-compose exec app bin/sandbox
docker-compose exec app bin/rails server --binding 0.0.0.0 --port 4000
```
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@

SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStarterFrontend::Engine)

Capybara.register_driver :apparition_docker_friendly do |app|
opts = {
headless: true,
browser_options: [
:no_sandbox,
:disable_gpu,
{ disable_features: 'VizDisplayCompositor' }
]
}
Capybara::Apparition::Driver.new(app, opts)
end

RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = false
Expand Down