Skip to content

Commit 2905d9d

Browse files
committed
WIP: infra/setup
1 parent 7331e27 commit 2905d9d

File tree

110 files changed

+1061064
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1061064
-120
lines changed

.github/workflows/test-actions.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
test-infra-example:
9-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-22.04
1010
steps:
1111
- uses: actions/checkout@v3
1212
- uses: ./infra/example
@@ -19,3 +19,15 @@ jobs:
1919
- run: echo "Failure" && exit 1
2020
shell: bash
2121
if: steps.custom-action.outputs.out != 'example-output'
22+
23+
test-infra-setup:
24+
runs-on: ubuntu-22.04
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: ./infra/setup
28+
id: infra-setup
29+
with:
30+
cloud: openstack
31+
stack-name: test
32+
- shell: bash
33+
run: ls ${{ steps.infra-setup.outputs.workdir }}

infra/example/dist/pulumi/index.d.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/example/dist/pulumi/lib/index.d.ts

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/example/dist/src/entrypoints/setup.d.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"format": "prettier --write '**/*.ts'",
99
"format-check": "prettier --check '**/*.ts'",
1010
"lint": "eslint src/**/*.ts",
11-
"package": "npm run package:example",
11+
"package": "npm run package:example && npm run package:setup",
12+
"package:setup": "ncc build src/entrypoints/setup.ts --source-map --license licenses.txt --out setup/dist",
1213
"package:example": "ncc build src/entrypoints/example.ts --source-map --license licenses.txt --out example/dist",
1314
"test": "jest --passWithNoTests",
1415
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
@@ -34,6 +35,11 @@
3435
"typescript": "^4.9.3"
3536
},
3637
"dependencies": {
37-
"@actions/core": "^1.10.0"
38+
"@actions/core": "^1.10.0",
39+
"@actions/exec": "^1.1.1",
40+
"@actions/io": "^1.1.2",
41+
"@actions/tool-cache": "^2.0.1",
42+
"@pulumi/pulumi": "^3.48.0",
43+
"@pulumi/random": "^4.8.2"
3844
}
3945
}

infra/pulumi/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Pulumi Projects for Scality
2+
3+
Configuration from code for spawning cloud infrastructure intended for deploying various
4+
flavours of Scality products.
5+
6+
## Goals
7+
8+
**Modularity**: Split infrastructure into logical composable units (e.g. "a network with
9+
subnets and a bastion", "a node with disks", ...)
10+
11+
**Multi-cloud**: provide a single interface for "infrastructure" and handle the backend
12+
selection at runtime
13+
14+
## Organization
15+
16+
Pulumi has the concept of [projects][pulumi-projects] and [stacks][pulumi-stacks].
17+
18+
[pulumi-projects]: https://www.pulumi.com/docs/intro/concepts/project/
19+
[pulumi-stacks]: https://www.pulumi.com/docs/intro/concepts/stack/
20+
21+
A project defines a configurable Pulumi program, and stacks are instances of this
22+
program with independent configurations.
23+
24+
Since they will likely require drastically different infrastructure layouts, we will
25+
separate Scality products (RING and ARTESCA) into distinct projects.
26+
27+
However, Pulumi also exposes a concept of [components][pulumi-components] which can
28+
be shared in a reusable library. We will use to provide basic building blocks and
29+
standard implementations for known cloud providers.

infra/pulumi/artesca/Pulumi.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: scality-infra-artesca
2+
description: Cloud infrastructure for deploying ARTESCA
3+
runtime: nodejs
4+
5+
config:
6+
cloud:
7+
type: string
8+
description: The cloud provider to use
9+
default: openstack
10+
nodes-count:
11+
type: integer
12+
description: The number of nodes to spawn (not counting bastion)
13+
default: 1

infra/pulumi/artesca/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Pulumi project for ARTESCA cloud infrastructure
2+
3+
To be documented: configuration options, managed resources, quickstart commands.

infra/pulumi/artesca/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Pulumi project for spawning cloud infrastructure to deploy ARTESCA.
3+
*
4+
* @packageDocumentation
5+
*/
6+
7+
import * as pulumi from "@pulumi/pulumi";
8+
import * as random from "@pulumi/random";
9+
10+
export async function main() {
11+
const config = new pulumi.Config();
12+
const cloud = config.require("cloud");
13+
const nodesCount = config.requireNumber("nodes-count");
14+
const stack = pulumi.getStack();
15+
const project = pulumi.getProject();
16+
17+
const randomID = new random.RandomId("random-stack-id", {
18+
byteLength: 10, // 10 bytes to get 5 characters in hex
19+
keepers: { stackName: stack },
20+
});
21+
22+
const prefix = pulumi.interpolate`${project}-${randomID.hex}`;
23+
console.log(
24+
`This stack (${stack}, from project ${project}) will create ${nodesCount} nodes ` +
25+
`with the "${cloud}" provider.`
26+
);
27+
28+
// attempt getting outputs, can't export from a function
29+
return { prefix };
30+
}

infra/pulumi/index.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Entrypoints for provisioning cloud infrastructure with Pulumi Automation API.
3+
*
4+
* These entrypoints replicate some Pulumi CLI commands, and add state management
5+
* helpers for use with Scality Artifacts.
6+
*
7+
* @packageDocumentation
8+
*/
9+
import * as os from "node:os";
10+
import * as path from "node:path";
11+
import * as fs from "node:fs/promises";
12+
13+
import { LocalWorkspace } from "@pulumi/pulumi/automation";
14+
15+
import { main as artescaProgram } from "./artesca";
16+
import { main as ringProgram } from "./ring";
17+
18+
const programs = { artesca: artescaProgram, ring: ringProgram };
19+
export type Product = keyof typeof programs;
20+
21+
export async function init(
22+
product: Product,
23+
stackName: string,
24+
sourceDir?: string,
25+
workDir?: string
26+
) {
27+
// Create (or validate) the workDir
28+
if (workDir === undefined)
29+
workDir = await fs.mkdtemp(path.join(os.tmpdir(), "scality-pulumi-"));
30+
await fs.mkdir(workDir, { recursive: true });
31+
32+
// Copy project (and optional stack) settings from known paths
33+
if (sourceDir === undefined) sourceDir = __dirname;
34+
await fs.cp(path.join(sourceDir, product), workDir, { recursive: true });
35+
36+
// (maybe, add configuration hooks here as well, but can be done with the resulting
37+
// workspace, so no rush)
38+
39+
// Return a local workspace
40+
return await LocalWorkspace.createOrSelectStack(
41+
{ stackName, projectName: `scality-infra-${product}`, program: programs[product] },
42+
{ workDir }
43+
);
44+
}

0 commit comments

Comments
 (0)