Skip to content

Commit f98a6e6

Browse files
committed
remove provide-image, replace with arg
1 parent e22075d commit f98a6e6

File tree

6 files changed

+25
-50
lines changed

6 files changed

+25
-50
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ RUN dpkg --add-architecture arm64 && \
134134
apt-get install --assume-yes libfoo:arm64
135135
```
136136

137-
If you want cross to provide the `FROM` instruction, use `target.{{TARGET}}.dockerfile.provide-base`.
137+
If you want cross to provide the `FROM` instruction, you can do the following
138+
139+
``` Dockerfile
140+
ARG CROSS_BASE_IMAGE
141+
FROM $CROSS_BASE_IMAGE
142+
143+
RUN ...
144+
```
138145

139146
#### Pre-build hook
140147

docs/cross_toml.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,4 @@ passthrough = ["IMPORTANT_ENV_VARIABLES"]
5252
file = "./Dockerfile"
5353
context = "."
5454
build-args = { ARG1 = "foo" }
55-
provide-base = false # tell cross to insert a `FROM` instruction
5655
```

src/config.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ impl Environment {
6464
self.get_target_var(target, "DOCKERFILE")
6565
}
6666

67-
fn dockerfile_provide_base(&self, target: &Target) -> Option<bool> {
68-
self.get_target_var(target, "DOCKERFILE_PROVIDE_BASE")
69-
.map(|s| bool_from_envvar(&s))
70-
}
71-
7267
fn dockerfile_context(&self, target: &Target) -> Option<String> {
7368
self.get_target_var(target, "DOCKERFILE_CONTEXT")
7469
}
@@ -248,14 +243,6 @@ impl Config {
248243
self.string_from_config(target, Environment::dockerfile, CrossToml::dockerfile)
249244
}
250245

251-
pub fn dockerfile_provide_base(&self, target: &Target) -> Option<bool> {
252-
self.bool_from_config(
253-
target,
254-
|s, t| (None, s.dockerfile_provide_base(t)),
255-
|s, t| (None, s.dockerfile_provide_base(t)),
256-
)
257-
}
258-
259246
pub fn dockerfile_context(&self, target: &Target) -> Result<Option<String>> {
260247
self.string_from_config(
261248
target,

src/cross_toml.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub struct CrossTargetConfig {
4545
#[serde(rename_all = "kebab-case")]
4646
pub struct CrossTargetDockerfileConfig {
4747
file: String,
48-
#[serde(default)]
49-
provide_base: bool,
5048
context: Option<String>,
5149
build_args: Option<HashMap<String, String>>,
5250
}
@@ -57,7 +55,6 @@ impl FromStr for CrossTargetDockerfileConfig {
5755
fn from_str(s: &str) -> Result<Self, Self::Err> {
5856
Ok(CrossTargetDockerfileConfig {
5957
file: s.to_string(),
60-
provide_base: false,
6158
context: None,
6259
build_args: None,
6360
})
@@ -104,16 +101,6 @@ impl CrossToml {
104101
self.get_string(target, |t| t.dockerfile.as_ref().map(|c| &c.file))
105102
}
106103

107-
/// Returns the `target.{}.dockerfile.provide_base` part of `Cross.toml`
108-
pub fn dockerfile_provide_base(&self, target: &Target) -> Option<bool> {
109-
self.get_bool(
110-
target,
111-
|_| None,
112-
|t| t.dockerfile.as_ref().map(|c| c.provide_base),
113-
)
114-
.1
115-
}
116-
117104
/// Returns the `target.{}.dockerfile.context` part of `Cross.toml`
118105
pub fn dockerfile_context(&self, target: &Target) -> Option<String> {
119106
self.get_string(target, |t| {

src/docker.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,15 @@ pub fn run(
360360
let context = config.dockerfile_context(target)?;
361361
let name = config.image(target)?;
362362

363-
let mut build = Dockerfile::File {
363+
let build = Dockerfile::File {
364364
path: &path,
365365
context: context.as_deref(),
366366
name: name.as_deref(),
367367
};
368368

369-
if config.dockerfile_provide_base(target).unwrap_or_default() {
370-
let mut content = format!("FROM {image}\n");
371-
content.push_str(&crate::file::read(&path)?);
372-
build = Dockerfile::Custom {
373-
content,
374-
from_file: true,
375-
};
376-
}
377-
378369
image = build
379370
.build(
371+
config,
380372
&engine,
381373
&host_root,
382374
config.dockerfile_build_args(target)?.unwrap_or_default(),
@@ -397,10 +389,10 @@ ARG CROSS_DEB_ARCH=
397389
ARG CROSS_CMD
398390
RUN eval "${{CROSS_CMD}}""#
399391
),
400-
from_file: false,
401392
};
402393
custom
403394
.build(
395+
config,
404396
&engine,
405397
&host_root,
406398
Some(("CROSS_CMD", pre_build.join("\n"))),
@@ -428,14 +420,14 @@ pub enum Dockerfile<'a> {
428420
},
429421
Custom {
430422
content: String,
431-
/// if `true`, the name of the file will be slightly different
432-
from_file: bool,
433423
},
434424
}
435425

436426
impl<'a> Dockerfile<'a> {
427+
#[allow(clippy::too_many_arguments)]
437428
pub fn build(
438429
&self,
430+
config: &Config,
439431
engine: &Path,
440432
host_root: &Path,
441433
build_args: impl IntoIterator<Item = (impl AsRef<str>, impl AsRef<str>)>,
@@ -454,20 +446,23 @@ impl<'a> Dockerfile<'a> {
454446
}
455447

456448
if let Some(arch) = target_triple.deb_arch() {
457-
docker_build.args(["--build-arg", &format!("CROSS_DEB_ARCH={}", arch)]);
449+
docker_build.args(["--build-arg", &format!("CROSS_DEB_ARCH={arch}")]);
450+
}
451+
452+
if let Ok(cross_base_image) = image(config, target_triple) {
453+
docker_build.args([
454+
"--build-arg",
455+
&format!("CROSS_BASE_IMAGE={cross_base_image}"),
456+
]);
458457
}
459458

460459
let path = match self {
461460
Dockerfile::File { path, .. } => PathBuf::from(path),
462-
Dockerfile::Custom { content, from_file } => {
461+
Dockerfile::Custom { content } => {
463462
let path = host_root
464463
.join("target")
465464
.join(target_triple.to_string())
466-
.join(format!(
467-
"Dockerfile.{}{}",
468-
target_triple,
469-
if !from_file { "-custom" } else { "" }
470-
));
465+
.join(format!("Dockerfile.{}", target_triple,));
471466
{
472467
let mut file = file::write_file(&path, true)?;
473468
file.write_all(content.as_bytes())?;

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ impl Target {
238238
}
239239

240240
/// Returns the architecture name according to `dpkg` naming convention
241-
///
241+
///
242242
/// # Notes
243-
///
243+
///
244244
/// Some of these make no sense to use in our standard images
245245
pub fn deb_arch(&self) -> Option<&'static str> {
246246
match self.triple() {

0 commit comments

Comments
 (0)