Skip to content
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
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it depend on build-docker? If so, should we also declare the dependency and build the image if it's not built?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and no. if you run it without the image built, it'll fail. But it should run without re-buidling everytime. I can't think of a simple mechanism to trigger the build if it was not done when running

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, I was also on the fence whether it should be a hard requirement. So if the docker image was never built, we still get a somewhat meaningful error message, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% docker run --rm -it -p 127.0.0.1:9292:9292/tcp connectors
Unable to find image 'connectors:latest' locally
docker: Error response from daemon: pull access denied for connectors, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcodes the port, which may not be in alignment with connectors.yml Is that something we need to worry about? Should we also be sure that the docker image can be run with env-vars which overwrite your yaml configs, like we do for our other docker images?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right, we should not hardcore the port. For the env it sounds like a great improvement

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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