<commit_before>require "conjure/provision/docker/template"
require "securerandom"

module Conjure
  module Provision
    class Passenger
      attr_reader :ip_address

      def initialize(platform, database, rails_env, options)
        @platform = platform
        @database = database
        @rails_env = rails_env
        @nginx_directives = options[:nginx_directives] || {}
      end

      def start 
        @ip_address = dockerfile.build(@platform).start("/sbin/my_init", start_options)
      end

      private

      def start_options
        {:run_options => "-p 80:80 -p 2222:22"}
      end

      def dockerfile
        public_key = File.expand_path("~/.ssh/id_rsa.pub")
        raise "Error: ~/.ssh/id_rsa.pub must exist." unless File.exist?(public_key)
        file = Docker::Template.new("conjure/passenger-ruby21:1.0.1")
        file.add_file public_key, "/root/.ssh/authorized_keys"
        file.add_file public_key, "/home/app/.ssh/authorized_keys"
        file.run "chown app.app /home/app/.ssh/authorized_keys"
        file.run "chown root.root /root/.ssh/authorized_keys"
        file.add_file_data nginx_conf, "/etc/nginx/sites-enabled/application.conf"
        file.add_file_data database_yml, "/home/app/application/shared/config/database.yml"
        file.add_file_data secrets_yml, "/home/app/application/shared/config/secrets.yml"
        file
      end

      def database_yml
        {@rails_env => @database.rails_config}.to_yaml
      end

      def secrets_yml
        {@rails_env => {"secret_key_base" => SecureRandom.hex(64)}}.to_yaml
      end
<commit_msg>Accept system_packages option when provisioning<commit_after>require "conjure/provision/docker/template"
require "securerandom"

module Conjure
  module Provision
    class Passenger
      attr_reader :ip_address

      def initialize(platform, database, rails_env, options)
        @platform = platform
        @database = database
        @rails_env = rails_env
        @nginx_directives = options[:nginx_directives] || {}
        @system_packages = options[:system_packages] || []
      end

      def start 
        @ip_address = dockerfile.build(@platform).start("/sbin/my_init", start_options)
      end

      private

      def start_options
        {:run_options => "-p 80:80 -p 2222:22"}
      end

      def dockerfile
        public_key = File.expand_path("~/.ssh/id_rsa.pub")
        raise "Error: ~/.ssh/id_rsa.pub must exist." unless File.exist?(public_key)
        file = Docker::Template.new("conjure/passenger-ruby21:1.0.1")
        file.run apt_command if apt_command
        file.add_file public_key, "/root/.ssh/authorized_keys"
        file.add_file public_key, "/home/app/.ssh/authorized_keys"
        file.run "chown app.app /home/app/.ssh/authorized_keys"
        file.run "chown root.root /root/.ssh/authorized_keys"
        file.add_file_data nginx_conf, "/etc/nginx/sites-enabled/application.conf"
        file.add_file_data database_yml, "/home/app/application/shared/config/database.yml"
        file.add_file_data secrets_yml, "/home/app/application/shared/config/secrets.yml"
        file
      end

      def apt_command
        if @system_packages.any?
          "apt-get update && apt-get install -y #{@system_packages.join ' '}"
        end
      end

      def database_yml
        {@rails_env => @database.rails_config}.to_yaml
      end

      def secrets_yml
        {@rails_env => {"secret_key_base" => SecureRandom.hex(64)}}.to_yaml
      end

{'fraction_non_alphanumeric': 0.11245326430831176, 'fraction_numerical': 0.009778544722461893, 'mean_word_length': 2.6610526315789476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2212451', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1080, 'n_words': 202}