run-redmine 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e5bafcf93d6a08ba073f415c92d301221055763039061bba94e727885c84bcc
4
+ data.tar.gz: 563893a52c53338d930e44283a4a90a52f0d2841158d2e6cf8e6a209032d8930
5
+ SHA512:
6
+ metadata.gz: bde20117075026555bf0bdf1d6455b82c2fee1ba85ddde144b793d2afe7137ad2e2874f9b1ae21816070290a9ca36e9766671cb881e610b63d09c521622e2b7c
7
+ data.tar.gz: dd6ebb52211082fa02ac7f3107cdd96ea3fec4ec2ffc4436d8e2c70a84d48039797e2aa912d42b4c1ed5d7f96aa28da082a4fa358c95c07f264919f7bdaa93b7
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'redmine'
@@ -0,0 +1,73 @@
1
+ FROM ubuntu:16.04
2
+ MAINTAINER Andrei.Malyshev@kodep.ru
3
+ ENV PATH ~/.rbenv/shims:~/.rbenv/bin:$PATH
4
+ ENV MAKEOPTS "-j8"
5
+ ENV RUBY_BUILD_CACHE_PATH yes
6
+
7
+ RUN echo 'LANG="ru_RU.UTF-8"' >> /etc/default/locale
8
+ RUN echo '1.01'
9
+ RUN apt-get update && apt-get -y install locales && locale-gen ru_RU && locale-gen ru_RU.UTF-8
10
+
11
+ RUN apt-get install -y \
12
+ git-core \
13
+ autoconf \
14
+ bash \
15
+ bison \
16
+ bzip2 \
17
+ ca-certificates \
18
+ coreutils \
19
+ curl \
20
+ gcc \
21
+ git \
22
+ libc-dev \
23
+ libffi-dev \
24
+ libxml2-dev \
25
+ libxslt-dev \
26
+ libssl-dev \
27
+ libreadline-dev \
28
+ make \
29
+ subversion \
30
+ libmagickwand-dev \
31
+ openssh-client \
32
+ postgresql \
33
+ libpq-dev \
34
+ sudo \
35
+ software-properties-common \
36
+ graphicsmagick-libmagick-dev-compat \
37
+ imagemagick \
38
+ libsqlite3-dev \
39
+ tree \
40
+ screen
41
+ RUN git clone --depth 1 git://github.com/rbenv/rbenv.git ~/.rbenv \
42
+ && git clone --depth 1 git://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
43
+ RUN mv /bin/sh /bin/sh.bk && ln /bin/bash /bin/sh
44
+
45
+ ARG ruby_version=2.5.1
46
+ ENV RUBY_VERSION=$ruby_version
47
+
48
+ RUN rbenv install $RUBY_VERSION
49
+ RUN mkdir -p /var/www
50
+ WORKDIR /var/www/
51
+ RUN git clone https://github.com/redmine/redmine.git
52
+ WORKDIR /var/www/redmine
53
+
54
+ ARG redmine_version=3.4.4
55
+ ENV REDMINE_VERSION=$redmine_version
56
+
57
+ RUN git checkout $REDMINE_VERSION
58
+ RUN rbenv local ${RUBY_VERSION}
59
+ ADD ./database.yml /var/www/redmine/config
60
+ RUN gem install bundler && bundle --without=test development --retry=5
61
+
62
+ ENV RAILS_ENV=development
63
+ ADD ./pg/pg_hba.conf /etc/postgresql/9.5/main
64
+ RUN rake generate_secret_token
65
+ ADD ./run.sh /root/run.sh
66
+ RUN chmod +x /root/run.sh
67
+
68
+ RUN gem install redmine && rbenv rehash
69
+
70
+ ARG port=3000
71
+ ENV PORT=$port
72
+ EXPOSE $port
73
+ ENTRYPOINT /root/run.sh
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: redmine
4
+ host: localhost
5
+ username: postgres
6
+ encoding: utf8
7
+ pool: 5
@@ -0,0 +1,15 @@
1
+ local all postgres trust
2
+
3
+ # TYPE DATABASE USER ADDRESS METHOD
4
+
5
+ # "local" is for Unix domain socket connections only
6
+ local all all trust
7
+ # IPv4 local connections:
8
+ host all all 127.0.0.1/32 trust
9
+ # IPv6 local connections:
10
+ host all all ::1/128 md5
11
+ # Allow replication connections from localhost, by a user with the
12
+ # replication privilege.
13
+ #local replication postgres peer
14
+ #host replication postgres 127.0.0.1/32 md5
15
+ #host replication postgres ::1/128 md5
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+ set -x
3
+ env
4
+ cd /var/www/redmine
5
+ service postgresql start
6
+ echo "Migrations"
7
+ bundle exec rake db:create && rake db:migrate
8
+ echo "Pulling plugins"
9
+ redmine install-plugins
10
+ echo "Server"
11
+ bundle exec rails s -b 0.0.0.0 -p $PORT
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './redmine/banner'
4
+ require_relative './redmine/cli/runner'
5
+
6
+ Redmine::Banner.print
7
+ Redmine::CLI::Runner.new.run
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Redmine
4
+ module Banner
5
+ def print
6
+ puts 'Redmine launcher V 1.0'
7
+ end
8
+
9
+ module_function :print
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Redmine
4
+ module CLI
5
+ class Arguments
6
+ attr_accessor :command, :instance_name, :config_path, :plugins_path
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../commands/start'
4
+ require_relative '../commands/pull_plugins'
5
+
6
+ module Redmine
7
+ module CLI
8
+ class CommandFactory
9
+ def initialize(args, config)
10
+ @arguments = args
11
+ @config = config
12
+ end
13
+
14
+ def command
15
+ case @arguments.command
16
+ when Redmine::CLI::Parser::COMMAND_START
17
+ Redmine::Commands::Start.new(@arguments, @config)
18
+ when Redmine::CLI::Parser::COMMAND_LIST
19
+ Redmine::Commands::List.new
20
+ when Redmine::CLI::Parser::COMMAND_INSTALL_PLUGINS
21
+ Redmine::Commands::PullPlugins.new(@arguments)
22
+ else
23
+ raise Redmine::CLI::UnclearCommand, @arguments.command
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ require_relative './arguments'
6
+
7
+ require_relative './../commands/start'
8
+ require_relative './../commands/list'
9
+
10
+ module Redmine
11
+ module CLI
12
+ class UnclearCommand < StandardError; end
13
+ class Parser
14
+ COMMANDS = [
15
+ COMMAND_START = 'start',
16
+ COMMAND_LIST = 'list',
17
+ COMMAND_SHOW = 'show',
18
+ COMMAND_SHELL = 'shell',
19
+ COMMAND_PULL = 'pull',
20
+ COMMAND_INSTALL_PLUGINS = 'install-plugins'
21
+ ].freeze
22
+
23
+ attr_reader :arguments
24
+
25
+ def initialize(args)
26
+ parse(args)
27
+ end
28
+
29
+ private
30
+
31
+ def parse(args)
32
+ @arguments = ::Redmine::CLI::Arguments.new
33
+ # options = OpenStruct.new
34
+ opt_parser = OptionParser.new do |opts|
35
+ end
36
+
37
+ opt_parser.parse!(args)
38
+ parse_remainings(args)
39
+ end
40
+
41
+ def parse_remainings(args)
42
+ command = args.shift
43
+ case command
44
+ when COMMAND_START
45
+ @arguments.command = COMMAND_START
46
+ when COMMAND_LIST
47
+ @arguments.command = COMMAND_LIST
48
+ when COMMAND_SHOW
49
+ process_show_command(args)
50
+ when COMMAND_SHELL
51
+ process_shell_command(args)
52
+ when COMMAND_PULL
53
+ process_pull_command(args)
54
+ when COMMAND_INSTALL_PLUGINS
55
+ process_install_plugins_command(args)
56
+ else
57
+ puts "Unknown command #{command}"
58
+ raise UnclearCommand, command
59
+ end
60
+ end
61
+
62
+ def process_show_command(args)
63
+ @arguments.command = COMMAND_SHOW
64
+ @arguments.instance_name = args.shift
65
+ end
66
+
67
+ def process_shell_command(args)
68
+ @arguments.command = COMMAND_SHELL
69
+ @arguments.instance_name = args.shift
70
+ end
71
+
72
+ def process_pull_command(args)
73
+ @arguments.command = COMMAND_PULL
74
+ @arguments.instance_name = args.shift
75
+ end
76
+
77
+ def process_install_plugins_command(args)
78
+ @arguments.command = COMMAND_INSTALL_PLUGINS
79
+ @arguments.config_path = args.shift
80
+ @arguments.plugins_path = args.shift
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,44 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../config'
5
+ require_relative './parser'
6
+ require_relative './command_factory'
7
+
8
+ module Redmine
9
+ module CLI
10
+ class Runner
11
+ def run
12
+ perform
13
+ # run_docker
14
+ end
15
+
16
+ private
17
+
18
+ def cli_args
19
+ ARGV
20
+ end
21
+
22
+ def config
23
+ @config ||= Redmine::Config.new(config_filename)
24
+ rescue
25
+ puts $!.message
26
+ puts $!.backtrace
27
+ puts "Invalid or missing #{config_filename}"
28
+ end
29
+
30
+ def arguments
31
+ @arguments ||= Redmine::CLI::Parser.new(cli_args).arguments
32
+ end
33
+
34
+ def perform
35
+ command = CommandFactory.new(arguments, config).command
36
+ command.execute
37
+ end
38
+
39
+ def config_filename
40
+ 'config.yml'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ module Redmine
2
+ module Commands
3
+ module Docker
4
+ class Build
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ def command_line
10
+ "cd docker && docker build -t redmineup/demo-base --build-arg ruby_version=#{@config.ruby_version} --build-arg redmine_version=#{@config.redmine_version} ."
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tmpdir'
4
+
5
+ module Redmine
6
+ module Commands
7
+ module Docker
8
+ class CopyConfig
9
+ def initialize(config)
10
+ @config = config
11
+ end
12
+
13
+ def command_line
14
+ "cat << EOF >#{Dir.tmpdir}/config.yml\n#{@config.yaml}\nEOF\ndocker cp #{Dir.tmpdir}/config.yml #{@config.name}:/config.yml; rm -f #{Dir.tmpdir}/config.yml"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Redmine
4
+ module Commands
5
+ module Docker
6
+ class Create
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def command_line
12
+ "docker create --rm --name=#{@config.name} -e PORT=#{@config.port} -p #{@config.port}:#{@config.port} --mount source=redmine-pg,target=/var/lib/postgresql/9.5/main redmineup/demo-base"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Redmine
4
+ module Commands
5
+ module Docker
6
+ class CreateVolume
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def command_line
12
+ "docker volume create redmine-pg-#{@config.name}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Redmine
2
+ module Commands
3
+ module Docker
4
+ class Start
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ def command_line
10
+ "docker start #{@config.name}"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ require_relative './shell'
6
+
7
+ module Redmine
8
+ module Commands
9
+ DOCKER_LIST_COMMAND = 'docker ps'
10
+ class List
11
+ def results
12
+ parse(Shell.new.execute('docker ps'))
13
+ end
14
+
15
+ def execute
16
+ Redmine::Commands::ListPrinter.new.print_results(results)
17
+ end
18
+
19
+ private
20
+
21
+ def parse(docker_ps_output)
22
+ results = docker_ps_output.split("\n")[1..-1].map do |line|
23
+ process_line(line)
24
+ end
25
+ results.select { |result| result.name =~ /^redmine-run__/ }
26
+ end
27
+
28
+ def process_line(line)
29
+ line_tokens = line.split(/\s{2,}/)
30
+ OpenStruct.new(
31
+ container_id: line_tokens[0],
32
+ image: line_tokens[1],
33
+ command: line_tokens[2],
34
+ created: line_tokens[3],
35
+ status: line_tokens[4],
36
+ ports: line_tokens[5],
37
+ name: line_tokens[6]
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module Redmine
2
+ module Commands
3
+ class ListPrinter
4
+ def print(results)
5
+ banner
6
+ results.map { |result| print_result(result) }
7
+ footer
8
+ end
9
+
10
+ def banner
11
+ puts 'RUNNING REDMINE INSTANCES:'
12
+ puts '=========================='
13
+ end
14
+
15
+ def print_result(result)
16
+ puts "\t#{result.name.gsub(/^redmine-run__/, '')}"
17
+ end
18
+
19
+ def footer
20
+ puts "\n\n"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ require_relative '../utils/plugin_installer'
6
+
7
+ module Redmine
8
+ module Commands
9
+ class PullPlugins
10
+ def initialize(args)
11
+ @args = args
12
+ end
13
+
14
+ def execute
15
+ config.plugins.values.each do |plugin|
16
+ installer = Redmine::Utils::PluginInstaller.new(
17
+ @args.plugins_path,
18
+ OpenStruct.new(plugin)
19
+ )
20
+ installer.install
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def config
27
+ @config ||= Redmine::Config.new(@args.config_path)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Redmine
2
+ module Commands
3
+ class Shell
4
+ def execute(cmd)
5
+ Kernel.system cmd
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ require_relative './docker/build'
6
+ require_relative './docker/create_volume'
7
+ require_relative './docker/create'
8
+ require_relative './docker/copy_config'
9
+ require_relative './docker/start'
10
+
11
+ module Redmine
12
+ module Commands
13
+ class Start
14
+ attr_reader :config, :arguments
15
+
16
+ def initialize(arguments, config)
17
+ @arguments = arguments
18
+ @config = config
19
+ end
20
+
21
+ def execute
22
+ run_command Redmine::Commands::Docker::Build.new(config).command_line
23
+ run_command Redmine::Commands::Docker::CreateVolume.new(config).command_line
24
+ run_command Redmine::Commands::Docker::Create.new(config).command_line
25
+ run_command Redmine::Commands::Docker::CopyConfig.new(config).command_line
26
+ run_command Redmine::Commands::Docker::Start.new(config).command_line
27
+ end
28
+
29
+ private
30
+
31
+ def run_command(command_line)
32
+ puts "+ #{command_line}"
33
+ Open3.popen3(command_line) do |input, output, error, process_thread|
34
+ Thread.new {
35
+ until input.closed?
36
+ inp = gets.chomp
37
+ puts inp
38
+ input.puts inp
39
+ end
40
+ }
41
+
42
+ t_err = Thread.new {
43
+ until error.eof?
44
+ putc error.readchar
45
+ end
46
+ }
47
+
48
+ t_out = Thread.new {
49
+ until output.eof?
50
+ putc output.readchar
51
+ end
52
+ }
53
+
54
+ Process::waitpid(process_thread.pid) rescue nil
55
+ # "rescue nil" is there in case process already ended.
56
+
57
+ t_err.join
58
+ t_out.join
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Redmine
6
+ class Config
7
+ def initialize(filename)
8
+ @filename = filename
9
+ parse
10
+ end
11
+
12
+ def ruby_version
13
+ @config['ruby']['version']
14
+ end
15
+
16
+ def redmine_version
17
+ @config['redmine']['version']
18
+ end
19
+
20
+ def port
21
+ @config['server']['port']
22
+ end
23
+
24
+ def name
25
+ "redmine-run__#{@config['name']}"
26
+ end
27
+
28
+ def plugins
29
+ @config['plugins']
30
+ end
31
+
32
+ def yaml
33
+ YAML.dump(@config)
34
+ end
35
+
36
+ private
37
+
38
+ def parse
39
+ content = File.read(@filename)
40
+ @config = YAML.safe_load(content)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ module Redmine
2
+ module Utils
3
+ class PluginInstaller
4
+ def initialize(plugins_folder, plugin_props)
5
+ @plugins_folder = plugins_folder
6
+ @plugin = plugin_props
7
+ end
8
+
9
+ def install
10
+ if folder_exists?
11
+ update_plugin
12
+ else
13
+ clone_plugin
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def folder_exists?
20
+ File.directory?(dest_dir)
21
+ end
22
+
23
+ def dest_dir
24
+ File.join(@plugins_folder, @plugin.folder)
25
+ end
26
+
27
+ def shell
28
+ @shell ||= Redmine::Commands::Shell.new
29
+ end
30
+
31
+ def clone_plugin
32
+ shell.execute(
33
+ "git clone #{@plugin.git} #{dest_dir}"
34
+ )
35
+ end
36
+
37
+ def update_plugin
38
+ shell.execute(
39
+ "cd #{dest_dir}; git fetch -a; git reset --hard #{commit_specification}"
40
+ )
41
+ end
42
+
43
+ def commit_specification
44
+ return @plugin.tag if @plugin.tag
45
+ return "origin/#{@plugin.branch}" if @plugin.branch
46
+ end
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: run-redmine
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrei Malyshev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: Andrei.Malyshev@kodep.ru
15
+ executables:
16
+ - redmine
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/redmine
21
+ - docker/Dockerfile
22
+ - docker/database.yml
23
+ - docker/pg/pg_hba.conf
24
+ - docker/run.sh
25
+ - lib/redmine.rb
26
+ - lib/redmine/banner.rb
27
+ - lib/redmine/cli/arguments.rb
28
+ - lib/redmine/cli/command_factory.rb
29
+ - lib/redmine/cli/parser.rb
30
+ - lib/redmine/cli/runner.rb
31
+ - lib/redmine/commands/docker/build.rb
32
+ - lib/redmine/commands/docker/copy_config.rb
33
+ - lib/redmine/commands/docker/create.rb
34
+ - lib/redmine/commands/docker/create_volume.rb
35
+ - lib/redmine/commands/docker/start.rb
36
+ - lib/redmine/commands/list.rb
37
+ - lib/redmine/commands/list_printer.rb
38
+ - lib/redmine/commands/pull_plugins.rb
39
+ - lib/redmine/commands/shell.rb
40
+ - lib/redmine/commands/start.rb
41
+ - lib/redmine/config.rb
42
+ - lib/redmine/utils/plugin_installer.rb
43
+ homepage: https://redmineup.com
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.7.6
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Run redmine in one line
67
+ test_files: []