From d70b408d2eb6cb90fcbeba3042bd5e2a3bbddcdf Mon Sep 17 00:00:00 2001 From: Chloe Liban Date: Wed, 18 Nov 2020 15:17:58 +0100 Subject: [PATCH] chore(docker): containerize repo --- .dockerignore | 24 ++++++++++++++++ DOCKER_README.MD | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 7 +++++ README.md | 9 +++--- 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 DOCKER_README.MD create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..7ad410f3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,24 @@ +## MAC OS +.DS_Store + +## TEXTMATE +*.tmproj +tmtags + +## EMACS +*~ +\#* +.\#* + +## VIM +*.swp + +## PROJECT::GENERAL +coverage +rdoc +pkg +.rvmrc + +## PROJECT::SPECIFIC +data.sqlite3 +sequel_data.sqlite3 diff --git a/DOCKER_README.MD b/DOCKER_README.MD new file mode 100644 index 00000000..af4f0d57 --- /dev/null +++ b/DOCKER_README.MD @@ -0,0 +1,72 @@ +In this page you will find our recommended way of installing Docker on your machine. +This guide is made for OSX users. + +## Install docker + +First install Docker using [Homebrew](https://brew.sh/) +``` +$ brew install docker +``` + +You can then install [Docker Desktop](https://docs.docker.com/get-docker/) if you wish, or use `docker-machine`. As we prefer the second option, we will only document this one. + +## Setup your docker + +Install `docker-machine` +``` +$ brew install docker-machine +``` + +Then install [VirtualBox](https://www.virtualbox.org/) with [Homebrew Cask](https://github.com/Homebrew/homebrew-cask) to get a driver for your Docker machine +``` +$ brew cask install virtualbox +``` + +You may need to enter your password and authorize the application in your `System Settings` > `Security & Privacy`. + +Create now a new machine, set it up as default and connect your shell to it (here we use zsh. The commands should anyway be displayed in each steps' output) + +``` +$ docker-machine create --driver virtualbox default +$ docker-machine env default +$ eval "$(docker-machine env default)" +``` + +Now you're all setup to use our provided Docker image! + +## Build the image + +```bash +docker build -t algolia-rails . +``` + +## Run the image + +You need to provide few environment variables at runtime to be able to run the [Common Test Suite](https://github.com/algolia/algoliasearch-client-specs/tree/master/common-test-suite). +You can set them up directly in the command: + +```bash +docker run -it --rm --env ALGOLIA_APP_ID=XXXXXX [...] -v $PWD:/app -w /app algolia-rails bash +``` + +However, we advise you to export them in your `.bashrc` or `.zshrc`. That way, you can use [Docker's shorten syntax](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) to set your variables. + +```bash +docker run -it --rm --env ALGOLIA_APPLICATION_ID \ + --env ALGOLIA_API_KEY \ +-v $PWD:/app -w /app algolia-rails bash +``` + +Once your container is running, any changes you make in your IDE are directly reflected in the container. + +To launch the tests, you can use one of the following commands +```shell script + +# run the whole test suite +bundle exec rspec + +# run a single test +bundle exec rspec ./path/to/test_spec.rb:#line_number +``` + +Feel free to contact us if you have any questions. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..23fc56cc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM ruby:2.6.3 + +RUN gem install bundler + +WORKDIR /app +COPY . /app/ +RUN bundle install diff --git a/README.md b/README.md index 3e1bd875..cc2a5959 100644 --- a/README.md +++ b/README.md @@ -1184,12 +1184,11 @@ end ``` +## ❓ Troubleshooting -# Troubleshooting +Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/) where you will find answers for the most common issues and gotchas with the client. +## Use the Dockerfile -## Frequently asked questions - -Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/framework-integration/rails/troubleshooting/faq/) where you will find answers for the most common issues and gotchas with the gem. - +If you want to contribute to this project without installing all its dependencies, you can use our Docker image. Please check our [dedicated guide](DOCKER_README.MD) to learn more.