From c514fd62fe005d8d41a39e11508a3aee6ba9946d Mon Sep 17 00:00:00 2001 From: Jamie Alessio Date: Tue, 22 Oct 2019 19:48:02 +0000 Subject: [PATCH 1/1] Introduce docker-compose config for development --- .dockerignore | 1 + .gitignore | 3 ++ Dockerfile | 52 +++++++++++++++++++ config/docker.database.yml | 20 +++++++ docker-compose.yml | 24 +++++++++ docker/postgres/Dockerfile | 4 ++ .../postgres/openstreetmap-postgres-init.sh | 11 ++++ 7 files changed, 115 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 config/docker.database.yml create mode 100644 docker-compose.yml create mode 100644 docker/postgres/Dockerfile create mode 100755 docker/postgres/openstreetmap-postgres-init.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..4c436a485 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +docker-db-data diff --git a/.gitignore b/.gitignore index 1328658c6..73316769e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ public/attachments public/export storage tmp + +# docker-compose database directory +docker-db-data diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..978834105 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +FROM ruby:2.5 + +# fixes dpkg man page softlink error while installing postgresql-client [source: https://stackoverflow.com/a/52655008/5350059] +RUN mkdir -p /usr/share/man/man1 && \ + mkdir -p /usr/share/man/man7 + +# npm is not available in Debian repo so following official instruction [source: https://github.com/nodesource/distributions/blob/master/README.md#debinstall] +RUN curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh && \ + bash nodesource_setup.sh && \ + rm -f nodesource_setup.sh + +# install packages +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + build-essential \ + curl \ + imagemagick \ + libarchive-dev \ + libffi-dev \ + libmagickwand-dev \ + libpq-dev \ + libsasl2-dev \ + libxml2-dev \ + libxslt1-dev \ + locales \ + nodejs \ + osmosis \ + postgresql-client \ + ruby-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# install npm packages +RUN npm install -g --unsafe-perm \ + phantomjs-prebuilt \ + yarn + +# Setup app location +RUN mkdir -p /app +WORKDIR /app + +# Install gems +ADD Gemfile* /app/ +RUN bundle install + +# Setup local +RUN sed -i -e 's/# en_GB.UTF-8 UTF-8/en_GB.UTF-8 UTF-8/' /etc/locale.gen && \ + echo 'LANG="en_GB.UTF-8"'>/etc/default/locale && \ + dpkg-reconfigure --frontend=noninteractive locales && \ + update-locale LANG=en_GB.UTF-8 + +ENV LANG en_GB.UTF-8 diff --git a/config/docker.database.yml b/config/docker.database.yml new file mode 100644 index 000000000..6e6e5fd99 --- /dev/null +++ b/config/docker.database.yml @@ -0,0 +1,20 @@ +# This configuration is tailored for use with docker-compose. See DOCKER.md for more information. + +development: + adapter: postgresql + database: openstreetmap + username: openstreetmap + password: openstreetmap + host: db + encoding: utf8 + +# Warning: The database defined as 'test' will be erased and +# re-generated from your development database when you run 'rake'. +# Do not set this db to the same as development or production. +test: + adapter: postgresql + database: osm_test + username: postgres + password: + host: db + encoding: utf8 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..70730febf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3" + +services: + web: + build: + context: . + volumes: + - .:/app + ports: + - "3000:3000" + command: bundle exec rails s -p 3000 -b '0.0.0.0' + depends_on: + - db + + db: + build: + context: . + dockerfile: docker/postgres/Dockerfile + ports: + - "54321:5432" + environment: + POSTGRES_DB: openstreetmap + volumes: + - ./docker-db-data:/var/lib/postgresql/data diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile new file mode 100644 index 000000000..672e2e7a6 --- /dev/null +++ b/docker/postgres/Dockerfile @@ -0,0 +1,4 @@ +FROM postgres:11 + +# Add db init script to install OSM-specific Postgres functions/extensions. +ADD docker/postgres/openstreetmap-postgres-init.sh /docker-entrypoint-initdb.d/ diff --git a/docker/postgres/openstreetmap-postgres-init.sh b/docker/postgres/openstreetmap-postgres-init.sh new file mode 100755 index 000000000..d8c619d45 --- /dev/null +++ b/docker/postgres/openstreetmap-postgres-init.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -ex + +# Create 'openstreetmap' user +psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" <<-EOSQL + CREATE USER openstreetmap PASSWORD 'openstreetmap'; + GRANT ALL PRIVILEGES ON DATABASE openstreetmap TO openstreetmap; +EOSQL + +# Create btree_gist extensions +psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -c "CREATE EXTENSION btree_gist" openstreetmap -- 2.39.5