Skip to content

Commit 025909d

Browse files
rjanjabrienw
authored andcommitted
Add docker build option, mkdocs documentation (#264)
* Revise documentation
1 parent 5f4baee commit 025909d

38 files changed

+1225
-666
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ erl_crash.dump
2020
*.ez
2121
/_site
2222
/.sass-cache
23+
24+
# Ignore virtualenv, used for building documentation
25+
/_venv

docs/about.md

-55
This file was deleted.

docs/config.md

-92
This file was deleted.

docs/config/build.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Build Strategies
2+
3+
Bootleg aims to cover the most common build strategies. Because the architecture on which your code runs must be the same as that with which your application was compiled, it's important to build your app in the right environment.
4+
5+
## Supported build strategies
6+
7+
### Local Machine
8+
9+
To build your app on the same machine where you're running Bootleg, just set the `#!elixir :build_type` config option:
10+
11+
!!! example "config/deploy.exs"
12+
```elixir
13+
use Bootleg.DSL
14+
15+
config(:build_type, :local)
16+
```
17+
18+
### Docker Container
19+
20+
To build your app within a Docker container, create a Dockerfile that reproduces the server environment you are targeting.
21+
22+
#### Create a Dockerfile
23+
24+
Create a file named `Dockerfile.build` in your project directory.
25+
26+
!!! note "Dockerfile.build"
27+
```docker
28+
FROM ubuntu:16.04
29+
30+
ENV REFRESHED_AT=2018-08-16 \
31+
LANG=en_US.UTF-8 \
32+
HOME=/opt/build \
33+
TERM=xterm
34+
35+
WORKDIR /opt/build
36+
37+
RUN \
38+
apt-get update -y && \
39+
apt-get install -y git wget vim locales && \
40+
locale-gen en_US.UTF-8 && \
41+
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && \
42+
dpkg -i erlang-solutions_1.0_all.deb && \
43+
rm erlang-solutions_1.0_all.deb && \
44+
apt-get update -y && \
45+
apt-get install -y erlang elixir
46+
47+
CMD ["/bin/bash"]
48+
```
49+
The example here has been borrowed from Distillery's [excellent guide](https://hexdocs.pm/distillery/guides/building_in_docker.html).
50+
51+
#### Build Docker Image
52+
53+
A one-time build command is needed to set up your Docker image:
54+
55+
```sh
56+
$ docker build -f Dockerfile.build -t elixir-ubuntu:latest .
57+
```
58+
59+
#### Use Docker with Bootleg
60+
61+
To tell Bootleg to use Docker, set the `#!elixir :build_type` and specify the image name in the `#!elixir :build_image` option:
62+
63+
!!! example "config/deploy.exs"
64+
```elixir
65+
use Bootleg.DSL
66+
67+
config(:build_type, :docker)
68+
config(:build_image, "elixir-ubuntu:latest")
69+
```
70+
71+
!!! info
72+
If your project has local dependencies, they will not be automatically available from within the Docker image. To satisfy these dependencies you'll need to specify some other options. See [docker options](/reference/docker.md) for more information.
73+
74+
### Remote Build Server
75+
76+
In order to build your project remotely, Bootleg requires that your build server be set up to compile Elixir code. Make sure you have already installed Elixir and Erlang on any build server you define.
77+
78+
To build your app on a remote build server, first define a `#!elixir :build` role:
79+
80+
!!! example "config/deploy.exs"
81+
```elixir
82+
use Bootleg.DSL
83+
84+
role :build, "build.example.com", user: "develop", workspace: "/some/build/workspace"
85+
```
86+
87+
When defining a role, host options such as public key can also be supplied. See [roles and host options](roles.md) for more information.
88+
89+
## Build your app
90+
91+
To initiate the Build step, run the provided Mix task:
92+
93+
```sh
94+
$ mix bootleg.build
95+
```
96+
97+
!!! info
98+
If your application doesn't build at this point, the errors should point you towards the problem. But don't worry too much about it for right now. We'll cover additional configuration in the following pages.
99+

docs/config/environments.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Environments
2+
3+
Bootleg has its own concept of environments, which is analogous to but different from `MIX_ENV`. Bootleg environments can be used if you have multiple clusters that you deploy your code to, such as a QA or staging cluster, in addition to
4+
your production cluster.
5+
6+
## Configuration structure
7+
8+
If you bootstrapped your config as detailed in the [Installing](/installing.md#set-up-bootleg) section the following files should already exist:
9+
10+
:::plain
11+
mix.exs
12+
├── config/
13+
├── deploy.exs # Main Bootleg config
14+
└── deploy/
15+
└── production.exs # Environment-specific detail
16+
17+
## Specifying a Bootleg environment
18+
19+
To invoke a [Bootleg Mix Task](/reference/mix.md) with a specific environment, simply pass the name of the environment as the first argument. That environment's config file will be loaded immediately after `config/deploy.exs`.
20+
21+
For example, say you have both a `production` and a `staging` cluster. Your configuration might look something like this:
22+
23+
:::plain
24+
mix.exs
25+
├── config/
26+
├── deploy.exs
27+
└── deploy/
28+
├── staging.exs
29+
└── production.exs
30+
31+
!!! example "Using the Staging Environment"
32+
```sh
33+
$ mix bootleg.update staging
34+
Starting remote build for staging environment
35+
```
36+
37+
!!! example "Using the Production Environment"
38+
```sh
39+
$ mix bootleg.update production
40+
Starting remote build for production environment
41+
```
42+
43+
The default environment is `production`, though this can be changed in your configuration.
44+
45+
!!! example "Using the default Environment"
46+
```sh
47+
$ mix bootleg.update
48+
Starting remote build for production environment
49+
```
50+
51+

docs/config/roles.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
# Roles
3+
4+
Actions in Bootleg are paired with roles, which are simply a collection of hosts that are responsible for the same function, for example building a release, archiving a release, or executing commands against a running application.
5+
6+
Hosts can be grouped into one or more roles. Roles can be declared repeatedly to provide options to different sets of hosts.
7+
8+
9+
## Roles provided by Bootleg
10+
11+
| Role | Description |
12+
|:---|:---|
13+
| `#!elixir :build` | Takes only one host. If a list is given, only the first host is used. |
14+
| `#!elixir :app` | Takes a list of hosts, or a string with one host. |
15+
16+
## Defining your own roles
17+
18+
By defining roles, you are defining responsibility groups to cross cut your host infrastructure. The `build` and
19+
`app` roles have inherent meaning to the default behavior of Bootleg, but you may also define more that you can later filter on when running commands inside a Bootleg hook.
20+
21+
Certain functionality or extensions may require additional roles, for example if your
22+
release needs to run Ecto migrations, you could assign a `#!elixir primary: true`
23+
option to one host and then filter on it.
24+
25+
### Syntax
26+
27+
The `role` macro requires both a name, specified as an atom, and a host or list of hosts. Any options you want to apply to those hosts can also be supplied.
28+
29+
### Examples
30+
31+
!!! example "Setting a different SSH option on a single host"
32+
```elixir
33+
role :app, ["host1", "host2"], user: "deploy", identity: "/home/deploy/.ssh/deploy_key.priv"
34+
role :app, "host2", port: 2222
35+
```
36+
Two hosts are declared for the `app` role. Both will use a username of `deploy` and the same public key identity file. Only **host2** will use the non-standard port of *2222*.
37+
38+
!!! example "Setting environment variables for the remote commands"
39+
```elixir
40+
role :app, ["host1", "host2"], env: %{FOO: "bar", BIZ: "baz"}
41+
```
42+
Two hosts are declared for the `app` role, both using environment variables set for any commands run remotely, `FOO=bar` and `BIZ=baz`.
43+
44+
!!! example "Setting your own host options"
45+
```elixir
46+
role :db, ["db.example.com", "db2.example.com"], user: "datadog"
47+
role :db, "db.example.com", primary: true
48+
```
49+
Two hosts are declared for the `db` role. Only `db.example.com` will receive an additional host-specific option for being the primary. Host options can be arbitrarily named and targeted by tasks.
50+
51+
!!! example "Using an internal role option to change behavior"
52+
Some host options are defined in Bootleg and have special meaning. `release_workspace` can be used when a single remote server is used to both build and run the application.
53+
```elixir
54+
role :build, "example.com", workspace: "/home/deployer/builds", release_workspace: "/home/deployer"
55+
role :app, "example.com", release_workspace: "/home/deployer"
56+
```
57+
By specifying a `release_workspace` on the `:build` role, a release is placed in `/home/deployer` after it is built. By specifying a `release_workspace` on the `:app` role, that same release is copied from the `/home/deployer` directory to the app workspace.
58+
59+
### Additional behaviors
60+
61+
There is another built-in role `:all` which includes all hosts assigned to any role. `:all` is only available via `remote/2`.

0 commit comments

Comments
 (0)