Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Added Docker support (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekziade committed Mar 31, 2022
1 parent 54f888d commit df0b3c7
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .ci/pipelines/connectors.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ eshPipeline(
},
match_on_all_branches: true,
],
[
name: 'Docker',
type: 'script',
script: {
eshWithRbenv {
sh 'make build-docker'
}
},
match_on_all_branches: true,
],
[
name: 'Packaging',
type: 'script',
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ubuntu:focal

WORKDIR /app
COPY . /app

# installing all system dependencies, yq, ruby-build and rbenv
RUN apt-get update && \
apt-get install --yes --no-install-recommends uuid-runtime curl ca-certificates git make build-essential libssl-dev libreadline-dev zlib1g-dev && \
rm -rf /var/lib/apt/lists/* && \
curl -L https://github.com/mikefarah/yq/releases/download/v4.24.2/yq_linux_amd64.tar.gz | tar -xzvf - && mv yq_linux_amd64 /usr/bin/yq && \
git clone https://github.com/rbenv/rbenv.git ~/.rbenv && \
curl -L https://github.com/sstephenson/ruby-build/archive/v20220324.tar.gz | tar -zxvf - -C /tmp/ && \
cd /tmp/ruby-build-* && ./install.sh

# set the env
ENV PATH /root/.rbenv/bin:/root/.rbenv/shims:$PATH
RUN echo 'eval "$(rbenv init -)"' >> .bashrc
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh # or /etc/profile

# run the make file to generate an api key an install the app
RUN make install api_key


EXPOSE 9292
CMD ["make", "run"]
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'bundler', '2.2.33'
gem 'activesupport', '5.2.6'
gem 'bson', '~> 4.2.2'
gem 'mime-types', '= 3.1'
gem 'tzinfo-data', '= 1.2022.1'

group :test do
gem 'rspec-collection_matchers', '~> 1.2.0'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ GEM
timecop (0.9.4)
tzinfo (1.2.9)
thread_safe (~> 0.1)
tzinfo-data (1.2022.1)
tzinfo (>= 1.0.0)
unicode-display_width (2.1.0)
webmock (3.14.0)
addressable (>= 2.8.0)
Expand Down Expand Up @@ -189,6 +191,7 @@ DEPENDENCIES
sinatra
sinatra-contrib
timecop
tzinfo-data
webmock

BUNDLED WITH
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ build:

install:
rbenv install -s
- gem install bundler -v 2.2.33
- gem install bundler -v 2.2.33 && rbenv rehash
bundle install --jobs 1
cp -n config/connectors.yml.example config/connectors.yml || true

run:
${YQ} e ".revision = \"$(shell git rev-parse HEAD)\"" -i config/connectors.yml
${YQ} e ".repository = \"$(shell git config --get remote.origin.url)\"" -i config/connectors.yml
${YQ} e ".version = \"$(shell script/version.sh)\"" -i config/connectors.yml
cd lib/app; bundle exec rackup config.ru
cd lib/app; bundle exec rackup --host 0.0.0.0 config.ru

build-docker:
docker build -t connectors .

run-docker:
docker run --rm -it -p 127.0.0.1:9292:9292/tcp connectors

console:
cd lib/app; bundle exec irb -r ./console.rb
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Note: The connector framework is a tech preview feature. Tech preview features a


### System Requirements

You can run the application using Docker or directly on your system.

For the latter you will need:
- Ruby (see [.ruby-version](.ruby-version))
- bundler 2.2.29
- yq (see [yq installation](https://github.com/mikefarah/yq#install))
Expand All @@ -34,6 +38,21 @@ make run
Consumers will need to use the `api_key` string as the password in
the basic Authorization header.

### Running a with Docker
You can run the web server using our Dockerfile.

First, build the Docker image with:
```shell
make build-docker
```

The stdout will display the generated API key.

Then, you can run the server within Docker with:
```shell
make run-docker
```

### Validating your webserver
You can use any REST client library, or `curl` to hit your webserver once it is up and running. Try:

Expand Down
1 change: 1 addition & 0 deletions config/connectors.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ revision: "main"

# web service
http:
host: 0.0.0.0
port: 9292
api_key: changeme
deactivate_auth: false
Expand Down
1 change: 1 addition & 0 deletions lib/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConnectorsWebApp < Sinatra::Base
configure do
set :raise_errors, false
set :show_exceptions, false
set :bind, settings.http['host']
set :port, settings.http['port']
set :api_key, settings.http['api_key']
set :deactivate_auth, settings.http['deactivate_auth']
Expand Down

0 comments on commit df0b3c7

Please sign in to comment.