Skip to content

Commit 8738d5d

Browse files
authored
Merge pull request #9 from brainhivenl/refactor/prepare-config
Prepare configuration for deployment
2 parents e0f4012 + a0f597a commit 8738d5d

7 files changed

Lines changed: 44 additions & 59 deletions

File tree

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,28 @@ cargo build --release
125125
Create a `steiger.yml` file:
126126

127127
```yaml
128-
services:
128+
build:
129129
frontend:
130-
build:
131-
type: docker
132-
context: ./frontend
133-
dockerfile: Dockerfile.prod # optional, defaults to Dockerfile
134-
buildArgs:
135-
ENV: ${env} # variable substitution is supported
130+
type: docker
131+
context: ./frontend
132+
dockerfile: Dockerfile.prod # optional, defaults to Dockerfile
133+
buildArgs:
134+
ENV: ${env} # variable substitution is supported
136135

137136
backend:
138-
build:
139-
type: bazel
140-
targets:
141-
app: //cmd/server:image
142-
migrations: //cmd/migrations:image
137+
type: bazel
138+
targets:
139+
app: //cmd/server:image
140+
migrations: //cmd/migrations:image
143141

144142
go-service:
145-
build:
146-
type: ko
147-
importPath: ./cmd/service
143+
type: ko
144+
importPath: ./cmd/service
148145

149146
flake:
150-
build:
151-
type: nix
152-
systems: ["x86_64-linux"]
153-
packages:
154-
api: default # attribute path to package e.g. `outputs.packages.<system>.default`
147+
type: nix
148+
packages:
149+
api: default # attribute path to package e.g. `outputs.packages.<system>.default`
155150

156151
profiles:
157152
prod:
@@ -177,15 +172,14 @@ oci_image(
177172
Platform-specific builds:
178173

179174
```yaml
180-
services:
175+
build:
181176
multi-arch:
182-
build:
183-
type: bazel
184-
platforms:
185-
linux/amd64: //platforms:linux_amd64
186-
linux/arm64: //platforms:linux_arm64
187-
targets:
188-
app: //cmd/app:image
177+
type: bazel
178+
platforms:
179+
linux/amd64: //platforms:linux_amd64
180+
linux/arm64: //platforms:linux_arm64
181+
targets:
182+
app: //cmd/app:image
189183
```
190184
191185
## Usage

example/steiger.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
services:
1+
build:
22
rust:
3-
build:
4-
type: docker
5-
context: .
3+
type: docker
4+
context: .

src/builder/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use futures::TryFutureExt;
2+
use miette::Diagnostic;
3+
use prodash::{messages::MessageLevel, tree::Item};
4+
use tokio::{task::JoinSet, time::Instant};
5+
16
use crate::{
27
builder::{bazel::BazelBuilder, docker::DockerBuilder, ko::KoBuilder, nix::NixBuilder},
38
config::{Build, Config},
49
image::Image,
510
};
611

7-
use futures::TryFutureExt;
8-
use miette::Diagnostic;
9-
use prodash::{messages::MessageLevel, tree::Item};
10-
use tokio::{task::JoinSet, time::Instant};
11-
1212
mod bazel;
1313
mod docker;
1414
mod ko;
@@ -130,14 +130,14 @@ impl MetaBuild {
130130
let config = Arc::clone(&self.config);
131131
let mut set = JoinSet::default();
132132

133-
pb.init(Some(config.services.len()), None);
133+
pb.init(Some(config.build.len()), None);
134134
pb.message(MessageLevel::Info, format!("detected platform: {platform}"));
135135

136-
for (name, service) in config.services.iter() {
136+
for (name, build) in config.build.iter() {
137137
let progress = pb.add_child(name);
138138
let ctx = Context::new(name.clone(), platform.to_string(), ());
139139

140-
match &service.build {
140+
match &build {
141141
Build::Ko(ko) => {
142142
set.spawn(
143143
run_builder(&mut self.ko, progress, ctx.with(ko.clone()))?
@@ -175,7 +175,7 @@ impl MetaBuild {
175175
let elapsed = instant.elapsed();
176176

177177
pb.message(
178-
MessageLevel::Info,
178+
MessageLevel::Success,
179179
format!("build completed in {elapsed:?}"),
180180
);
181181

src/cmd/build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ use crate::{
1414
tag::{self, TagError},
1515
};
1616

17-
mod skaffold {
18-
use serde::Serialize;
17+
pub mod output {
18+
use serde::{Deserialize, Serialize};
1919

20-
#[derive(Serialize)]
20+
#[derive(Serialize, Deserialize)]
2121
#[serde(rename_all = "camelCase")]
2222
pub struct Build {
2323
pub image_name: String,
2424
pub tag: String,
2525
}
2626

27-
#[derive(Serialize)]
27+
#[derive(Serialize, Deserialize)]
2828
#[serde(rename_all = "camelCase")]
2929
pub struct Output {
3030
pub builds: Vec<Build>,
@@ -131,10 +131,10 @@ pub async fn run(
131131
}
132132

133133
if let Some(path) = output_file {
134-
let output = skaffold::Output {
134+
let output = output::Output {
135135
builds: artifacts
136136
.into_iter()
137-
.map(|(image_name, tag)| skaffold::Build { image_name, tag })
137+
.map(|(image_name, tag)| output::Build { image_name, tag })
138138
.collect(),
139139
};
140140

src/config.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde_yml::{Mapping, Value};
1111
#[derive(Debug, Deserialize)]
1212
#[serde(rename_all = "camelCase")]
1313
pub struct Config {
14-
pub services: HashMap<String, Service>,
14+
pub build: HashMap<String, Build>,
1515
}
1616

1717
#[derive(Clone, Debug, Deserialize)]
@@ -61,12 +61,6 @@ pub struct Profile {
6161
pub vars: HashMap<String, String>,
6262
}
6363

64-
#[derive(Debug, Deserialize)]
65-
#[serde(rename_all = "camelCase")]
66-
pub struct Service {
67-
pub build: Build,
68-
}
69-
7064
#[derive(Debug, Diagnostic, thiserror::Error)]
7165
pub enum ConfigError {
7266
#[error("I/O error")]

src/exec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ where
5656
P: Progress + 'static,
5757
{
5858
let progress = Arc::new(progress);
59-
6059
let mut child = spawn(cmd).await?;
6160

6261
progress::proxy_stdio(child.stdout, Arc::clone(&progress));

steiger.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
services:
1+
build:
22
steiger:
3-
build:
4-
type: docker
5-
context: .
3+
type: docker
4+
context: .

0 commit comments

Comments
 (0)