-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docker-compose development environment
This allows a quick hands-on approach to contributing to Solidus: ```bash docker-compose up -d ``` The ruby version in the image can be configured through the `ruby_version` docker build argument (at this point, 2.7.2 is used by default): ```bash docker-compose build --build-arg ruby_version=2.6 app docker-compose up -d ``` The rails version can be set when the project is booted up: ```bash RAILS_VERSION='~> 5.0' docker-compose up -d ``` Tests can be run setting the corresponding `DB` environment variable: ```bash docker-compose exec app bin/rspec docker-compose exec app env DB=postgres bin/rspec docker-compose exec app env DB=mysql bin/rspec ``` By default, port `3000` is exposed to allow installing the sandbox application as usual. However, it can be configured through the `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 ``` Some considerations: - The file `database.yml` in the Dummy app has been changed to accommodate the docker-compose setup. Taking the occasion it has been refactor to be more consistent. - The simplest configuration forces us to use `root` as the postgres user. MySQL's docker image creates the `root` user and grants all the privileges to it. Using the same user (and password) for both engines simplifies `database.yml` configuration. In case another username was to be chosen, MySQL wouldn't allow it to create the databases needed to do the testing. If we decide to change it in the future, we'll need to provision a SQL script to the image on boot time: ``` services: mysql: # ... volumes: - ./docker/provision/mysql/init:/docker-entrypoint-initdb.d ``` ```sql -- docker/provision/mysql/init/01_databases.sql CREATE DATABASE IF NOT EXISTS `solidus_api_test`; CREATE DATABASE IF NOT EXISTS `solidus_backend_test`; CREATE DATABASE IF NOT EXISTS `solidus_core_test`; CREATE DATABASE IF NOT EXISTS `solidus_frontend_test`; GRANT ALL ON `solidus_api_test`.* TO 'solidus_user'@'%'; GRANT ALL ON `solidus_backend_test`.* TO 'solidus_user'@'%'; GRANT ALL ON `solidus_core_test`.* TO 'solidus_user'@'%'; GRANT ALL ON `solidus_frontend_test`.* TO 'solidus_user'@'%' ``` - Dummy application's `database.yml` file no longer checks whether the `CI` environment variable is set. Instead, it's CircleCI configuration the one that sets `DB_USERNAME` to `root`. This is part of the work of making the file more consistent. - MySQL and Postgres hosts are now configurable through `DB_MYSQL_HOST` & `DB_POSTGRES_HOST`. This allows us link to both services from the `app` container. - At first, I explored having two different images, one for each database engine. But I find the final solution simpler. However, it's another option to consider. - The `Gemfile` has been modified to allow mysql2, postgres & sqlite3/fast_sqlite gems to be installed at the same time. They will install everything in case the `DB_ALL` environment variable is set (as we are doing in the docker-compose file). This change should be backward compatible. - A new selenium capybara driver has been added to make tests pass inside the docker container.
- Loading branch information
1 parent
3ba6bc6
commit 7888d51
Showing
13 changed files
with
415 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\set HISTFILE ~/history/psql_history |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 \ | ||
chromium-driver \ | ||
&& 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_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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ tags | |
node_modules | ||
yarn.lock | ||
package-lock.json | ||
.env |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.