aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/config/manifest.js2
-rw-r--r--app/assets/javascripts/mini_environments.js2
-rw-r--r--app/assets/stylesheets/application.scss1
-rw-r--r--app/channels/application_cable/channel.rb4
-rw-r--r--app/channels/application_cable/connection.rb4
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--app/controllers/mini_environments_controller.rb21
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/mini_environments_helper.rb2
-rw-r--r--app/jobs/setup_job.rb5
-rw-r--r--app/jobs/terraform_job.rb17
-rw-r--r--app/mailers/application_mailer.rb4
-rw-r--r--app/models/application_record.rb3
-rw-r--r--app/models/finished_terraform_job.rb3
-rw-r--r--app/models/mini_environment.rb3
-rw-r--r--app/models/user.rb5
-rw-r--r--app/views/layouts/application.html.erb8
-rw-r--r--app/views/mini_environments/index.html.erb8
-rw-r--r--app/views/mini_environments/new.html.erb5
-rw-r--r--app/views/mini_environments/show.html.erb6
20 files changed, 111 insertions, 0 deletions
diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js
new file mode 100644
index 0000000..5918193
--- /dev/null
+++ b/app/assets/config/manifest.js
@@ -0,0 +1,2 @@
+//= link_tree ../images
+//= link_directory ../stylesheets .css
diff --git a/app/assets/javascripts/mini_environments.js b/app/assets/javascripts/mini_environments.js
new file mode 100644
index 0000000..dee720f
--- /dev/null
+++ b/app/assets/javascripts/mini_environments.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
new file mode 100644
index 0000000..ba2ffbf
--- /dev/null
+++ b/app/assets/stylesheets/application.scss
@@ -0,0 +1 @@
+@import 'govuk_admin_template';
diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb
new file mode 100644
index 0000000..d672697
--- /dev/null
+++ b/app/channels/application_cable/channel.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Channel < ActionCable::Channel::Base
+ end
+end
diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb
new file mode 100644
index 0000000..0ff5442
--- /dev/null
+++ b/app/channels/application_cable/connection.rb
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Connection < ActionCable::Connection::Base
+ end
+end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
new file mode 100644
index 0000000..85c44e9
--- /dev/null
+++ b/app/controllers/application_controller.rb
@@ -0,0 +1,6 @@
+class ApplicationController < ActionController::Base
+ include GDS::SSO::ControllerMethods
+ before_action :authenticate_user!
+
+ protect_from_forgery with: :exception
+end
diff --git a/app/controllers/mini_environments_controller.rb b/app/controllers/mini_environments_controller.rb
new file mode 100644
index 0000000..c45ed4a
--- /dev/null
+++ b/app/controllers/mini_environments_controller.rb
@@ -0,0 +1,21 @@
+class MiniEnvironmentsController < ApplicationController
+ def show
+ @mini_environment = MiniEnvironment.find(params[:id])
+ end
+
+ def new
+ @mini_environment = MiniEnvironment.new
+ end
+
+ def create
+ ActiveRecord::Base.transaction do
+ @mini_environment = MiniEnvironment.create(
+ params.require(:mini_environment).permit(:name)
+ )
+
+ SetupJob.enqueue(@mini_environment.id)
+ end
+
+ redirect_to @mini_environment
+ end
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
new file mode 100644
index 0000000..de6be79
--- /dev/null
+++ b/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff --git a/app/helpers/mini_environments_helper.rb b/app/helpers/mini_environments_helper.rb
new file mode 100644
index 0000000..4990a52
--- /dev/null
+++ b/app/helpers/mini_environments_helper.rb
@@ -0,0 +1,2 @@
+module MiniEnvironmentsHelper
+end
diff --git a/app/jobs/setup_job.rb b/app/jobs/setup_job.rb
new file mode 100644
index 0000000..c7b1b80
--- /dev/null
+++ b/app/jobs/setup_job.rb
@@ -0,0 +1,5 @@
+class SetupJob < TerraformJob
+ def run_terraform
+ puts "Setting up #{@mini_environment.name}"
+ end
+end
diff --git a/app/jobs/terraform_job.rb b/app/jobs/terraform_job.rb
new file mode 100644
index 0000000..739a5b5
--- /dev/null
+++ b/app/jobs/terraform_job.rb
@@ -0,0 +1,17 @@
+class TerraformJob < Que::Job
+ def run(mini_environment_id)
+ ActiveRecord::Base.transaction do
+ @mini_environment = MiniEnvironment.find(mini_environment_id)
+
+ run_terraform
+ end
+ end
+
+ def destroy
+ FinishedTerraformJob.create(
+ mini_environment_id: @mini_environment.id,
+ job_class: attrs[:job_class]
+ )
+ super
+ end
+end
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
new file mode 100644
index 0000000..286b223
--- /dev/null
+++ b/app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
+class ApplicationMailer < ActionMailer::Base
+ default from: 'from@example.com'
+ layout 'mailer'
+end
diff --git a/app/models/application_record.rb b/app/models/application_record.rb
new file mode 100644
index 0000000..10a4cba
--- /dev/null
+++ b/app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+end
diff --git a/app/models/finished_terraform_job.rb b/app/models/finished_terraform_job.rb
new file mode 100644
index 0000000..7ada6bd
--- /dev/null
+++ b/app/models/finished_terraform_job.rb
@@ -0,0 +1,3 @@
+class FinishedTerraformJob < ApplicationRecord
+ belongs_to :mini_environment
+end
diff --git a/app/models/mini_environment.rb b/app/models/mini_environment.rb
new file mode 100644
index 0000000..d53a8b1
--- /dev/null
+++ b/app/models/mini_environment.rb
@@ -0,0 +1,3 @@
+class MiniEnvironment < ApplicationRecord
+ has_many :finished_terraform_jobs, dependent: :destroy
+end
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 0000000..4ca70b3
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,5 @@
+class User < ApplicationRecord
+ include GDS::SSO::User
+
+ serialize :permissions, Array
+end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
new file mode 100644
index 0000000..5b90ace
--- /dev/null
+++ b/app/views/layouts/application.html.erb
@@ -0,0 +1,8 @@
+<% content_for :head do %>
+ <%= stylesheet_link_tag "application", :media => "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tag %>
+ <%= yield :extra_headers %>
+<% end %>
+
+<%= render template: 'layouts/govuk_admin_template' %>
diff --git a/app/views/mini_environments/index.html.erb b/app/views/mini_environments/index.html.erb
new file mode 100644
index 0000000..11d5a79
--- /dev/null
+++ b/app/views/mini_environments/index.html.erb
@@ -0,0 +1,8 @@
+
+<a href="<%= new_mini_environment_path %>">Create new mini environment</a>
+
+<% MiniEnvironment.all.each do |mini_environment| %>
+ <a href="<%= mini_environment_path mini_environment %>">
+ <h2><%= mini_environment.name %></h2>
+ </a>
+<% end %>
diff --git a/app/views/mini_environments/new.html.erb b/app/views/mini_environments/new.html.erb
new file mode 100644
index 0000000..4a4712e
--- /dev/null
+++ b/app/views/mini_environments/new.html.erb
@@ -0,0 +1,5 @@
+
+<%= form_for @mini_environment, url: {action: "create"} do |f| %>
+ <%= f.text_field :name %>
+ <%= f.submit "Create" %>
+<% end %>
diff --git a/app/views/mini_environments/show.html.erb b/app/views/mini_environments/show.html.erb
new file mode 100644
index 0000000..2d8988c
--- /dev/null
+++ b/app/views/mini_environments/show.html.erb
@@ -0,0 +1,6 @@
+<h1>Name: <%= @mini_environment.name %></h1>
+
+<% @mini_environment.finished_terraform_jobs.each do |job| %>
+ <%= job.job_class %>
+ <%= job.created_at %>
+<% end %>