how to write the Dockerfile for a Ruby Capybara scraper? - ruby

I am trying to write a Dockerfile to run a Ruby Capybara scraper on a docker container. I tested the following code on my host OS. But it is making an error on a docker container.
Dockerfile
FROM ruby:2.6.6
RUN apt-get update -y && \
apt-get install -y xvfb
RUN wget https://ftp.mozilla.org/pub/firefox/releases/80.0.1/linux-x86_64/en-US/firefox-80.0.1.tar.bz2
RUN tar -xjf firefox-80.0.1.tar.bz2
RUN mv firefox /opt/firefox80
RUN ln -s /opt/firefox80/firefox /usr/bin/firefox
RUN ls /opt/firefox80
RUN wget -N https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz
RUN tar -xvzf geckodriver-v0.27.0-linux64.tar.gz
RUN chmod +x geckodriver
RUN mv -f geckodriver /usr/local/share/geckodriver
RUN ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver
RUN ln -s /usr/local/share/geckodriver /usr/bin/geckodriver
RUN mkdir capybara
WORKDIR /capybara/
COPY . /capybara
RUN bundle install
main.rb
require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'
include Capybara::DSL
Capybara.register_driver :selenium_headless_firefox do |app|
browser_options = ::Selenium::WebDriver::Firefox::Options.new()
browser_options.args << '--headless'
Capybara::Selenium::Driver.new(
app,
browser: :firefox,
options: browser_options
)
end
target = "https://maps.google.com/?cid=13666314335012854449"
session = Capybara::Session.new(:selenium_headless_firefox)
session.visit(target)
Gemfile
source 'https://rubygems.org'
gem 'selenium-webdriver'
gem 'capybara', '~>3.30'
gem 'geckodriver-helper'
Error Message on Docker
/usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/response.rb:72:in `assert_ok': invalid argument: can't kill an exited process (Selenium::WebDriver::Error::UnknownError)
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/common.rb:88:in `new'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/common.rb:88:in `create_response'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/default.rb:114:in `request'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/bridge.rb:102:in `create_session'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/firefox/marionette/driver.rb:44:in `initialize'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/firefox/driver.rb:33:in `new'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/firefox/driver.rb:33:in `new'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/driver.rb:54:in `for'
from /usr/local/bundle/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver.rb:88:in `for'
from /usr/local/bundle/gems/capybara-3.33.0/lib/capybara/selenium/driver.rb:52:in `browser'
from /usr/local/bundle/gems/capybara-3.33.0/lib/capybara/selenium/driver.rb:71:in `visit'
from /usr/local/bundle/gems/capybara-3.33.0/lib/capybara/session.rb:278:in `visit'
This is what I get when I run the main.rb file on a docker container. I am looking forward to any help from the developer community.
I ran the main.rb file by docker run [docker_image] ruby main.rb

The issue is not with Capybara, but with Firefox - the tar.bz2 file you download does not contain its dependencies, which causes it to crash. The easiest solution is to install it via apt. Assuming all your files are in the same directory your Dockerfile should look like:
FROM ruby:2.6.6
WORKDIR /app
COPY . .
RUN apt-get update -y && \
apt-get install -y xvfb firefox-esr && \
wget -N https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz && \
tar -xvzf geckodriver-v0.27.0-linux64.tar.gz && \
chmod +x geckodriver && \
mv -f geckodriver /usr/local/share/geckodriver && \
ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver && \
ln -s /usr/local/share/geckodriver /usr/bin/geckodriver && \
bundle install && \
apt-get clean && \
rm geckodriver-v0.27.0-linux64.tar.gz && \
rm -rf /var/lib/apt/lists/*
CMD [ "ruby", "/app/main.rb" ]
Then you can run:
docker build -t capybara:latest . # Build image
docker run -it --rm --env DISPLAY=$DISPLAY --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --net=host capybara:latest firefox # Verify Firefox works
docker run -it --rm capybara:latest # Run your script
Note: The second command will only work on Linux, running dockerized Linux GUI applications on Windows is a bit more difficult and requires some additional setup.
Edit:
There is no such thing as installing something
"on Docker". Docker is not an OS. It's an application containerization framework. It can run various operating systems inside the containers (or no OS at all - see base image). Thhat means method of installing something inside a Docker image (or container - not recommended) depends on what's already installed.
In this case your base image ruby:2.6.6 is based on a Debian Buster image (see Dockerfile), so you need to install the browser you need the way you would on regular desktop or server install of the system.
Debian Buster does not come with Chrome, because it's not open source. To install it's open source equivalent - Chromium - modify your Dockerfile as follows:
FROM ruby:2.6.6
WORKDIR /app
COPY . .
RUN apt-get update -y && \
apt-get install -y xvfb chromium && \
wget -N https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz && \
tar -xvzf geckodriver-v0.27.0-linux64.tar.gz && \
chmod +x geckodriver && \
mv -f geckodriver /usr/local/share/geckodriver && \
ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver && \
ln -s /usr/local/share/geckodriver /usr/bin/geckodriver && \
bundle install && \
apt-get clean && \
rm geckodriver-v0.27.0-linux64.tar.gz && \
rm -rf /var/lib/apt/lists/*
CMD [ "ruby", "/app/main.rb" ]
If you really need Chrome, follow the official documentation (keeping in mind you need to remove archive files after installation). With that said the Dockerfile for Chrome would be:
FROM ruby:2.6.6
WORKDIR /app
COPY . .
RUN apt-get update -y && \
apt-get install -y xvfb && \
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt install -y ./google-chrome-stable_current_amd64.deb && \
wget -N https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz && \
tar -xvzf geckodriver-v0.27.0-linux64.tar.gz && \
chmod +x geckodriver && \
mv -f geckodriver /usr/local/share/geckodriver && \
ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver && \
ln -s /usr/local/share/geckodriver /usr/bin/geckodriver && \
bundle install && \
apt-get clean && \
rm google-chrome-stable_current_amd64.deb && \
rm geckodriver-v0.27.0-linux64.tar.gz && \
rm -rf /var/lib/apt/lists/*
CMD [ "ruby", "/app/main.rb" ]

Related

multi-stage docker build with bundler

ARG RUBY_VERSION=3.1.0
ARG IMAGE_OS=slim-buster
FROM ruby:${RUBY_VERSION}-${IMAGE_OS} as prod-gem-base
ENV APP_ENVIRONMENT=production
ENV RACK_ENV=production
ARG CI_ACCESS_TOKEN
WORKDIR /contract-service
RUN apt-get update && apt-get install -qqy build-essential ca-certificates tzdata shared-mime-info git curl openssh-client libpq-dev && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
gem install bundler:2.3.13 && \
bundle config --global frozen 1 && \
bundle config set without 'development test' && \
mkdir -p -m 600 $HOME/.ssh && ssh-keyscan gitlab.xxx.de >> $HOME/.ssh/known_hosts && \
if [ -n $CI_ACCESS_TOKEN ]; then git config --global url."https://gitlab-ci-token:${CI_ACCESS_TOKEN}#gitlab.xxx.de /".insteadOf git#gitlab.xxx.de: ; fi
COPY Gemfile Gemfile.lock ./
RUN --mount=type=ssh bundle install --jobs 20 --retry 5 && \
bundle clean --force && \
rm -rf /usr/local/bundle/cache/*.gem && \
find /usr/local/bundle/gems/ -name "*.c" -delete && \
find /usr/local/bundle/gems/ -name "*.o" -delete
ARG RUBY_VERSION
ARG IMAGE_OS
FROM ruby:${RUBY_VERSION}-${IMAGE_OS} as prod-core-base
ENV APP_ENVIRONMENT=production
ENV RACK_ENV=production
WORKDIR /contract-service
RUN mkdir -p /tmp/pids && apt-get update && apt-get install -qqy --no-install-recommends shared-mime-info openssh-client libpq-dev && \
COPY --from=prod-gem-base /usr/local/bundle/ /usr/local/bundle/
COPY . .
EXPOSE 3005
CMD ["bundle", "exec", "puma", "--pidfile", "/tmp/pids/server.pid", "-b", "tcp://0.0.0.0", "-p", "3005"]
I am not sure how many ruby people are here. I am creating an with multi-stage build to cache the gems. I am building a production image but when the container is run the bundler outputs error as follows.
bundler: failed to load command: puma (/usr/local/bundle/bin/puma)
cntrct-contract.1.dfhae8xfhdip#stage-app01-ruh2 | /usr/local/bundle/gems/bundler-2.3.13/lib/bundler/definition.rb:486:in `materialize': Could not find rubocop-1.31.2, byebug-11.1.3, simplecov-0.21.2, simplecov-cobertura-2.1.0, webmock-3.13.0, cucumber-8.0.0, rspec-3.11.0, rspec-core-3.11.0, rspec_junit_formatter-0.5.1, rack-test-2.0.2, json-2.6.2, parallel-1.22.1, parser-3.1.2.0, rainbow-3.1.1, regexp_parser-2.5.0, rubocop-ast-1.19.1, ruby-progressbar-1.11.0, unicode-display_width-2.2.0, docile-1.4.0, simplecov-html-0.12.3, simplecov_json_formatter-0.1.4, crack-0.4.5, hashdiff-1.0.1, builder-3.2.4, cucumber-ci-environment-9.0.4, cucumber-core-11.0.0, cucumber-cucumber-expressions-15.2.0, cucumber-gherkin-23.0.1, cucumber-html-formatter-19.2.0, cucumber-messages-18.0.0, diff-lcs-1.5.0, multi_test-1.1.0, sys-uname-1.2.2, rspec-expectations-3.11.0, rspec-mocks-3.11.1, rspec-support-3.11.0, ast-2.4.2, cucumber-tag-expressions-4.1.0, ffi-1.15.5 in any of the sources (Bundler::GemNotFound)
cntrct-contract.1.dfhae8xfhdip#stage-app01-ruh2 | from /usr/local/bundle/gems/bundler-2.3.13/lib/bundler/definition.rb:191:in `specs'
cntrct-contract.1.8tfk50ss339q#stage-app01-ruh2 | from /usr/local/bundle/bin/bundle:25:in `<main>'
cntrct-contract.1.dfhae8xfhdip#stage-app01-ruh2 | from /usr/local/bundle/gems/bundler-2.3.13/lib/bundler/definition.rb:239:in `specs_for'
cntrct-contract.1.dfhae8xfhdip#stage-app01-ruh2 | from /usr/local/bundle/gems/bundler-2.3.13/lib/bundler/runtime.rb:18:in `setup'
cntrct-contract.1.dfhae8xfhdip#stage-app01-ruh2 | from /usr/local/bundle/gems/bundler-2.3.13/lib/bundler.rb:151:in `setup'
cntrct-contract.1.dfhae8xfhdip#stage-app01-ruh2 | from /usr/local/bundle/gems/bundler-2.3.13/lib/bundler/setup.rb:20:in `block in <top (required)>'
The issues is bundler is trying to load the development and test related gems which is not in the final image. Can someone tell me how to do it correctly with multi-stage docker build ?
Update: if I add RUN bundle config set without 'development test' && bundle after the COPY .. then everything works. I still didn't get the original issue!!! What am I missing ?

High Latency is being observed in AWS ARM Graviton Processor in Comparison to AMD Processor for ASGI based Django Application

I am running an Asgi-based Django Application(Rest Framework) using AWS Kubernetes in the production environment. Everything is running fine at AMD Processor(c5.2xlarge, c5.4xlarge). To decrease the cost we are trying to migrate the application to AWS Graviton Processor(c6g.2xlarge, c6g.4xlarge). But we are observing an increase in the 90% latency to 10X.
The command used for running the application -
DD_DJANGO_INSTRUMENT_MIDDLEWARE=false ddtrace-run gunicorn --workers 1 --worker-tmp-dir /dev/shm --log-file=- --thread 2 --bind :8080 --log-level INFO --timeout 5000 asgi:application -k uvicorn.workers.UvicornWorker
I have one more application that is WSGI based and it's working fine at the graviton processor.
Attaching the docker code -
FROM python:3.9-slim
RUN apt update -y
RUN mv /var/lib/dpkg/info/libc-bin.* /tmp/ && apt install libc-bin && mv /tmp/libc-bin.* /var/lib/dpkg/info/
#
### Create a group and user to run our app
## ARG APP_USER=user
## RUN groupadd -r ${APP_USER} && useradd --no-log-init -r -g ${APP_USER} ${APP_USER}
#
## Install packages needed to run your application (not build deps):
## mime-support -- for mime types when serving static files
## postgresql-client -- for running database commands
## We need to recreate the /usr/share/man/man{1..8} directories first because
## they were clobbered by a parent image.
RUN set -ex \
&& RUN_DEPS=" \
libpcre3 \
git \
mime-support \
postgresql-client \
libmagic1\
fail2ban libjpeg-dev libtiff5-dev zlib1g-dev libfreetype6-dev liblcms2-dev libxslt-dev libxml2-dev \
gdal-bin sysstat libpq-dev binutils libproj-dev procps" \
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
&& rm -rf /var/lib/apt/lists/*
ADD requirements /requirements
#ADD package.json package.json
#
## Install build deps, then run `pip install`, then remove unneeded build deps all in a single step.
## Correct the path to your production requirements file, if needed.
RUN set -ex \
&& BUILD_DEPS=" \
build-essential \
libpcre3-dev \
libpq-dev \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
# && npm install --production --no-save \
&& pip install --no-cache-dir -r /requirements/requirements.txt \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
&& rm -rf /var/lib/apt/lists/*
#
RUN rm -rf /requirements
RUN mkdir /code/
WORKDIR /code/
ADD . /code/
COPY ./scripts /scripts
RUN chmod +x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/static
RUN groupadd -r user
RUN useradd --no-log-init -r -g user user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
Python Modules -
aiohttp==3.8.1
aiosignal==1.2.0
amqp==5.1.1
anyio==3.6.1
asgiref==3.5.2
asttokens==2.0.5
async-timeout==4.0.2
attrs==21.4.0
aws-requests-auth==0.4.3
Babel==2.9.1
backcall==0.2.0
billiard==3.6.4.0
black==22.6.0
boto3==1.9.62
botocore==1.12.253
bytecode==0.13.0
celery==5.2.7
certifi==2022.6.15
charset-normalizer==2.0.12
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
ddsketch==2.0.4
ddtrace==1.3.0
decorator==5.1.1
Django==4.0.1
django-appconf==1.0.5
django-cache-memoize==0.1.10
django-compressor==3.1
django-compressor-autoprefixer==0.1.0
django-cors-headers==3.11.0
django-datadog-logger==0.5.0
django-elasticsearch-dsl==7.2.2
django-elasticsearch-dsl-drf==0.22.4
django-environ==0.8.1
django-extensions==3.1.5
django-libsass==0.9
django-log-request-id==2.0.0
django-nine==0.2.5
django-prometheus==2.2.0
django-sites==0.11
django-storages==1.12.3
django-uuid-upload-path==1.0.0
django-versatileimagefield==2.2
djangorestframework==3.13.1
djangorestframework-gis==0.18
docutils==0.15.2
elasticsearch==7.17.1
elasticsearch-dsl==7.4.0
executing==0.8.3
frozenlist==1.3.0
geographiclib==1.52
geopy==2.2.0
gunicorn==20.1.0
h11==0.12.0
httpcore==0.14.7
httpx==0.21.3
idna==3.3
ipython==8.0.1
jedi==0.18.1
jmespath==0.10.0
JSON-log-formatter==0.5.1
kombu==5.2.4
libsass==0.21.0
matplotlib-inline==0.1.3
multidict==6.0.2
mypy-extensions==0.4.3
packaging==21.3
parso==0.8.3
pathspec==0.9.0
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.2.0
platformdirs==2.5.2
prometheus-client==0.14.1
prompt-toolkit==3.0.30
protobuf==4.21.2
psycopg2-binary==2.9.3
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.12.0
pyparsing==3.0.9
python-dateutil==2.8.2
python-dotenv==0.19.2
python-magic==0.4.27
pytz==2021.3
rcssmin==1.1.0
regex==2022.1.18
requests==2.27.1
rfc3986==1.5.0
rjsmin==1.2.0
s3transfer==0.1.13
six==1.16.0
sniffio==1.2.0
sqlparse==0.4.2
stack-data==0.3.0
tenacity==8.0.1
tomli==2.0.1
traitlets==5.3.0
typing_extensions==4.3.0
urllib3==1.25.11
uvicorn==0.17.0
vine==5.0.0
wcwidth==0.2.5
whitenoise==5.3.0
yarl==1.7.2
Docker build command -
docker buildx build --push --platform linux/amd64,linux/arm64 -t ${ECR_LATEST_TAGX} -t ${ECR_VERSION_TAGX} --output=type=image --file ../incr.Dockerfile ../

Laravel sail up fail on Linux Mint 20.2

I am trying to build a dockerized laravel project following the documentation at https://laravel.com/docs/8.x/installation#getting-started-on-linux
I ran the following:
curl -s https://laravel.build/laravel-app | bash ,
cd laravel-app,
./vendor/bin/sail up
After pulling tons of files, I believe it comes to bulid the Dockerfile, not sure which as there are 3 Dockerfiles in 3 different folders inside laravel-app/vendor/laravel/sail/runtimes, there are 3 folders named 7.4, 8.0, and 8.1, in which each contains a Dockerfile but pretty much the differences are so subtle. These Dockerfiles have 18 commands, so after the pulls are finished it says Step 1/18, 2/18, etc... However it always messes up in step 9, it starts saying "Get: ## http://..ubnutu.com...." where ## is from 1 till 127 and then at the line
"Get:127 http://archive.ubuntu.com/ubuntu hirsute/universe amd64 gosu amd64 1.12-1build1 [745 kB]"
it always quits and says:
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/f/fontconfig/libfontconfig1_2.13.1-4.2ubuntu3_amd64.deb Connection timed out [IP: 91.189.88.142 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
My internet connection is stable but it always stops after the 127th Get line.
Also, I ran the command several times and same result happens, so I do not believe it's a connection issue.
Here's the components of the Dockerfile in folder 8.1, it is the 9th step where it is messed up (the second RUN command):
FROM ubuntu:21.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG NODE_VERSION=16
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.1-cli php8.1-dev \
php8.1-pgsql php8.1-sqlite3 php8.1-gd \
php8.1-curl \
php8.1-imap php8.1-mysql php8.1-mbstring \
php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
php8.1-intl php8.1-readline \
php8.1-ldap \
php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
php8.1-memcached php8.1-pcov php8.1-xdebug \
&& php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
Also, I tried to execute the 9th step manually, turns out that probably the problem is in the part of step 9 which says
"echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf", it results in "bash: /home/${user}/.gnupg/dirmngr.conf: Permission denied", I ran it with sudo and chmod u+x but same result.

Failed to Call Access Method Exception when Creating a MedicationOrder in FHIR

I am using this http://fhirtest.uhn.ca/baseDstu2 test FHIR server and it worked okay so far.
Now I am getting an HTTP-500 - Failed to Call Access Method exception.
Anyone has any idea on what has gone wrong?
This happens frequently. Probably because someone tested weird queries or similar that put the server in an unstable status.
I suggest posting a comment in https://chat.fhir.org/#narrow/stream/hapi to get the server restarted,
or install http://hapifhir.io/doc_cli.html which does basically the same but you have full control.
I built a Dockerfile:
FROM debian:sid
MAINTAINER Günter Zöchbauer <guenter#yyy.com>
ENV DEBIAN_FRONTEND noninteractive
RUN \
apt-get -q update && \
DEBIAN_FRONTEND=noninteractive && \
apt-get install --no-install-recommends -y -q \
apt-transport-https \
apt-utils \
wget \
bzip2 \
default-jdk
# net-tools sudo procps telnet
RUN \
apt-get update && \
rm -rf /var/lib/apt/lists/*
https://github.com/jamesagnew/hapi-fhir/releases/download/v2.0/hapi-fhir-2.0-cli.tar.bz2 && \
ADD hapi-* /hapi_fhir_cli/
RUN ls -la
RUN ls -la /hapi_fhir_cli
ADD prepare_server.sh /hapi_fhir_cli/
RUN \
cd /hapi_fhir_cli && \
bash -c /hapi_fhir_cli/prepare_server.sh
ADD start.sh /hapi_fhir_cli/
WORKDIR /hapi_fhir_cli
EXPOSE 5555
ENTRYPOINT ["/hapi_fhir_cli/start.sh"]
Which requires in the same directory as the Dockerfile
prepare_server.sh
#!/usr/bin/env bash
ls -la
./hapi-fhir-cli run-server --allow-external-refs &
while ! timeout 1 bash -c "echo > /dev/tcp/localhost/8080"; do sleep 10; done
./hapi-fhir-cli upload-definitions -t http://localhost:8080/baseDstu2
./hapi-fhir-cli upload-examples -c -t http://localhost:8080/baseDstu2
start.sh
#!/usr/bin/env bash
cd /hapi_fhir_cli
./hapi-fhir-cli run-server --allow-external-refs -p 5555
Build
docker build myname/hapi_fhir_cli_dstu2 -t . #--no-cache
Run
docker run -d -p 5555:5555 [image id from docker build]
Hope this helps.

How to change the version of Ruby in a Docker image (replace 2.2.0 with 2.0.0 )

The Heroku Docker image heroku/ruby installs ruby 2.2.3.
How do I use that image, but use ruby 2.0.0 instead (trying to Dockerize a Rails 3.2 app).
I know that the location of the Heroku buildpack for 2.0.0 is
https://heroku-buildpack-ruby.s3.amazonaws.com/cedar-14/ruby-2.0.0.tgz
but cannot see how to modify my Dockerfile so that it will use that version of Ruby instead.
I tried:
# Dockerfile
FROM heroku/ruby
# Install Ruby
ONBUILD RUN curl -s --retry 3 -L https://heroku-buildpack-ruby.s3.amazonaws.com/cedar-14/ruby-2.0.0.tgz | tar xz -C /app/heroku/ruby/ruby-2.2.0
which I'd hoped might overwrite the 2.2.0 with 2.0.0 (keeping the path etc the same) but that command gets ignored when I run docker-compose build
This is what I ended up doing (ruby and node) on the same docker file reproducing heroku environment:
FROM heroku/heroku:16
# Ruby dependencies
RUN apt-get update -qq && \
apt-get install -y -q --no-install-recommends \
build-essential\
libpq-dev\
libxml2-dev\
libxslt1-dev\
nodejs\
npm \
qt5-default\
libqt5webkit5-dev\
gstreamer1.0-plugins-base\
gstreamer1.0-tools\
gstreamer1.0-x\
xvfb \
&& rm -rf /var/lib/apt/lists/* \
&& truncate -s 0 /var/log/*log
# Ruby heroku
RUN apt remove -y --purge ruby && curl -s --retry 3 -L https://heroku-buildpack-ruby.s3.amazonaws.com/heroku-16/ruby-2.3.4.tgz | tar -xz
# Node heroku
RUN export NODE_VERSION=6.11.0 && \
curl -s --retry 3 -L https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz -o /tmp/node-v$NODE_VERSION-linux-x64.tar.gz && \
tar -xzf /tmp/node-v$NODE_VERSION-linux-x64.tar.gz -C /tmp && \
rsync -a /tmp/node-v$NODE_VERSION-linux-x64/ / && \
rm -rf /tmp/node-v$NODE_VERSION-linux-x64*
WORKDIR /var/app
You need to build an image yourself with the right versions. Change this Dockerfile as necessary - https://github.com/heroku/docker-ruby/blob/master/Dockerfile

Resources