Skip to content

Commit

Permalink
bake: use DESTDIR variable to define build output dir
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Aug 4, 2022
1 parent b7a542c commit 4813cdb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
binary:
runs-on: ubuntu-20.04
env:
BINARY_OUTPUT: ./build
DESTDIR: ./build
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -53,24 +53,24 @@ jobs:
-
name: List artifacts
run: |
tree -nh ${{ env.BINARY_OUTPUT }}
tree -nh ${{ env.DESTDIR }}
-
name: Check artifacts
run: |
find ${{ env.BINARY_OUTPUT }} -type f -exec file -e ascii -- {} +
find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
-
name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binary-${{ matrix.linkmode }}
path: ${{ env.BINARY_OUTPUT }}
path: ${{ env.DESTDIR }}
if-no-files-found: error
retention-days: 7

cross:
runs-on: ubuntu-20.04
env:
ALL_OUTPUT: ./build
DESTDIR: ./build
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -115,17 +115,17 @@ jobs:
-
name: List artifacts
run: |
tree -nh ${{ env.ALL_OUTPUT }}
tree -nh ${{ env.DESTDIR }}
-
name: Check artifacts
run: |
find ${{ env.ALL_OUTPUT }} -type f -exec file -e ascii -- {} +
find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
-
name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: cross-${{ matrix.target }}-${{ env.PLATFORM_PAIR }}
path: ${{ env.ALL_OUTPUT }}
path: ${{ env.DESTDIR }}
if-no-files-found: error
retention-days: 7

Expand Down
21 changes: 11 additions & 10 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ variable "PACKAGER_NAME" {
default = ""
}

# Defines the output folder
variable "DESTDIR" {
default = ""
}
function "bindir" {
params = [defaultdir]
result = DESTDIR != "" ? DESTDIR : "./bundles/${defaultdir}"
}
target "_common" {
args = {
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1 # https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#built-in-build-args
Expand Down Expand Up @@ -90,14 +99,10 @@ group "default" {
# binaries targets build dockerd, docker-proxy and docker-init
#

variable "BINARY_OUTPUT" {
default = DOCKER_LINKMODE == "static" ? "./bundles/binary" : "./bundles/dynbinary"
}

target "binary" {
inherits = ["_common"]
target = "binary"
output = [BINARY_OUTPUT]
output = [bindir(DOCKER_LINKMODE == "static" ? "binary" : "dynbinary")]
}

target "binary-cross" {
Expand All @@ -120,14 +125,10 @@ target "binary-smoketest" {
# all targets build binaries and extra tools as well (containerd, runc, ...)
#

variable "ALL_OUTPUT" {
default = "./bundles/all"
}

target "all" {
inherits = ["_common"]
target = "all"
output = [ALL_OUTPUT]
output = [bindir("all")]
}

target "all-cross" {
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/ctn-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docker buildx bake

# build binaries for the current host platform
# output to ./bin
BINARY_OUTPUT=./bin docker buildx bake
DESTDIR=./bin docker buildx bake

# build dynamically linked binaries
# output to ./bundles/dynbinary by default
Expand All @@ -27,7 +27,7 @@ docker buildx bake all

# build all for the current host platform
# output to ./bin
ALL_OUTPUT=./bin docker buildx bake all
DESTDIR=./bin docker buildx bake all

# build all for all supported platforms
docker buildx bake all-cross
Expand Down

0 comments on commit 4813cdb

Please sign in to comment.