Skip to content

Commit

Permalink
Add support for specifing multiple build paths (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSimons authored Aug 26, 2024
1 parent e81bf4e commit 94c05cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,38 @@ The following steps are a guideline for modifying/creating Dockerfiles.
Team code owners must be assigned to each Dockerfile for maintenance and issue assignment purposes.

2. Validate the changes locally by running [build.ps1](./build.ps1).
It is strongly suggested to specify the `-DockerfilePath` option to avoid the overhead of building all the images.
It is strongly suggested to specify the `-Paths` option to avoid the overhead of building all the images.

For example, if editing the [Fedora 40 Dockerfile](./src/fedora/40/amd64/Dockerfile), then run the following command to build just that Dockerfile.

```powershell
.\build.ps1 -DockerfilePath "*fedora/40/amd64*"
.\build.ps1 -Paths "*fedora/40/amd64*"
```

It is a good practice to use `--dry-run` option on the first attempt to verify what commands will get run.

```powershell
.\build.ps1 -DockerfilePath "*fedora/40/amd64*" -ImageBuilderCustomArgs "--dry-run"
.\build.ps1 -Paths "*fedora/40/amd64*" -OptionalImageBuilderArgs "--dry-run"
```

Partial paths and wildcards in the `-DockerfilePath` option are also supported. The following example will build all the Fedora Dockerfiles.
Partial paths and wildcards in the `-Paths` option are also supported. The following example will build all the Fedora Dockerfiles.

```powershell
.\build.ps1 -DockerfilePath "*fedora/*"
.\build.ps1 -Paths "*fedora/*"
```

To build a dependency graph when there are [dependent images](#image-dependency), multiple paths can be specified.

```powershell
.\build.ps1 -Paths "*alpine/3.20/amd64*","*alpine/3.20/withnode/amd64*"
```

Alternatively, wildcards can by utilized to specify everything under a shared directory.
Using wildcards can sometimes cause extra images to be built outside of the dependency graph which may be undersirable.
In this case, it is recommended to utilize the multiple `paths` approach.

```powershell
.\build.ps1 -Paths "*alpine/3.20*"
```

3. Prepare a PR
Expand Down
9 changes: 6 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[cmdletbinding()]
param(
[string]$DockerfilePath = "*",
[string]$ImageBuilderCustomArgs
# Paths to the Dockerfiles to build
[string[]]$Paths,

# Additional args to pass to ImageBuilder
[string]$OptionalImageBuilderArgs
)

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
pushd $PSScriptRoot
try {
./eng/common/Invoke-ImageBuilder.ps1 "build --path '$DockerfilePath' $ImageBuilderCustomArgs"
./eng/common/build.ps1 -Paths $Paths -OptionalImageBuilderArgs $OptionalImageBuilderArgs
}
finally {
popd
Expand Down

0 comments on commit 94c05cc

Please sign in to comment.