Skip to content

Commit

Permalink
Add bootleg.init Mix task. (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
holetse authored and brienw committed Jul 21, 2017
1 parent e1e9468 commit f073c48
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ end

## Quick Start

### Initalize your project

```sh
$ mix bootleg.init
```

### Configure your release parameters

```elixir
Expand Down
49 changes: 49 additions & 0 deletions lib/mix/tasks/init.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
defmodule Mix.Tasks.Bootleg.Init do
use Bootleg.Task
require Mix.Generator
alias Mix.Generator

@shortdoc "Initializes a project for use with Bootleg"

@moduledoc """
Initializes a project for use with Bootleg.
"""

def run(_args) do
deploy_file_path = Path.join(["config", "deploy.exs"])
Generator.create_directory("config")
Generator.create_file(deploy_file_path, deploy_file_text())
end

Generator.embed_text(:deploy_file, """
use Bootleg.Config
# Configure the following roles to match your environment.
# `build` defines what remote server your distillery release should be built on.
# `app` defines what remote servers your distillery release should be deployed and managed on.
#
# Some available options are:
# - `user`: ssh username to use for SSH authentication to the role's hosts
# - `password`: password to be used for SSH authentication
# - `identity`: local path to an identity file that will be used for SSH authentication instead of a password
# - `workspace`: remote file system path to be used for building and deploying this Elixir project
role :build, "build.example.com", workspace: "/tmp/bootleg/build"
role :app, ["app1.example.com", "app2.example.com"], workspace: "/var/app/example"
# Phoenix has some extra build steps which can be defined as task after the compile step runs.
#
# Uncomment the following task definition if this is a Phoenix application. To learn more about
# hooks and adding additional behavior to your deploy workflow, please refer to the bootleg
# README which can be found at https://github.com/labzero/bootleg/blob/master/README.md
# after_task :compile do
# remote :build do
# "[ -f package.json ] && npm install || true"
# "[ -f brunch-config.js ] && [ -d node_modules ] && ./node_modules/brunch/bin/brunch b -p || true"
# "[ -d deps/phoenix ] && mix phoenix.digest || true"
# end
# end
""")

end
10 changes: 10 additions & 0 deletions test/bootleg_functional_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ defmodule Bootleg.FunctionalTest do
end)
end

@tag boot: 0
test "init" do
shell_env = [{"BOOTLEG_PATH", File.cwd!}]
location = Fixtures.inflate_project(:n00b)
Enum.each(["deps.get", "bootleg.init"], fn cmd ->
assert {_, 0} = System.cmd("mix", [cmd], [env: shell_env, cd: location])
end)
assert File.regular?(Path.join([location, "config", "deploy.exs"]))
end

end
3 changes: 3 additions & 0 deletions test/fixtures/n00b/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/_build
/deps
/releases
30 changes: 30 additions & 0 deletions test/fixtures/n00b/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure for your application as:
#
# config :n00b, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:n00b, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
18 changes: 18 additions & 0 deletions test/fixtures/n00b/lib/n00b.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule N00b do
@moduledoc """
Documentation for N00b.
"""

@doc """
Hello world.
## Examples
iex> N00b.hello
:world
"""
def hello do
:world
end
end
36 changes: 36 additions & 0 deletions test/fixtures/n00b/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule N00b.Mixfile do
use Mix.Project

def project do
[app: :n00b,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end

# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
def application do
# Specify extra applications you'll use from Erlang/Elixir
[extra_applications: [:logger]]
end

# Dependencies can be Hex packages:
#
# {:my_dep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
#
# Type "mix help deps" for more examples and options
defp deps do
[
{:distillery, "~> 1.4", runtime: false},
{:bootleg, ">= 0.0.0", path: System.get_env("BOOTLEG_PATH"), runtime: false}
]
end
end

0 comments on commit f073c48

Please sign in to comment.