Skip to content

Commit

Permalink
Simplifying docker settings
Browse files Browse the repository at this point in the history
Signed-off-by: Ko Nagase <[email protected]>
  • Loading branch information
sanak committed Apr 28, 2022
1 parent 9e05838 commit c233dd5
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 276 deletions.
14 changes: 7 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Gemfile
GEM_PG_VERSION=1.2.2

# docker-compose.yml - postgres
POSTGRES_USER=gtt
POSTGRES_PASSWORD=gtt
POSTGRES_DB=gtt
# docker-compose.yml - postgis
# config/database.yml
DB_HOST=postgis
DB_NAME=gtt
DB_USER=gtt
DB_PASS=gtt
DB_PORT=5432

# config/configuration.yml
SMTP_ENABLE_STARTTLS_AUTO=true # (or false)
Expand Down
96 changes: 37 additions & 59 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
FROM ruby:2.7-slim-buster
FROM node:16-bullseye-slim as gtt-builder

WORKDIR /app

COPY plugins/redmine_gtt/ ./redmine_gtt/

RUN apt update; \
apt install -y git; \
cd redmine_gtt; \
yarn; \
yarn webpack

FROM ruby:3.1-slim-bullseye as base

# explicitly set uid/gid to guarantee that it won't change in the future
# the values 999:999 are identical to the current user/group id assigned
Expand All @@ -8,6 +20,7 @@ RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
wget \
\
# bzr \
Expand All @@ -21,8 +34,6 @@ RUN set -eux; \
ghostscript \
gsfonts \
imagemagick \
# https://github.com/docker-library/ruby/issues/344
shared-mime-info \
# grab gosu for easy step-down from root
gosu \
# grab tini for signal processing and zombie killing
Expand All @@ -44,89 +55,57 @@ RUN set -eux; \
chown redmine:redmine "$HOME"; \
chmod 1777 "$HOME"

ARG REDMINE_VERSION="4.2.3"
ARG REDMICA_VERSION=""
# ENV REDMINE_DOWNLOAD_SHA256 ad4109c3425f1cfe4c8961f6ae6494c76e20d81ed946caa1e297d9eda13b41b4
ENV REDMINE_VERSION="5.0.0"
ENV REDMINE_DOWNLOAD_URL https://www.redmine.org/releases/redmine-5.0.0.tar.gz
ENV REDMINE_DOWNLOAD_SHA256 7e840dec846646dae52fff5c631b135d1c915d6e03ea6f01ca8f12ad35803bef

RUN set -eux; \
if [ -n "$REDMINE_VERSION" ]; then \
wget -O redmine.tar.gz "https://www.redmine.org/releases/redmine-${REDMINE_VERSION}.tar.gz"; \
# echo "$REDMINE_DOWNLOAD_SHA256 *redmine.tar.gz" | sha256sum -c -;
elif [ -n "$REDMICA_VERSION" ]; then \
wget -O redmine.tar.gz "https://github.com/redmica/redmica/archive/v${REDMICA_VERSION}.tar.gz"; \
fi; \
# if we use wget here, we get certificate issues (https://github.com/docker-library/redmine/pull/249#issuecomment-984176479)
curl -fL -o redmine.tar.gz "$REDMINE_DOWNLOAD_URL"; \
echo "$REDMINE_DOWNLOAD_SHA256 *redmine.tar.gz" | sha256sum -c -; \
tar -xf redmine.tar.gz --strip-components=1; \
rm redmine.tar.gz files/delete.me log/delete.me; \
mkdir -p log public/plugin_assets sqlite tmp/pdf tmp/pids; \
mkdir -p log public/plugin_assets tmp/pdf tmp/pids; \
chown -R redmine:redmine ./; \
# log to STDOUT (https://github.com/docker-library/redmine/issues/108)
echo 'config.logger = Logger.new(STDOUT)' > config/additional_environment.rb; \
# fix permissions for running as an arbitrary user
chmod -R ugo=rwX config db sqlite; \
chmod -R ugo=rwX config; \
find log tmp -type d -exec chmod 1777 '{}' +

# for Redmine patches
ARG PATCH_STRIP=1
ARG PATCH_DIRS=""
COPY patches/ ./patches/
# GTT plugin
COPY --from=gtt-builder --chown=redmine:redmine /app/ ./plugins/

COPY --chown=redmine:redmine config/ ./config/

# for GTT gem native extensions
ARG GEM_PG_VERSION="1.2.3"
COPY Gemfile.local ./
COPY plugins/ ./plugins/
COPY --chown=redmine:redmine Gemfile.local ./

# Other plugins
COPY --chown=redmine:redmine plugins/redmine_gtt_smash/ ./plugins/redmine_gtt_smash/
COPY --chown=redmine:redmine plugins/redmine_text_blocks/ ./plugins/redmine_text_blocks/

# Themes (if exists)
COPY --chown=redmine:redmine public/themes/ ./public/themes/

FROM base

RUN set -eux; \
\
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends \
# default-libmysqlclient-dev \
# freetds-dev \
gcc \
# libmariadbclient-dev \
libpq-dev \
# libsqlite3-dev \
make \
patch \
# in 4.1+, libmagickcore-dev and libmagickwand-dev are no longer necessary/used: https://www.redmine.org/issues/30492
libmagickcore-dev libmagickwand-dev \
# for GTT dependencies
g++ \
libgeos-dev \
curl \
; \
rm -rf /var/lib/apt/lists/*; \
\
if [ -n "$PATCH_DIRS" ]; then \
for dir in $(echo $PATCH_DIRS | sed "s/,/ /g"); do \
for file in ./patches/"$dir"/*; do \
patch -p"$PATCH_STRIP" < $file; \
done; \
done; \
rm -rf ./patches/*; \
fi; \
curl -sL https://deb.nodesource.com/setup_14.x | bash -; \
apt-get install -y --no-install-recommends nodejs; \
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -; \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list; \
apt-get update; \
apt-get install -y --no-install-recommends yarn; \
for plugin in ./plugins/*; do \
if [ -f "$plugin/webpack.config.js" ]; then \
cd "$plugin" && yarn && npx webpack && rm -rf node_modules && cd ../..; \
fi; \
done; \
export GEM_PG_VERSION="$GEM_PG_VERSION"; \
gosu redmine bundle config --local without 'development test'; \
# fill up "database.yml" with bogus entries so the redmine Gemfile will pre-install all database adapter dependencies
# https://github.com/redmine/redmine/blob/e9f9767089a4e3efbd73c35fc55c5c7eb85dd7d3/Gemfile#L50-L79
echo '# the following entries only exist to force `bundle install` to pre-install all database adapter dependencies -- they can be safely removed/ignored' > ./config/database.yml; \
# for adapter in mysql2 postgresql sqlserver sqlite3; do \
for adapter in postgis; do \
echo "$adapter:" >> ./config/database.yml; \
echo " adapter: $adapter" >> ./config/database.yml; \
done; \
gosu redmine bundle install --jobs "$(nproc)"; \
rm ./config/database.yml; \
# fix permissions for running as an arbitrary user
chmod -R ugo=rwX Gemfile.lock "$GEM_HOME"; \
rm -rf ~redmine/.bundle; \
Expand All @@ -145,7 +124,6 @@ RUN set -eux; \
; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false

COPY config/ ./config/
VOLUME /usr/src/redmine/files

COPY docker-entrypoint.sh /
Expand Down
6 changes: 1 addition & 5 deletions Gemfile.local
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
source 'https://rubygems.org'

# each plugin's native extensions should be added to here
gem "rgeo"
gem "pg", (ENV['GEM_PG_VERSION'] ? "~> #{ENV['GEM_PG_VERSION']}" : "~> 1.2.3")
gem 'puma'
11 changes: 11 additions & 0 deletions config/additional_environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copy this file to additional_environment.rb and add any statements
# that need to be passed to the Rails::Initializer. `config` is
# available in this context.
#
# Example:
#
# config.log_level = :debug
# ...
#

config.logger = Logger.new(STDOUT)
17 changes: 17 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
default: &default
adapter: postgis
database: <%= ENV['DB_NAME'] %>
host: <%= ENV['DB_HOST'] %>
username: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASS'] %>
port: <%= ENV['DB_PORT'] || 5432 %>
encoding: utf8

production:
<<: *default

test:
<<: *default

development:
<<: *default
68 changes: 14 additions & 54 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,28 @@
version: "3"

services:
postgis:
image: postgis/postgis:14-3.2
environment:
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_USER: ${DB_USER}
POSTGRES_DB: ${DB_NAME}
volumes:
- postgis:/var/lib/postgresql/data

gtt:
redmine:
build:
context: ./
dockerfile: ./Dockerfile
args:
REDMINE_VERSION: 4.2.3
REDMICA_VERSION: ""
GEM_PG_VERSION: ${GEM_PG_VERSION}
PATCH_STRIP: 1
PATCH_DIRS: ""
context: .
ports:
- 3000:3000
environment:
REDMINE_DB_POSTGRES: postgres
REDMINE_DB_USERNAME: ${POSTGRES_USER}
REDMINE_DB_PASSWORD: ${POSTGRES_PASSWORD}
REDMINE_DB_DATABASE: ${POSTGRES_DB}
REDMINE_PLUGINS_MIGRATE: 1
# Gemfile
GEM_PG_VERSION: ${GEM_PG_VERSION}
# config/configuration.yml
SMTP_ENABLE_STARTTLS_AUTO: ${SMTP_ENABLE_STARTTLS_AUTO}
SMTP_ADDRESS: ${SMTP_ADDRESS}
SMTP_PORT: ${SMTP_PORT}
SMTP_DOMAIN: ${SMTP_DOMAIN}
SMTP_AUTHENTICATION: ${SMTP_AUTHENTICATION}
SMTP_USER_NAME: ${SMTP_USER_NAME}
SMTP_PASSWORD: ${SMTP_PASSWORD}
env_file:
- .env
volumes:
- ./files:/usr/src/redmine/files
- ./plugins:/usr/src/redmine/plugins
- ./public/themes:/usr/src/redmine/public/themes
# Exclude node package and webpack contents folders
- /usr/src/redmine/plugins/redmine_gtt/node_modules
- /usr/src/redmine/plugins/redmine_gtt/assets/javascripts
depends_on:
- postgres
- mapfish-print
restart: always

postgres:
image: postgis/postgis:13-3.1
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres:/var/lib/postgresql/data
restart: always

mapfish-print:
image: camptocamp/mapfish_print:3.28
ports:
- 8080:8080
environment:
EXTRA_JARS: /usr/local/tomcat/webapps/ROOT/print-apps/lib
volumes:
- ./mapfish-print-apps:/usr/local/tomcat/webapps/ROOT/print-apps
restart: always
- postgis

volumes:
gtt:
postgres:
mapfish-print:
postgis:
Loading

0 comments on commit c233dd5

Please sign in to comment.