diff --git a/.travis.yml b/.travis.yml index e6baf95..a3a863e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ -sudo: false +sudo: required language: ruby +services: + - docker cache: bundler rvm: - 2.2 @@ -8,7 +10,14 @@ rvm: - 2.5 before_install: + # Set file permission for local ssh private key + - chmod 600 config/docker/ssh/vagrant + - docker-compose up -d + - # Force root user permissions for authorized keys. Prevent error at ssh connection. + - docker-compose exec webapp chown root:root /root/.ssh/authorized_keys + - ssh root@localhost -p 5001 -i config/docker/ssh/vagrant -o StrictHostKeyChecking=no 'exit' - gem install bundler --no-document script: - bundle exec rubocop + - bundle exec cucumber diff --git a/Berksfile b/Berksfile deleted file mode 100644 index 3b3a8f9..0000000 --- a/Berksfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'https://supermarket.chef.io' - -cookbook 'dkdeploy-core', path: 'config/vm/cookbooks/dkdeploy-core' diff --git a/Berksfile.lock b/Berksfile.lock deleted file mode 100644 index c60bbae..0000000 --- a/Berksfile.lock +++ /dev/null @@ -1,47 +0,0 @@ -DEPENDENCIES - dkdeploy-core - path: config/vm/cookbooks/dkdeploy-core - -GRAPH - apt (7.0.0) - build-essential (8.1.1) - mingw (>= 1.1) - seven_zip (>= 0.0.0) - compat_resource (12.19.1) - database (6.1.1) - postgresql (>= 1.0.0) - dkdeploy-core (1.0.0) - apt (>= 0.0.0) - database (>= 0.0.0) - mysql (>= 0.0.0) - mysql2_chef_gem (>= 0.0.0) - inifile_chef_gem (0.1.0) - build-essential (>= 0.0.0) - mariadb (1.5.3) - apt (>= 0.0.0) - build-essential (>= 0.0.0) - selinux_policy (~> 2.0) - yum (>= 0.0.0) - yum-epel (>= 0.0.0) - yum-scl (>= 0.0.0) - mingw (2.0.2) - seven_zip (>= 0.0.0) - mysql (8.5.1) - mysql2_chef_gem (2.1.0) - build-essential (>= 2.4.0) - mariadb (>= 0.0.0) - mysql (>= 8.2.0) - openssl (8.1.2) - postgresql (6.1.4) - build-essential (>= 2.0.0) - compat_resource (>= 12.16.3) - openssl (>= 4.0) - selinux_policy (2.1.0) - seven_zip (2.0.2) - windows (>= 1.2.2) - windows (4.2.2) - yum (5.1.0) - yum-epel (3.1.0) - yum-scl (0.2.0) - inifile_chef_gem (>= 0.0.0) - yum (>= 0.0.0) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..542bee3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM rastasheep/ubuntu-sshd:16.04 +# Install locales +RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ + && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +ENV LANG en_US.utf8 + +# Create test user and group +RUN adduser 'test-user' --no-create-home --gecos "" --disabled-login +RUN groupadd 'test-group' +RUN usermod -aG 'test-group' 'test-user' + +RUN apt-get update && apt-get install -y \ + apache2-utils \ + mysql-client \ + # Need for gem "dkdeploy-test_environment". Use commands like "sudo rm ..." + sudo \ + # Need for gem "dkdeploy-test_environment". + less \ + rsync + +RUN mkdir -p /var/www + diff --git a/README.md b/README.md index 8ce41ff..c9dc9bc 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,9 @@ The complete list of the dkdeploy constants you find in `/lib/capistrano/dkdeplo rvm (v1.29.x) with installed Ruby 2.2. -Add the virtual box alias to your `hosts` file - - 192.168.156.180 dkdeploy-core.test - ### Running tests -1. Starting the local box (`vagrant up --provision`) +1. Starting the local docker (`docker-compose up -d`) 2. Checking coding styles (`rubocop`) 3. Running BDD cucumber tests (`cucumber`) diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index fcda6eb..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,54 +0,0 @@ -unless Vagrant.has_plugin?('vagrant-berkshelf') - puts "Please install vagrant plugin vagrant-berkshelfs first\n" - puts " vagrant plugin install vagrant-berkshelf\n\n" - puts "Exit vagrant\n\n" - abort -end - -Vagrant.require_version '~> 2.0' - -Vagrant.configure(2) do |config| - chef_version = '13.6.4' - domain = 'dkdeploy-core.test' - ip_address = '192.168.156.180' - - # Search boxes at https://atlas.hashicorp.com/search. - config.vm.box = 'bento/ubuntu-16.04' - config.vm.box_check_update = false - config.berkshelf.enabled = true - - config.vm.define('dkdeploy-core', primary: true) do |master_config| - master_config.vm.network 'private_network', ip: ip_address - - # Chef settings - master_config.vm.provision :chef_solo do |chef| - chef.install = true - chef.channel = 'stable' - chef.version = chef_version - chef.log_level = :warn - chef.add_recipe 'dkdeploy-core' - end - - # Memory limit and name of Virtualbox - master_config.vm.provider 'virtualbox' do |virtualbox| - virtualbox.name = domain - virtualbox.gui = ENV['ENABLE_GUI_MODE'] && ENV['ENABLE_GUI_MODE'] =~ /^(true|yes|y|1)$/i - virtualbox.customize [ - 'modifyvm', :id, - '--natdnsproxy1', 'off', - '--natdnshostresolver1', 'on', - '--memory', '1024', - '--audio', 'none' - ] - end - end - - if Vagrant.has_plugin?('landrush') - config.landrush.enabled = true - config.landrush.guest_redirect_dns = false - config.landrush.tld = 'dev' - config.landrush.host domain, ip_address - else - config.vm.post_up_message = "Either install Vagrant plugin 'landrush' or add this entry to your host file: #{ip_address} #{domain}" - end -end diff --git a/config/vm/cookbooks/dkdeploy-core/templates/my_extra_settings.erb b/config/docker/mysql/conf/dkdeploy.cnf similarity index 55% rename from config/vm/cookbooks/dkdeploy-core/templates/my_extra_settings.erb rename to config/docker/mysql/conf/dkdeploy.cnf index de53be0..ff06ce2 100644 --- a/config/vm/cookbooks/dkdeploy-core/templates/my_extra_settings.erb +++ b/config/docker/mysql/conf/dkdeploy.cnf @@ -1,6 +1,6 @@ [mysqld] # configure mysql to produce log with slow queries -# log-output = /var/log/mysql-default/ +# log-output = /var/log/mysql/ slow_query_log = 1 # log file - needs to match :mysql_slow_log in deploy.rb of fixture -slow_query_log_file = /var/log/mysql-default/slow-queries.log +slow_query_log_file = /var/log/mysql/slow-queries.log diff --git a/config/docker/ssh/authorized_keys b/config/docker/ssh/authorized_keys new file mode 100644 index 0000000..18a9c00 --- /dev/null +++ b/config/docker/ssh/authorized_keys @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key diff --git a/config/docker/ssh/vagrant b/config/docker/ssh/vagrant new file mode 100644 index 0000000..7d6a083 --- /dev/null +++ b/config/docker/ssh/vagrant @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI +w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP +kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2 +hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO +Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW +yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd +ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1 +Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf +TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK +iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A +sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf +4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP +cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk +EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN +CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX +3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG +YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj +3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+ +dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz +6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC +P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF +llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ +kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH ++vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ +NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s= +-----END RSA PRIVATE KEY----- diff --git a/config/vm/cookbooks/dkdeploy-core/metadata.rb b/config/vm/cookbooks/dkdeploy-core/metadata.rb deleted file mode 100644 index 5c3f0d5..0000000 --- a/config/vm/cookbooks/dkdeploy-core/metadata.rb +++ /dev/null @@ -1,10 +0,0 @@ -name 'dkdeploy-core' -maintainer 'dkd Internet Service GmbH' -license 'MIT' -description 'Project cookbook' -version '1.0.0' - -depends 'mysql' -depends 'database' -depends 'mysql2_chef_gem' -depends 'apt' diff --git a/config/vm/cookbooks/dkdeploy-core/recipes/default.rb b/config/vm/cookbooks/dkdeploy-core/recipes/default.rb deleted file mode 100644 index 3fc9e94..0000000 --- a/config/vm/cookbooks/dkdeploy-core/recipes/default.rb +++ /dev/null @@ -1,66 +0,0 @@ -# update apt packages -include_recipe 'apt' - -# Create unix user for tests -user 'test-user' do - action :create -end - -group 'test-group' do - action :create - append true - members 'test-user' -end - -# install apache2-utils. It is needed for the assets:add_htpasswd task -package 'apache2-utils' do - action :install -end - -mysql_service 'default' do - port '3306' - bind_address '0.0.0.0' # Need for remote connection - initial_root_password 'ilikerandompasswords' - run_group 'vagrant' - run_user 'vagrant' - action [:create, :start] -end - -mysql_config 'default' do - instance 'default' # necessary in some cases, causes hanging on provisioning https://github.com/chef-cookbooks/mysql/issues/387 - owner 'vagrant' # use different user to allow capistrano access to log file - group 'vagrant' - source 'my_extra_settings.erb' - notifies :restart, 'mysql_service[default]' - action :create -end - -mysql2_chef_gem 'default' do - action :install -end - -mysql_connection_info = { - host: '127.0.0.1', - username: 'root', - password: 'ilikerandompasswords' -} - -mysql_database 'dkdeploy_core' do - connection mysql_connection_info - action :create -end - -mysql_database_user 'root' do - connection mysql_connection_info - host '%' - password 'ilikerandompasswords' - privileges [:all] - action [:create, :grant] -end - -directory '/var/www' do - owner 'vagrant' - group 'vagrant' - mode '0770' - action :create -end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0c7d69e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' +services: + webapp: + build: '.' + ports: + - '5001:22' + depends_on: + - db + links: + - db:database + volumes: + - mysql-log:/var/log/mysql + - ./config/docker/ssh/authorized_keys:/root/.ssh/authorized_keys + db: + image: mysql:5.7 + restart: always + ports: + - '5002:3306' + environment: + MYSQL_ROOT_PASSWORD: ilikerandompasswords + MYSQL_DATABASE: dkdeploy_core + volumes: + - ./config/docker/mysql/conf:/etc/mysql/conf.d + - mysql-log:/var/log/mysql +volumes: + mysql-log: diff --git a/features/db.feature b/features/db.feature index 4a7198a..18272ad 100644 --- a/features/db.feature +++ b/features/db.feature @@ -6,12 +6,12 @@ Feature: Test tasks for namespace 'db' And I want to use the database `dkdeploy_core` Scenario: Check if settings upload is possible with settings given as arguments - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` Then a remote file named "shared_path/config/db_settings.dev.yaml" should exist Scenario: Check if settings upload is possible with settings given interactively When I run `cap dev db:upload_settings` interactively - And I type "127.0.0.1" + And I type "database" And I type "3306" And I type "dkdeploy_core" And I type "root" @@ -22,7 +22,7 @@ Feature: Test tasks for namespace 'db' And a remote file named "shared_path/config/db_settings.dev.yaml" should exist Scenario: Check if settings upload is possible with settings given as enviroment variables - When I successfully run `cap dev db:upload_settings DB_HOST=127.0.0.1 DB_PORT=3306 DB_NAME=dkdeploy_core DB_USERNAME=root DB_PASSWORD=ilikerandompasswords DB_CHARSET=utf8` + When I successfully run `cap dev db:upload_settings DB_HOST=database DB_PORT=3306 DB_NAME=dkdeploy_core DB_USERNAME=root DB_PASSWORD=ilikerandompasswords DB_CHARSET=utf8` Then a remote file named "shared_path/config/db_settings.dev.yaml" should exist Scenario: Reading missing database config file @@ -30,63 +30,63 @@ Feature: Test tasks for namespace 'db' Then the output should contain "Unable to locate database config file on remote server." Scenario: Reading existing database config file - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` Then a file named "temp/db_settings.dev.yaml" should not exist When I run `cap dev db:read_db_settings` Then a file named "temp/db_settings.dev.yaml" should exist Scenario: Check if password will not appear in log - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` Then the output should not contain "ilikerandompasswords" Scenario: Check content of database after uploading a script - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I wait 5 seconds to let the database commit the transaction Then the database should have a table `demo_table` with column `demo_column` And the database should not have a table `wrong_table` with column `wrong_column` Scenario: Check dumping complete database without cache table content - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I successfully run `cap dev db:download` Then a file matching %r should exist And a file matching %r should exist Scenario: Check dumping only structure of database - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I successfully run `cap dev db:download_structure` Then a file matching %r should exist And a file matching %r should not exist Scenario: Check dumping content of database - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I successfully run `cap dev db:download_content` Then a file matching %r should exist And a file matching %r should not exist Scenario: Check dumping tables - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` When I successfully run `cap dev db:dump_table[demo_table]` Then a file matching %r should exist Scenario: Check dumping tables to a specific file - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` When I successfully run `cap dev db:download_tables[demo_table,temp,demo_table.sql]` Then a file matching %r should exist Scenario: Check database for preseed structure - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev db:add_default_structure` And I wait 5 second to let the database commit the transaction Then the database should have a table `preseed_table` with column `value` Scenario: Check database for preseed content - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev db:add_default_structure` And I successfully run `cap dev db:add_default_content` And I wait 5 second to let the database commit the transaction diff --git a/features/file_access.feature b/features/file_access.feature index 048a217..8b1b1e7 100644 --- a/features/file_access.feature +++ b/features/file_access.feature @@ -87,9 +87,9 @@ Feature: Test tasks for namespace 'file_permissions' Given I extend the development capistrano configuration variable custom_file_access with value {app: {release_path: {catalog: {mode: 'u+rwx,g+rwx,o-wx'}, not_existing: {mode: 'u+rwx,g+rwx,o-wx'}}}} And a remote directory named "releases_path/not_existing" should not exist When I successfully run `cap dev file_access:set_custom_access` - Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist on host dkdeploy-core.test" - And the output should not contain "sudo chmod u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/not_existing" - And the output should contain "sudo chmod u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/catalog" + Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist" + And the output should not contain "chmod u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/not_existing" + And the output should contain "chmod u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/catalog" Scenario: Check if the selected_custom file_access_task skips with empty selected_custom_file_access Given I extend the development capistrano configuration variable default_file_access_owner_of_shared_path with value 'test-user' @@ -101,20 +101,20 @@ Feature: Test tasks for namespace 'file_permissions' Given I extend the development capistrano configuration variable default_file_access_owner_of_shared_path with value 'test-user' And I extend the development capistrano configuration variable selected_custom_file_access with value [:catalog] When I successfully run `cap dev file_access:set_selected_custom_access` - Then the output should contain "sudo chown -R test-user /var/www/dkdeploy/current/catalog" + Then the output should contain "chown -R test-user /var/www/dkdeploy/current/catalog" Scenario: Check if the selected_custom_file_access task skips over not mentioned folders Given I extend the development capistrano configuration variable default_file_access_owner_of_shared_path with value 'test-user' And I extend the development capistrano configuration variable selected_custom_file_access with value ['another_directory'] When I successfully run `cap dev file_access:set_selected_custom_access` Then the output should contain "Skipped setting custom_file_access permissions for 'catalog' because it is not mentioned in selected_custom_file_access!" - And the output should not contain "sudo chown -R test-user /var/www/dkdeploy/current/catalog" + And the output should not contain "chown -R test-user /var/www/dkdeploy/current/catalog" Scenario: Check if the selected_custom_file_access task skips over not existing folders Given I extend the development capistrano configuration variable custom_file_access with value {app: {release_path: {catalog: {mode: 'u+rwx,g+rwx,o-wx'}, not_existing: {mode: 'u+rwx,g+rwx,o-wx'}}}} And I extend the development capistrano configuration variable selected_custom_file_access with value [:not_existing, :catalog] And a remote directory named "releases_path/not_existing" should not exist When I successfully run `cap dev file_access:set_selected_custom_access` - Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist on host dkdeploy-core.test" - And the output should not contain "sudo chmod -R u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/not_existing" - And the output should contain "sudo chmod -R u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/catalog" + Then the output should contain "The resource /var/www/dkdeploy/current/not_existing does not exist" + And the output should not contain "chmod -R u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/not_existing" + And the output should contain "chmod -R u+rwx,g+rwx,o-wx /var/www/dkdeploy/current/catalog" diff --git a/features/mysql.feature b/features/mysql.feature index c9cad3f..d107cbc 100644 --- a/features/mysql.feature +++ b/features/mysql.feature @@ -6,21 +6,21 @@ Feature: Test tasks for namespace 'mysql' And I want to use the database `dkdeploy_core` Scenario: Downloading the MYSQL slow log - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I successfully run `cap dev db:download_content` And I successfully run `cap dev mysql:download_slow_log` - Then a file named "temp/slow-queries.dev.dkdeploy-core.test.log" should exist + Then a file named "temp/slow-queries.dev.localhost.log" should exist Scenario: Downloading the MYSQL slow log analyze file - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I successfully run `cap dev db:download_content` And I successfully run `cap dev mysql:analyze_download_slow_log` - Then a file named "temp/mysql_slow_log_analyze.dev.dkdeploy-core.test.log" should exist + Then a file named "temp/mysql_slow_log_analyze.dev.localhost.log" should exist Scenario: Clearing the MySQL slow log file - When I successfully run `cap dev "db:upload_settings[127.0.0.1,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` + When I successfully run `cap dev "db:upload_settings[database,3306,dkdeploy_core,root,ilikerandompasswords,utf8]"` And I successfully run `cap dev "db:update[temp,dkdeploy_core.sql.gz]"` And I successfully run `cap dev db:download_content` And I successfully run `cap dev mysql:clear_slow_log` diff --git a/features/support/env.rb b/features/support/env.rb index f6db0b2..4a31733 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,22 +1,19 @@ require 'dkdeploy/test_environment/application' -ssh_config = {} +ssh_config = { + user: 'root', + keys: [File.join(Dir.getwd, 'config', 'docker', 'ssh', 'vagrant')], + port: '5001' +} -ssh_key_files = Dir.glob(File.join(Dir.getwd, '.vagrant', 'machines', '**', 'virtualbox', 'private_key')) -unless ssh_key_files.empty? - # Define generated ssh key files - ssh_config = { - user: 'vagrant', - keys: ssh_key_files - } -end - -TEST_APPLICATION = Dkdeploy::TestEnvironment::Application.new(File.expand_path('../..', __dir__), 'dkdeploy-core.test', ssh_config) -TEST_APPLICATION.mysql_connection_settings = { host: 'dkdeploy-core.test', username: 'root', password: 'ilikerandompasswords' } +TEST_APPLICATION = Dkdeploy::TestEnvironment::Application.new(File.expand_path('../..', __dir__), 'localhost', ssh_config) +TEST_APPLICATION.mysql_connection_settings = { host: '127.0.0.1', port: 5002, username: 'root', password: 'ilikerandompasswords' } # this configuration tricks Bundler into executing another Bundler project with clean enviroment # The official way via Bundler.with_clean_env did not work properly here Aruba.configure do |config| - config.command_runtime_environment = { 'BUNDLE_GEMFILE' => File.join(TEST_APPLICATION.test_app_path, 'Gemfile') } + config.command_runtime_environment = Bundler.original_env.merge( + { 'BUNDLE_GEMFILE' => File.join(TEST_APPLICATION.test_app_path, 'Gemfile') } + ) config.exit_timeout = 30 end diff --git a/features/utils.feature b/features/utils.feature index 0a3d0f4..f22a885 100644 --- a/features/utils.feature +++ b/features/utils.feature @@ -28,10 +28,10 @@ Feature: Test tasks for namespace 'utils' Remote file content """ When I successfully run `cap dev utils:download_file['download_file.txt']` - Then a file named "temp/download_file.dkdeploy-core.test.txt" should exist + Then a file named "temp/download_file.localhost.txt" should exist Scenario: Download a file from server which does exist locally - Given a file named "temp/download_file.dkdeploy-core.test.txt" with: + Given a file named "temp/download_file.localhost.txt" with: """ Local file content """ @@ -41,7 +41,7 @@ Local file content Remote file content """ When I successfully run `cap dev utils:download_file['download_file.txt']` - Then the file "temp/download_file.dkdeploy-core.test.txt" should contain exactly: + Then the file "temp/download_file.localhost.txt" should contain exactly: """ Remote file content diff --git a/lib/dkdeploy/interaction_handler/password.rb b/lib/dkdeploy/interaction_handler/password.rb index 8b5be05..073b25f 100644 --- a/lib/dkdeploy/interaction_handler/password.rb +++ b/lib/dkdeploy/interaction_handler/password.rb @@ -18,12 +18,7 @@ def initialize(password) # @param [String] data # @param [Net::SSH::Connection::Channel] channel def on_data(_command, _stream_name, data, channel) - if data =~ /.*password.*/i - channel.send_data("#{@password}\n") - else - channel.close - raise 'Unexpected data from stream. Can not send password to undefined stream.' - end + channel.send_data("#{@password}\n") if data =~ /.*password.*/i end end end diff --git a/spec/fixtures/application/config/deploy.rb b/spec/fixtures/application/config/deploy.rb index b303dce..fefea45 100644 --- a/spec/fixtures/application/config/deploy.rb +++ b/spec/fixtures/application/config/deploy.rb @@ -1,9 +1,6 @@ set :application, 'test_app' SSHKit.config.command_map.prefix[:compass].push 'bundle exec' -SSHKit.config.command_map.prefix[:chown].push 'sudo' -SSHKit.config.command_map.prefix[:chgrp].push 'sudo' -SSHKit.config.command_map.prefix[:chmod].push 'sudo' set :asset_folders, %w[download] set :asset_default_content, %w[download] @@ -32,7 +29,7 @@ charset: 'utf8', username: 'root', password: 'ilikerandompasswords', - host: '127.0.0.1', + host: 'database', port: 3306, name: 'dkdeploy_core' } diff --git a/spec/fixtures/application/config/deploy/dev.rb b/spec/fixtures/application/config/deploy/dev.rb index 81b2f87..92f7e45 100644 --- a/spec/fixtures/application/config/deploy/dev.rb +++ b/spec/fixtures/application/config/deploy/dev.rb @@ -1,22 +1,12 @@ set :deploy_to, '/var/www/dkdeploy' -server 'dkdeploy-core.test', roles: %w[web app backend db], primary: true +server 'root@localhost:5001', roles: %w[web app backend db], primary: true # no ssh compression on the dev stage set :ssh_options, { - compression: 'none' + compression: 'none', + keys: [File.join(Dir.getwd, '..', '..', 'config', 'docker', 'ssh', 'vagrant')] } -ssh_key_files = Dir.glob(File.join(Dir.getwd, '..', '..', '.vagrant', 'machines', '**', 'virtualbox', 'private_key')) -unless ssh_key_files.empty? - # Define generated ssh key files - set :ssh_options, fetch(:ssh_options).merge( - { - user: 'vagrant', - keys: ssh_key_files - } - ) -end - set :copy_source, 'htdocs' set :copy_exclude, %w[ Gemfile* @@ -28,11 +18,11 @@ set :version_file_path, '' # default file owner/group for dev stage -set :default_file_access_owner_of_shared_path, 'vagrant' -set :default_file_access_owner_of_release_path, 'vagrant' +set :default_file_access_owner_of_shared_path, 'root' +set :default_file_access_owner_of_release_path, 'root' -set :default_file_access_group_of_shared_path, 'vagrant' -set :default_file_access_group_of_release_path, 'vagrant' +set :default_file_access_group_of_shared_path, 'root' +set :default_file_access_group_of_release_path, 'root' # mysql slow query log for performance analysis -set :mysql_slow_log, '/var/log/mysql-default/slow-queries.log' +set :mysql_slow_log, '/var/log/mysql/slow-queries.log'