Skip to content

Commit 3b2a461

Browse files
committed
wip: adds README and earthly version support
1 parent 41d4d42 commit 3b2a461

File tree

6 files changed

+144
-22
lines changed

6 files changed

+144
-22
lines changed

blueprint.cue

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ ci: {
99
registry: "332405224602.dkr.ecr.eu-central-1.amazonaws.com"
1010
role: "arn:aws:iam::332405224602:role/ci"
1111
}
12-
docker: {
13-
credentials: {
14-
provider: "aws"
15-
path: "global/ci/docker"
16-
}
12+
13+
docker: credentials: {
14+
provider: "aws"
15+
path: "global/ci/docker"
1716
}
17+
1818
earthly: {
1919
credentials: {
2020
provider: "aws"
2121
path: "global/ci/earthly"
2222
}
2323
org: "Catalyst"
2424
satellite: "ci"
25+
version: "0.8.15"
2526
}
26-
github: {
27-
registry: "ghcr.io"
28-
}
27+
28+
github: registry: "ghcr.io"
2929
}
3030
}

blueprint/schema/_embed/schema.cue

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ package schema
8181
// Satellite contains the satellite to use for caching.
8282
// +optional
8383
satellite?: null | string @go(Satellite,*string)
84+
85+
// The version of Earthly to use in CI.
86+
// +optional
87+
version?: null | string @go(Version,*string)
8488
}
8589

8690
// ProviderGithub contains the configuration for the Github provider.

blueprint/schema/schema.go

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type Providers struct {
5353
// +optional
5454
Earthly ProviderEarthly `json:"earthly"`
5555

56+
// Github contains the configuration for the Github provider.
57+
// +optional
5658
Github ProviderGithub `json:"github"`
5759
}
5860

@@ -88,6 +90,10 @@ type ProviderEarthly struct {
8890
// Satellite contains the satellite to use for caching.
8991
// +optional
9092
Satellite *string `json:"satellite"`
93+
94+
// The version of Earthly to use in CI.
95+
// +optional
96+
Version *string `json:"version"`
9197
}
9298

9399
// ProviderGithub contains the configuration for the Github provider.

blueprint/schema/schema_go_gen.cue

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ package schema
8181
// Satellite contains the satellite to use for caching.
8282
// +optional
8383
satellite?: null | string @go(Satellite,*string)
84+
85+
// The version of Earthly to use in CI.
86+
// +optional
87+
version?: null | string @go(Version,*string)
8488
}
8589

8690
// ProviderGithub contains the configuration for the Github provider.

forge/actions/setup/README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Setup Action
2+
3+
The setup action can be used to install the Forge CLI and configure various providers by reading from the root blueprint file.
4+
The blueprint schema provides options for configuring a number of third-party providers like AWS, Earthly, etc.
5+
The setup action will automatically interrogate these options and use them to determine which providers to set up.
6+
The action only configures providers that have been specified in the blueprint file.
7+
8+
## Usage
9+
10+
Add a `blueprint.cue` to the root of your repository and add configuration for individual providers.
11+
Here is an example:
12+
13+
```cue
14+
version: "1.0"
15+
ci: {
16+
providers: {
17+
aws: {
18+
region: "eu-central-1"
19+
registry: "123456.dkr.ecr.eu-central-1.amazonaws.com"
20+
role: "arn:aws:iam::123456:role/ci"
21+
}
22+
earthly: {
23+
credentials: {
24+
provider: "aws"
25+
path: "path/to/secret"
26+
}
27+
org: "myorg"
28+
satellite: "sat"
29+
}
30+
}
31+
}
32+
```
33+
34+
The above blueprint configures both the AWS and Earthly Cloud providers.
35+
Once in place, simply invoke the setup action in a step:
36+
37+
```yaml
38+
name: Run Setup
39+
on:
40+
push:
41+
42+
permissions:
43+
contents: read
44+
id-token: write
45+
46+
jobs:
47+
setup:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Setup
51+
uses: input-output-hk/catalyst-forge/forge/actions/setup@master
52+
```
53+
54+
The action will then perform the following:
55+
56+
1. Install the latest version of the Forge CLI
57+
2. Authenticate to AWS via OIDC
58+
3. Authenticate to Earthly Cloud using the credentials in the AWS Secrets Manager secret stored at `path/to/secret`
59+
4. Set the default Earthly Cloud organization to `myorg`
60+
61+
### Configuring Providers
62+
63+
All providers expect credentials to be passed via a secret.
64+
The format for the secret is the same as used elsewhere in Catalyst Forge.
65+
Notably, the setup action assumes credentials are stored in a common way inside secrets.
66+
The secret must be a JSON string with specific keys mapping to specific credentials.
67+
68+
The below list documents the expected format for each provider:
69+
70+
1. Docker
71+
- `username`: The username to login with
72+
- `password`: The password to login with
73+
1. Earthly
74+
- `token`: The Earthly Cloud token to login with
75+
76+
If the secret uses a different format, the `maps` field of the secret can be used to map them correctly:
77+
78+
```cue
79+
version: "1.0"
80+
ci: {
81+
providers: {
82+
docker: {
83+
credentials: {
84+
provider: "aws"
85+
path: "path/to/secret"
86+
maps: {
87+
username: "my_username"
88+
password: "my_password"
89+
}
90+
}
91+
}
92+
}
93+
}
94+
```
95+
96+
In the above example, the fields `my_username` and `my_password` are remapped to the expected `username` and `password` fields.
97+
98+
### Local Testing
99+
100+
By default, the setup action installs release versions of the Forge CLI.
101+
The `forge_version` input can be set to `local` in order to build a local version of the CLI.
102+
This is useful for testing changes without needing to perform a release.
103+
104+
Note that this _only_ works when run within the Catalyst Forge repository.
105+
106+
## Inputs
107+
108+
| Name | Description | Required | Default |
109+
| ------------- | ---------------------------------------- | -------- | ----------------------- |
110+
| forge_version | The version of the forge CLI to install | No | `"latest"` |
111+
| github_token | The GitHub token used for authentication | No | `"${{ github.token }}"` |

forge/actions/setup/action.yml

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: Setup CI
22
description: Sets up the CI with the configured providers
33
inputs:
4-
earthly_version:
5-
description: The version of Earthly to install
6-
default: latest
74
forge_version:
85
description: The version of the forge CLI to install (use 'local' for testing)
96
default: latest
@@ -20,7 +17,7 @@ runs:
2017
uses: earthly/actions-setup@v1
2118
if: inputs.forge_version == 'local'
2219
with:
23-
version: ${{ inputs.earthly_version }}
20+
version: latest
2421
- name: Cache Forge CLI binary
2522
if: inputs.forge_version == 'local'
2623
id: cache-forge
@@ -118,11 +115,6 @@ runs:
118115
password: ${{ inputs.github_token }}
119116

120117
# Earthly Provider
121-
- name: Install Earthly
122-
uses: earthly/actions-setup@v1
123-
if: inputs.forge_version != 'local' # Prefer to install Earthly after logging into Docker Hub
124-
with:
125-
version: ${{ inputs.earthly_version }}
126118
- name: Get Earthly provider configuration
127119
id: earthly
128120
shell: bash
@@ -132,6 +124,9 @@ runs:
132124
EARTHLY=$(echo "$BP" | jq -r .ci.providers.earthly)
133125
if [[ "$EARTHLY" != "null" ]]; then
134126
ORG=$(echo "$BP" | jq -r .ci.providers.earthly.org)
127+
VERSION=$(echo "$BP" | jq -r .ci.providers.earthly.version)
128+
else
129+
VERSION="latest"
135130
fi
136131
137132
EARTHLY_CREDS=$(echo "$BP" | jq -r .ci.providers.earthly.credentials)
@@ -146,9 +141,15 @@ runs:
146141
fi
147142
148143
echo "org=$ORG" >> $GITHUB_OUTPUT
144+
echo "version=$VERSION" >> $GITHUB_OUTPUT
149145
150146
echo "::add-mask::$TOKEN"
151147
echo "token=$TOKEN" >> $GITHUB_OUTPUT
148+
- name: Install Earthly
149+
uses: earthly/actions-setup@v1
150+
if: inputs.forge_version != 'local' # Prefer to install Earthly after logging into Docker Hub
151+
with:
152+
version: ${{ steps.earthly.outputs.version }}
152153
- name: Login to Earthly Cloud
153154
if: steps.earthly.outputs.token != ''
154155
shell: bash
@@ -158,8 +159,4 @@ runs:
158159
if: steps.earthly.outputs.org != ''
159160
shell: bash
160161
run: |
161-
earthly org select "${{ steps.earthly.outputs.org }}"
162-
- name: Testing
163-
shell: bash
164-
run: |
165-
forge run ./forge/cli+test
162+
earthly org select "${{ steps.earthly.outputs.org }}"

0 commit comments

Comments
 (0)