From df0b3c7fcc0a34696fac84194f2cac2320ddf91a Mon Sep 17 00:00:00 2001 From: Tarek Ziade Date: Thu, 31 Mar 2022 16:35:29 +0200 Subject: [PATCH] Added Docker support (#65) --- .ci/pipelines/connectors.groovy | 10 ++++++++++ Dockerfile | 25 +++++++++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 3 +++ Makefile | 10 ++++++++-- README.md | 19 +++++++++++++++++++ config/connectors.yml.example | 1 + lib/app/app.rb | 1 + 8 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.ci/pipelines/connectors.groovy b/.ci/pipelines/connectors.groovy index def3abc1..c4b81f29 100644 --- a/.ci/pipelines/connectors.groovy +++ b/.ci/pipelines/connectors.groovy @@ -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', diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..92f5752f --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Gemfile b/Gemfile index 0192667f..67c97a5d 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 573b3ba0..b2fa9bf1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -189,6 +191,7 @@ DEPENDENCIES sinatra sinatra-contrib timecop + tzinfo-data webmock BUNDLED WITH diff --git a/Makefile b/Makefile index 71969f22..6b7b7756 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ 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 @@ -33,7 +33,13 @@ 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 diff --git a/README.md b/README.md index a641e707..00b08c0d 100644 --- a/README.md +++ b/README.md @@ -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)) @@ -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: diff --git a/config/connectors.yml.example b/config/connectors.yml.example index 399a2d1f..db0821a1 100644 --- a/config/connectors.yml.example +++ b/config/connectors.yml.example @@ -5,6 +5,7 @@ revision: "main" # web service http: + host: 0.0.0.0 port: 9292 api_key: changeme deactivate_auth: false diff --git a/lib/app/app.rb b/lib/app/app.rb index 1860a37a..51cc5643 100644 --- a/lib/app/app.rb +++ b/lib/app/app.rb @@ -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']