Skip to content

Commit 23091ac

Browse files
chloelbnDevinCodes
andauthored
chore(docker): dockerize the repository (#437)
* chore(docker): dockerize the repository * chore(docker): improves readme * chore(docker): fixes typos * chore(docker): use env instead of args * Apply suggestions from code review Co-authored-by: Devin <[email protected]> Co-authored-by: Devin <[email protected]>
1 parent 85f93b4 commit 23091ac

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

.dockerignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# rspec failure tracking
2+
.rspec_status
3+
4+
## MAC OS
5+
.DS_Store
6+
.idea/
7+
8+
## TEXTMATE
9+
*.tmproj
10+
tmtags
11+
12+
## EMACS
13+
*~
14+
\#*
15+
.\#*
16+
17+
## VIM
18+
*.swp
19+
20+
## PROJECT::GENERAL
21+
coverage
22+
rdoc
23+
pkg
24+
.rvmrc
25+
/.bundle/
26+
/.yardoc
27+
/_yardoc/
28+
/coverage/
29+
/doc/
30+
/pkg/
31+
/spec/reports/
32+
/tmp/
33+
34+
## PROJECT::SPECIFIC
35+
spec/integration_spec_conf.rb
36+
data.sqlite3
37+
38+
debug.log

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ spec/integration_spec_conf.rb
3737
data.sqlite3
3838

3939
debug.log
40+
.ruby-version

DOCKER_README.MD

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
This guide shows our recommended recommended way of installing Docker on your OS X machine.
2+
3+
## Install docker
4+
5+
First install Docker using [Homebrew](https://brew.sh/)
6+
```
7+
$ brew install docker
8+
```
9+
10+
You can install [Docker Desktop](https://docs.docker.com/get-docker/) if you wish, or use the `docker-machine` command to work with your Docker containers. This guide assumes you use the `docker-machine` command.
11+
12+
## Setup your Docker
13+
14+
Install `docker-machine`
15+
```
16+
$ brew install docker-machine
17+
```
18+
19+
Then install [VirtualBox](https://www.virtualbox.org/) using [Homebrew Cask](https://github.com/Homebrew/homebrew-cask) to get a driver for your Docker machine
20+
```
21+
$ brew cask install virtualbox
22+
```
23+
24+
You may need to enter your password and authorize the application through `System Settings` > `Security & Privacy`.
25+
26+
Create a new machine, and set it up as default, and connect your shell to the machine with the following commands:
27+
28+
```
29+
$ docker-machine create --driver virtualbox default
30+
$ docker-machine env default
31+
$ eval "$(docker-machine env default)"
32+
```
33+
34+
Now you're all setup to use our provided Docker image!
35+
36+
## Build the image
37+
38+
```bash
39+
docker build -t algolia-ruby .
40+
```
41+
42+
## Run the image
43+
44+
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).
45+
You can set them up directly in the command
46+
47+
```bash
48+
docker run -it --rm --env ALGOLIA_APPLICATION_ID_1=XXXXXX [...] -v $PWD:/app -w /app algolia-ruby bash
49+
```
50+
51+
But we advise you 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 retrieve your variables.
52+
53+
```bash
54+
### For external contributors, only the following env variables should be enough
55+
docker run -it --rm --env ALGOLIA_APPLICATION_ID_1 \
56+
--env ALGOLIA_ADMIN_KEY_1 \
57+
--env ALGOLIA_SEARCH_KEY_1 \
58+
-v $PWD:/app -w /app algolia-ruby bash
59+
60+
### This is needed only to run the full test suite
61+
docker run -it --rm --env ALGOLIA_APPLICATION_ID_1 \
62+
--env ALGOLIA_ADMIN_KEY_1 \
63+
--env ALGOLIA_SEARCH_KEY_1 \
64+
--env ALGOLIA_APPLICATION_ID_2 \
65+
--env ALGOLIA_ADMIN_KEY_2 \
66+
--env ALGOLIA_APPLICATION_ID_MCM \
67+
--env ALGOLIA_ADMIN_KEY_MCM \
68+
-v $PWD:/app -w /app algolia-ruby bash
69+
```
70+
71+
Once the container is up, you can edit files directly in your IDE: changes will be mirrored in the image.
72+
73+
Lastly to launch the tests, you can use one of the following commands
74+
```shell script
75+
# run only the unit tests
76+
bundle exec rake test:unit
77+
78+
# run only the integration tests
79+
bundle exec rake test:integration
80+
81+
# run the whole test suite
82+
bundle exec rake test:all
83+
84+
# run a single test
85+
bundle exec rake test TEST=/full/path/to/test.rb TESTOPTS="--name=test_name"
86+
```
87+
88+
Feel free to contact us if you have any questions.

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM ruby:2.6.3
2+
3+
RUN gem install bundler
4+
5+
WORKDIR /app
6+
COPY . /app/
7+
RUN bundle install

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ Encountering an issue? Before reaching out to support, we recommend heading to o
5959

6060
If you were using the v1 and wish to update to v2, please follow our [Upgrade Guide](upgrade_guide.md)
6161

62+
## Use the Dockerfile
63+
64+
If you wish to contribute to the repository but would like to avoid installing the dependencies locally, we provided you with a Docker image.
65+
Please check our [dedicated guide](DOCKER_README.MD) to learn more.
66+
6267
## 📄 License
6368

6469
Algolia Ruby API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).

0 commit comments

Comments
 (0)