openSUSE/open-build-service

View on GitHub
Rakefile

Summary

Maintainability
Test Coverage
CONTAINER_USERID = %x(id -u).freeze

namespace :docker do
  desc 'Build our development environment'
  task :build do
    # Setup the git commit message template
    sh 'git config commit.template .gitmessage'
    sh 'touch docker-files/home/.bash_history docker-files/home/.irb_history docker-files/home/.pry_history'
    sh "cat << EOF > docker-compose.override.yml
# This file is generated by our Rakefile. Do not change it!
services:
  frontend:
    build:
      args:
        CONTAINER_USERID: #{CONTAINER_USERID}
    volumes:
      - ./docker-files/home/.bash_history:/home/frontend/.bash_history:Z
      - ./docker-files/home/.irb_history:/home/frontend/.irb_history:Z
      - ./docker-files/home/.pry_history:/home/frontend/.pry_history:Z
      - ./docker-files/home/.irbrc:/home/frontend/.irbrc:Z
      - ./docker-files/home/.pryrc:/home/frontend/.pryrc:Z
EOF"
    sh "cat << EOF > docker-compose.minitest-user.yml
# This file is generated by our Rakefile. Do not change it!
services:
  minitest:
    build:
      args:
        CONTAINER_USERID: #{CONTAINER_USERID}
EOF"
    # Build the frontend container and pull newer version of the image if available
    sh 'docker compose build --pull frontend'
    # Build the minitest container on top of that
    sh 'docker compose -f docker-compose.yml -f docker-compose.minitest.yml -f docker-compose.minitest-user.yml build --pull minitest'
    # Bootstrap the app
    sh 'docker compose up -d db'
    sh 'docker compose run --no-deps --rm frontend bundle exec rake dev:bootstrap RAILS_ENV=development'
  ensure
    sh 'docker compose stop'
  end

  namespace :sre do
    desc 'Prepare the application health monitoring containers'
    task :build do
      sh 'docker compose -f docker-compose.sre.yml -f docker-compose.yml up -d rabbit'
      sh 'wget http://localhost:15672/cli/rabbitmqadmin -O contrib/rabbitmqadmin'
      sh 'chmod +x contrib/rabbitmqadmin'
      sh './contrib/rabbitmqadmin declare exchange name=pubsub type=topic durable=true auto_delete=false internal=false'
      # configure the app
      sh 'docker compose -f docker-compose.sre.yml -f docker-compose.yml up -d db'
      sh 'docker compose -f docker-compose.sre.yml -f docker-compose.yml run --no-deps --rm frontend bundle exec rake dev:sre:configure'
    ensure
      sh 'docker compose -f docker-compose.sre.yml -f docker-compose.yml stop'
    end
  end
end