Skip to content

Commit 786fc12

Browse files
authored
Merge pull request #64 from paynejacob/issue-46
move package tutorial out of readme.
2 parents ae7bdc0 + 1bdf6e7 commit 786fc12

File tree

10 files changed

+431
-150
lines changed

10 files changed

+431
-150
lines changed

README.md

Lines changed: 4 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
# Corral
2-
Corral is a CLI tool for creating and packaging reproducible development environments. Corral allows developers to manage multiple environments, called corrals, and provision them consistantly using shared packages.
2+
Corral is a CLI tool for creating and packaging reproducible development environments. Corral allows developers to manage multiple environments, called corrals, and provision them consistently using shared packages.
33

4-
# Available Packages
5-
- `ghcr.io/rancherlabs/corral/k3s:latest`: Create a single node k3s cluster in Digitalocean.
6-
- `ghcr.io/rancherlabs/corral/k3s-ha:latest`: Create a highly available k3s cluster in Digitalocean.
7-
- `ghcr.io/rancherlabs/corral/rke2:latest`: Create a single node rke2 cluster in Digitalocean.
8-
- `ghcr.io/rancherlabs/corral/rke2-ha:latest`: Create a highly available rke2 cluster in Digitalocean.
9-
- `ghcr.io/rancherlabs/corral/rancher:latest`: Create a single node rancher in Digitalocean.
10-
- `ghcr.io/rancherlabs/corral/rancher-ha:latest`: Create a HA rancher in Digitalocean.
11-
12-
This repo contains a few packages to get started! These packages share some common variables between them.
13-
14-
`digitalocean_token`: Used to provision Digitalocean resources.
15-
`digitalocean_domain`: Used to generate dns records.
16-
17-
`aws_access_key` `aws_access_secret` are used to provision AWS resources.
18-
19-
# Usage
20-
21-
To get started with corral lets create and connect to a k3s cluster in Digitalocean.
4+
# Installation
5+
To install corral download the latest binary from the [releases](https://github.com/rancherlabs/corral/releases).
226

237
## First Time Setup
248

@@ -71,134 +55,4 @@ A corral is a collection of resources in a remote environment. Think of it as a
7155
A corral package is a description of an environment. A package consists of one terraform module and filesystem overlay. The terraform module is used to provision cloud resources. Once the resources are created corral will upload the files in the overlay folder to any nodes generated by terraform and call the commands defined in the manifest.
7256

7357
# How do I create a package?
74-
Packages consist of 3 components, a terraform module, overlay, and a manifest. The terrform module can define node pools via an output. Node pools are a collection of hosts for corral to run commands on. Overlay files are files copied onto the nodes in the node pools. For linux hosts they are copied to `/`. The manifest describes the package and what commands should be run on the nodes to provision the corral. Commands are executed sequentially however they will be run concurrently on all nodes within the specified node pools. Packages should describe a specific environment and not offer too much configuration. A good package produces consistent environments and requires little to no input.
75-
76-
To get started create the package's folder structure.
77-
78-
```
79-
mypkg/
80-
terraform/
81-
module/
82-
main.tf
83-
corral.tf
84-
overlay/
85-
/opt
86-
/corral
87-
hello-world.sh
88-
manifest.yaml
89-
```
90-
91-
We can define values a user can set or read by defining values in the manifest. In this manifest we define a variable for our Digitalocean token. Variables are json schemas so we can define some validation to help the user. Variables can also be marked as sensitive, this prevents corral from returning them when the `vars` command is called. Manifests may also define variables with `readOnly`, this indicates that the package will set the value for this variable and the user should not attempt to change it.
92-
93-
```yaml
94-
name: mypkg
95-
variables:
96-
digitalocean_token:
97-
sensitive: true
98-
type: string
99-
optional: false
100-
description: "A Digitalocean API token with write permission. https://docs.digitalocean.com/reference/api/create-personal-access-token/"
101-
```
102-
103-
In our terraform module we start with `corral.tf`. This file can be named anything you like but there are a few special
104-
terraform variables and outputs for interacting with corral. All these objects are completely optional.
105-
106-
```terraform
107-
variable "corral_name" {} # The name of this corral.
108-
variable "corral_user_id" {} # A string to identify who created theses resources.
109-
variable "corral_user_public_key" {} # A public key the user has access to that can be used to grant access to generated resources.
110-
variable "corral_public_key" {} # The public key corral uses to run scripts. Required if node pools are defined.
111-
112-
output "corral_node_pools" { # A map of node pool names to nodes. Nodes must define name, user, and address. Optionally a bastion_address can be defined to route connections through.
113-
value = {
114-
pool1 = [for droplet in [digitalocean_droplet.hello_world] : {
115-
name = droplet.name
116-
user = "root"
117-
address = droplet.ipv4_address # Address are in the format [host]:[port], if no port is defined 22 will be used.
118-
}]
119-
}
120-
}
121-
```
122-
123-
Now let's define the node we referenced in our node pools in `mypkg/terraform/module/main.tf`.
124-
125-
```terraform
126-
terraform {
127-
required_version = ">= 0.13"
128-
required_providers {
129-
digitalocean = {
130-
source = "digitalocean/digitalocean"
131-
version = "~> 2.0"
132-
}
133-
}
134-
}
135-
136-
variable "digitalocean_token" {}
137-
138-
provider "digitalocean" {
139-
token = var.digitalocean_token
140-
}
141-
142-
resource "digitalocean_ssh_key" "corral_key" {
143-
name = "corral-${var.corral_user_id}-${var.corral_name}"
144-
public_key = var.corral_public_key
145-
}
146-
147-
resource "digitalocean_droplet" "hello_world" {
148-
name = "${var.corral_user_id}-${corral_name}"
149-
image = "ubuntu-20-04-x64"
150-
region = "sfo3"
151-
size = "s-1vcpu-2gb"
152-
tags = [var.corral_user_id, var.corral_name]
153-
ssh_keys = [digitalocean_ssh_key.corral_key.id]
154-
}
155-
```
156-
157-
Now let's add a script called `mypkg/overlay/opt/corral/hello-world.sh` to install our user public key and get the node's hostname. To do this we can read the user public key from the environment. All corral variables are available as `CORRAL_<variable name>`. If you want to set additional variables for the next script or future reference you can use the `corral_set` command by writing to standard out.
158-
159-
```shell
160-
#!/bin/bash
161-
162-
echo "$CORRAL_corral_user_public_key" >> /$(whoami)/.ssh/authorized_keys
163-
164-
echo "corral_set hostname=$(hostname)"
165-
```
166-
167-
To tell corral to use our script we can add a command to the manifest.
168-
169-
```yaml
170-
name: mypkg
171-
variables:
172-
digitalocean_token:
173-
sensitive: true
174-
type: string
175-
optional: false
176-
description: "A Digitalocean API token with write permission. https://docs.digitalocean.com/reference/api/create-personal-access-token/"
177-
commands:
178-
- command: /opt/corral/hello-world.sh
179-
node_pools:
180-
- pool1
181-
```
182-
183-
We can check our work with the `validate` command.
184-
185-
```yaml
186-
corral pacakge validate ./mypkg
187-
```
188-
189-
Finally, we can use our package by calling create.
190-
191-
```shell
192-
corral create test ./mypkg
193-
```
194-
195-
If you want to distribute your package you can push it to any OCI compatible registry.
196-
197-
```shell
198-
corral package login ghcr.io
199-
corral package publish ./mypkg ghcr.io/myghaccount/mypkg:latest
200-
```
201-
202-
203-
# Installation
204-
To install corral download the latest binary from the [releases](https://github.com/rancherlabs/corral/releases).
58+
[See the tutorial here.](docs/packages/tutorial.md)

0 commit comments

Comments
 (0)