diff --git a/Dockerfile.development b/Dockerfile.development index ebe208d1..fa0b9db6 100644 --- a/Dockerfile.development +++ b/Dockerfile.development @@ -6,8 +6,7 @@ WORKDIR $APP_HOME COPY Gemfile $APP_HOME/ COPY Gemfile.lock $APP_HOME/ -RUN bundle config set without 'development test' && \ - MAKE="make -j $(nproc)" bundle install -j $(nproc) +RUN MAKE="make -j $(nproc)" bundle install -j $(nproc) FROM --platform=linux/amd64 ruby:2.7.7 diff --git a/Makefile b/Makefile index c5a4cc68..13ad4db4 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,24 @@ init: build: init docker-compose build setup: build - docker-compose run --rm web bash -c 'export MAKE="make -j `nproc`" && bundle install -j `nproc`' - docker-compose run --rm web bundle exec bin/setup + docker-compose run --rm -e BUNDLE_IGNORE_CONFIG=true test bash -c 'export MAKE="make -j `nproc`" && bundle install -j `nproc`' + docker-compose run --rm test bundle exec bin/setup docker-compose stop - docker-compose down up: init docker-compose up -d restart: - docker-compose restart web worker + docker-compose restart web worker test +dbreset: down + docker volume rm -f barcelona_pgdata + docker-compose up -d + docker-compose run --rm test bundle exec bin/setup +down: + # make sure e2e process is not attached to this network + docker ps -a | grep barcelona-e2e-e2e | cut -d' ' -f1 | xargs docker rm -f + docker-compose down -t 0 +bundle-reset: down + docker volume rm -f barcelona_bundle + docker volume ls + docker-compose run --rm -e BUNDLE_IGNORE_CONFIG=true test bash -c 'export MAKE="make -j `nproc`" && bundle install -j `nproc`' +test: + docker-compose run --rm -e RAILS_ENV=test test bundle exec rspec -f d \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 979469f4..8423f55c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: web: &app_base depends_on: @@ -9,7 +9,7 @@ services: dockerfile: Dockerfile ports: - "3333:3333" - command: rails s -b 0.0.0.0 + command: rails s -b 0.0.0.0 -P /tmp/server.pid stdin_open: true tty: true links: @@ -17,7 +17,7 @@ services: - vault volumes: - bundle:/usr/local/bundle - # - .:/app + - .:/app environment: &env_base PORT: 3333 DATABASE_URL: postgres://postgres:@db:5432 @@ -29,6 +29,13 @@ services: # Uncomment to use vault auth # VAULT_URL: http://vault:8200 # VAULT_PATH_PREFIX: degica + worker: + <<: *app_base + ports: [] + command: rake jobs:work + volumes: + - bundle:/usr/local/bundle + - .:/app test: <<: *app_base build: @@ -36,10 +43,9 @@ services: dockerfile: Dockerfile.development ports: [] command: sleep infinity - worker: - <<: *app_base - ports: [] - command: rake jobs:work + volumes: + - bundle:/usr/local/bundle + - .:/app db: image: postgres:11 environment: diff --git a/lib/barcelona/plugins/datadog_logs_plugin.rb b/lib/barcelona/plugins/datadog_logs_plugin.rb index d281133d..abba54a0 100644 --- a/lib/barcelona/plugins/datadog_logs_plugin.rb +++ b/lib/barcelona/plugins/datadog_logs_plugin.rb @@ -20,18 +20,6 @@ def on_container_instance_user_data(_instance, user_data) user_data end - def on_heritage_task_definition(_heritage, task_definition) - task_definition.merge( - log_configuration: { - log_driver: "syslog", - options: { - "syslog-address" => "tcp://127.0.0.1:#{LOCAL_LOGGER_PORT}", - "tag" => "{{.FullID}}_#{task_definition[:name]}" - } - } - ) - end - def on_network_stack_template(_stack, template) bastion_lc = template["BastionLaunchConfiguration"] return template if bastion_lc.nil? diff --git a/lib/barcelona/plugins/datadog_plugin.rb b/lib/barcelona/plugins/datadog_plugin.rb index b4485b32..dd90da99 100644 --- a/lib/barcelona/plugins/datadog_plugin.rb +++ b/lib/barcelona/plugins/datadog_plugin.rb @@ -12,6 +12,19 @@ def on_container_instance_user_data(_instance, user_data) private + def on_heritage_task_definition(_heritage, task_definition) + # disable awslogs, but make sure logs do not fill up disk + task_definition.merge( + log_configuration: { + log_driver: "json-file", + options: { + "max-size" => "1m", + "tag" => "{{.FullID}}_#{task_definition[:name]}" + } + } + ) + end + def agent_command [ "DD_AGENT_MAJOR_VERSION=7 DD_API_KEY=#{api_key} bash -c", @@ -27,6 +40,7 @@ def api_key end def add_files!(user_data) + # this seems to be added to the bastion instance as well. "role:app" should probably be "role:bastion" to be accurate user_data.add_file("/etc/datadog-agent/datadog.yaml", "root:root", "000755", <<~DATADOG_YAML) api_key: #{api_key} logs_enabled: true diff --git a/lib/barcelona/plugins/logentries_plugin.rb b/lib/barcelona/plugins/logentries_plugin.rb index 8e255102..189ac98e 100644 --- a/lib/barcelona/plugins/logentries_plugin.rb +++ b/lib/barcelona/plugins/logentries_plugin.rb @@ -7,32 +7,34 @@ class LogentriesPlugin < Base "service rsyslog restart" ] - def on_container_instance_user_data(_instance, user_data) - update_user_data(user_data, "app") - user_data - end + # NOTE: disabling this temporarily until we delete the plugin - def on_heritage_task_definition(_heritage, task_definition) - task_definition.merge( - log_configuration: { - log_driver: "syslog", - options: { - "syslog-address" => "tcp://127.0.0.1:#{LOCAL_LOGGER_PORT}", - "tag" => "{{.FullID}}_#{task_definition[:name]}" - } - } - ) - end + # def on_container_instance_user_data(_instance, user_data) + # update_user_data(user_data, "app") + # user_data + # end - def on_network_stack_template(_stack, template) - bastion_lc = template["BastionLaunchConfiguration"] - return template if bastion_lc.nil? + # def on_heritage_task_definition(_heritage, task_definition) + # task_definition.merge( + # log_configuration: { + # log_driver: "syslog", + # options: { + # "syslog-address" => "tcp://127.0.0.1:#{LOCAL_LOGGER_PORT}", + # "tag" => "{{.FullID}}_#{task_definition[:name]}" + # } + # } + # ) + # end - user_data = InstanceUserData.load_or_initialize(bastion_lc["Properties"]["UserData"]) - update_user_data(user_data, "bastion") - bastion_lc["Properties"]["UserData"] = user_data.build - template - end + # def on_network_stack_template(_stack, template) + # bastion_lc = template["BastionLaunchConfiguration"] + # return template if bastion_lc.nil? + + # user_data = InstanceUserData.load_or_initialize(bastion_lc["Properties"]["UserData"]) + # update_user_data(user_data, "bastion") + # bastion_lc["Properties"]["UserData"] = user_data.build + # template + # end private diff --git a/spec/lib/barcelona/plugins/logentries_plugin_spec.rb b/spec/lib/barcelona/plugins/logentries_plugin_spec.rb deleted file mode 100644 index 288fb11f..00000000 --- a/spec/lib/barcelona/plugins/logentries_plugin_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'rails_helper' - -module Barcelona - module Plugins - describe LogentriesPlugin do - let!(:district) do - create :district, bastion_key_pair: "bastion", plugins_attributes: [ - { - name: 'logentries', - plugin_attributes: { - token: "logentries_token" - } - } - ] - end - - it "gets hooked with heritage_task_definition trigger" do - heritage = district.heritages.create(name: 'heritage', - image_name: "docker_image", - env_vars_attributes: [ - {key: "ENVIRONMENT", value: "VALUE"} - ]) - definition = heritage.base_task_definition("heritage") - expect(definition[:name]).to eq "heritage" - expect(definition[:log_configuration]).to eq(log_driver: "syslog", - options: { - "syslog-address" => "tcp://127.0.0.1:514", - "tag" => "{{.FullID}}_heritage" - }) - end - - it "gets hooked with container_instance_user_data trigger" do - ci = ContainerInstance.new(district) - user_data = YAML.load(Base64.decode64(ci.user_data.build)) - - conf_file = user_data["write_files"].find{ |f| f["path"] == "/etc/rsyslog.d/barcelona-logger.conf" } - expect(conf_file["path"]).to eq "/etc/rsyslog.d/barcelona-logger.conf" - expect(conf_file["owner"]).to eq "root:root" - expect(conf_file["permissions"]).to eq "644" - expect(conf_file["content"]).to be_a String - expect(user_data["runcmd"]).to include(*described_class::RUN_COMMANDS) - end - - it "gets hooked with network_stack_template trigger" do - template = JSON.load(::Barcelona::Network::NetworkStack.new(district).target!) - user_data = InstanceUserData.load(template["Resources"]["BastionLaunchConfiguration"]["Properties"]["UserData"]) - expect(user_data.packages).to include(*described_class::SYSTEM_PACKAGES) - expect(user_data.run_commands).to include(*described_class::RUN_COMMANDS) - end - end - end -end