-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from maxfierke/mf-rustup
Implement rustup as a possible runtime manager
- Loading branch information
Showing
38 changed files
with
533 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,12 +317,12 @@ Spectator.describe MStrap::Configuration do | |
end | ||
end | ||
|
||
describe "#runtime_manager" do | ||
describe "#default_runtime_manager" do | ||
context "for v1.0 configs" do | ||
subject { MStrap::Configuration.new(config_def_v1_0) } | ||
|
||
it "defaults to asdf" do | ||
expect(subject.runtime_manager).to be_a(MStrap::RuntimeManagers::ASDF) | ||
expect(subject.default_runtime_manager).to be_a(MStrap::RuntimeManagers::ASDF) | ||
end | ||
end | ||
|
||
|
@@ -350,7 +350,120 @@ Spectator.describe MStrap::Configuration do | |
subject { MStrap::Configuration.new(config_def_v1_1) } | ||
|
||
it "can be set through runtimes.default_manager" do | ||
expect(subject.runtime_manager).to be_a(MStrap::RuntimeManagers::Mise) | ||
expect(subject.default_runtime_manager).to be_a(MStrap::RuntimeManagers::Mise) | ||
end | ||
end | ||
end | ||
|
||
describe "#runtime_managers" do | ||
context "for v1.0 configs" do | ||
subject { MStrap::Configuration.new(config_def_v1_0) } | ||
|
||
it "defaults to [asdf]" do | ||
expect(subject.runtime_managers).to eq([MStrap::RuntimeManager.for("asdf")]) | ||
end | ||
end | ||
|
||
context "for v1.1 configs" do | ||
let(config_def_v1_1) do | ||
MStrap::Defs::ConfigDef.from_hcl(<<-HCL) | ||
version = "1.1" | ||
runtimes { | ||
default_manager = "mise" | ||
runtime "rust" { | ||
manager = "rustup" | ||
} | ||
} | ||
user { | ||
name = "Reginald Testington" | ||
email = "[email protected]" | ||
} | ||
profile "personal" { | ||
url = "ssh://[email protected]/reggiemctest/mstrap-personal.git" | ||
} | ||
HCL | ||
end | ||
|
||
subject { MStrap::Configuration.new(config_def_v1_1) } | ||
|
||
it "it derived through runtimes.default_manager and runtimes.runtime[*].manager" do | ||
expect(subject.runtime_managers).to eq([ | ||
MStrap::RuntimeManager.for("mise"), | ||
MStrap::RuntimeManager.for("rustup"), | ||
]) | ||
end | ||
end | ||
end | ||
|
||
describe "#runtimes" do | ||
context "for v1.0 configs" do | ||
subject { MStrap::Configuration.new(config_def_v1_0) } | ||
|
||
it "defaults all to ASDF-provided runtimes" do | ||
%w(crystal go node php python ruby rust).each do |language_name| | ||
expect(subject.runtimes[language_name].runtime_manager).to be_a(MStrap::RuntimeManagers::ASDF) | ||
end | ||
end | ||
|
||
it "returns the expected language runtimes" do | ||
expect(subject.runtimes["crystal"]).to be_a(MStrap::Runtimes::Crystal) | ||
expect(subject.runtimes["go"]).to be_a(MStrap::Runtimes::Go) | ||
expect(subject.runtimes["node"]).to be_a(MStrap::Runtimes::Node) | ||
expect(subject.runtimes["php"]).to be_a(MStrap::Runtimes::Php) | ||
expect(subject.runtimes["python"]).to be_a(MStrap::Runtimes::Python) | ||
expect(subject.runtimes["ruby"]).to be_a(MStrap::Runtimes::Ruby) | ||
expect(subject.runtimes["rust"]).to be_a(MStrap::Runtimes::Rust) | ||
end | ||
end | ||
|
||
context "for v1.1 configs" do | ||
let(config_def_v1_1) do | ||
MStrap::Defs::ConfigDef.from_hcl(<<-HCL) | ||
version = "1.1" | ||
runtimes { | ||
default_manager = "mise" | ||
runtime "rust" { | ||
manager = "rustup" | ||
} | ||
} | ||
user { | ||
name = "Reginald Testington" | ||
email = "[email protected]" | ||
} | ||
profile "personal" { | ||
url = "ssh://[email protected]/reggiemctest/mstrap-personal.git" | ||
} | ||
HCL | ||
end | ||
|
||
subject { MStrap::Configuration.new(config_def_v1_1) } | ||
|
||
it "allows overriding language manager for specific languages" do | ||
%w(crystal go node php python ruby).each do |language_name| | ||
expect(subject.runtimes[language_name].runtime_manager).to be_a(MStrap::RuntimeManagers::Mise) | ||
end | ||
|
||
expect(subject.runtimes["rust"].runtime_manager).to be_a(MStrap::RuntimeManagers::Rustup) | ||
end | ||
|
||
it "returns the expected language runtimes" do | ||
expect(subject.runtimes["crystal"]).to be_a(MStrap::Runtimes::Crystal) | ||
expect(subject.runtimes["go"]).to be_a(MStrap::Runtimes::Go) | ||
expect(subject.runtimes["node"]).to be_a(MStrap::Runtimes::Node) | ||
expect(subject.runtimes["php"]).to be_a(MStrap::Runtimes::Php) | ||
expect(subject.runtimes["python"]).to be_a(MStrap::Runtimes::Python) | ||
expect(subject.runtimes["ruby"]).to be_a(MStrap::Runtimes::Ruby) | ||
expect(subject.runtimes["rust"]).to be_a(MStrap::Runtimes::Rust) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module MStrap | ||
abstract class Bootstrapper | ||
include DSL | ||
|
||
def initialize(@config : Configuration) | ||
end | ||
|
||
def self.for(config : Configuration, project : Project) : Array(Bootstrapper) | ||
bootstrappers = Array(Bootstrapper).new | ||
|
||
if project.run_scripts? && Bootstrappers::ScriptBootstrapper.has_scripts?(project) | ||
bootstrappers << Bootstrappers::ScriptBootstrapper.new(config) | ||
else | ||
bootstrappers << Bootstrappers::DefaultBootstrapper.new(config) | ||
|
||
if project.web? | ||
bootstrappers << Bootstrappers::WebBootstrapper.new(config) | ||
end | ||
end | ||
|
||
bootstrappers | ||
end | ||
|
||
abstract def bootstrap(project : Project) : Bool | ||
|
||
protected getter :config | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module MStrap | ||
module Bootstrappers | ||
class DefaultBootstrapper < Bootstrapper | ||
# Conventional bootstrapping from mstrap. This will auto-detect the runtimes | ||
# used by the project and run the standard bootstrapping for each runtime. | ||
# This **does not** run any bootstrapping scripts, and is used mainly for | ||
# calling into conventional bootstrapping within a project's | ||
# `script/bootstrap` or `script/setup` from `mstrap project`. | ||
def bootstrap(project : Project) : Bool | ||
logd "Bootstrapping '#{project.name}' with runtime defaults." | ||
|
||
runtime_impls(project).each_value do |runtime| | ||
Dir.cd(project.path) do | ||
if runtime.matches? | ||
logd "Detected #{runtime.language_name}. Installing #{runtime.language_name}, project #{runtime.language_name} packages, and other relevant dependencies" | ||
runtime.setup | ||
end | ||
end | ||
end | ||
|
||
true | ||
end | ||
|
||
def runtime_impls(project) | ||
if project.runtimes.empty? | ||
config.runtimes | ||
else | ||
config.runtimes.select do |_, runtime| | ||
project.runtimes.includes?(runtime.language_name) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module MStrap | ||
module Bootstrappers | ||
class ScriptBootstrapper < Bootstrapper | ||
# :nodoc: | ||
BOOTSTRAP_SCRIPT = File.join("script", "bootstrap") | ||
|
||
# :nodoc: | ||
SETUP_SCRIPT = File.join("script", "setup") | ||
|
||
# Executes `script/bootstrap` and `script/setup` (if either exists and are | ||
# configured to run) | ||
def bootstrap(project : Project) : Bool | ||
logd "Found bootstrapping scripts, executing instead of using defaults." | ||
|
||
begin | ||
ENV["__MSTRAP_EXEC_SCRIPTS"] = "true" | ||
|
||
Dir.cd(project.path) do | ||
cmd BOOTSTRAP_SCRIPT if File.exists?(BOOTSTRAP_SCRIPT) | ||
cmd SETUP_SCRIPT if File.exists?(SETUP_SCRIPT) | ||
end | ||
ensure | ||
ENV.delete("__MSTRAP_EXEC_SCRIPTS") | ||
end | ||
|
||
true | ||
end | ||
|
||
# Whether project has any bootstrapping/setup scripts a-la | ||
# [`scripts-to-rule-them-all`](https://github.com/github/scripts-to-rule-them-all) | ||
def self.has_scripts?(project) | ||
[BOOTSTRAP_SCRIPT, SETUP_SCRIPT].any? do |script_path| | ||
File.exists?(File.join(project.path, script_path)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module MStrap | ||
module Bootstrappers | ||
# The `WebBootstrapper` is responsible for bootstrapping web-based projects. | ||
# Currently, this is just setting up an NGINX configuration for the project. | ||
class WebBootstrapper < Bootstrapper | ||
include DSL | ||
|
||
def initialize(@config : Configuration) | ||
super | ||
@mkcert = Mkcert.new | ||
end | ||
|
||
# Executes the bootstrapper | ||
def bootstrap(project : Project) : Bool | ||
logd "'#{project.name}' is a web project. Running web bootstrapper." | ||
|
||
if mkcert.installed? | ||
Dir.cd(Paths::PROJECT_CERTS) do | ||
mkcert.install! | ||
mkcert.install_cert!(project.hostname) | ||
end | ||
else | ||
logw "mkcert not found. Skipping cert setup." | ||
end | ||
|
||
Templates::NginxConf.new(project).write_to_config! | ||
true | ||
end | ||
|
||
private getter :mkcert | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module MStrap | ||
module Defs | ||
class RuntimeConfigDef | ||
include HCL::Serializable | ||
|
||
@[HCL::Label] | ||
property name : String | ||
|
||
@[HCL::Attribute] | ||
property manager : String? = nil | ||
|
||
def_equals_and_hash @name, @manager | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.