Skip to content

Commit

Permalink
Move build scripts and Dockerfile to a seperate folder
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schildt <[email protected]>
  • Loading branch information
SebastianSchildt committed May 6, 2024
1 parent f47b340 commit 66df0f4
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 66 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/kuksa_databroker-cli_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: databroker-cli-lint-${{ hashFiles('**/Cargo.lock') }}
- name: cargo fmt
Expand Down Expand Up @@ -84,32 +86,33 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: databroker-cli-release-${{ matrix.platform.name }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install build prerequisites
working-directory: ${{github.workspace}}/
run: |
which cross || cargo install cross
cargo install cargo-license cargo-cyclonedx
cargo install cross cargo-license cargo-cyclonedx
pip install "git+https://github.com/eclipse-kuksa/kuksa-common.git@6f3d7627760582d8ba83cc8a0f7449d00fffee84#subdirectory=sbom-tools"
- name: Build
working-directory: ${{github.workspace}}/
working-directory: ${{github.workspace}}/scripts
env:
KUKSA_DATABROKERCLI_SBOM: y
run: |
./build-databroker-cli.sh ${{ matrix.platform.name }}
- name: "Archiving artifacts"
shell: bash
working-directory: ${{github.workspace}}/dist/${{ matrix.platform.name }}
working-directory: ${{github.workspace}}/scripts/dist/${{ matrix.platform.name }}
run: |
tar -czf ../databroker-cli-${{ matrix.platform.name }}.tar.gz *
- name: "Uploading artifacts"
uses: actions/upload-artifact@v4
with:
name: databroker-cli-${{ matrix.platform.name }}
path: ${{github.workspace}}/dist/databroker-cli-${{ matrix.platform.name}}.tar.gz
path: ${{github.workspace}}/scripts/dist/databroker-cli-${{ matrix.platform.name}}.tar.gz
if-no-files-found: error

create-container:
Expand All @@ -129,10 +132,10 @@ jobs:

- name: Unpack binaries
run: |
mkdir -p dist/amd64 dist/arm64 dist/riscv64
tar xf artifacts/databroker-cli-arm64.tar.gz -C dist/arm64
tar xf artifacts/databroker-cli-amd64.tar.gz -C dist/amd64
tar xf artifacts/databroker-cli-riscv64.tar.gz -C dist/riscv64
mkdir -p scripts/dist/amd64 scripts/dist/arm64 scripts/dist/riscv64
tar xf artifacts/databroker-cli-arm64.tar.gz -C scripts/dist/arm64
tar xf artifacts/databroker-cli-amd64.tar.gz -C scripts/dist/amd64
tar xf artifacts/databroker-cli-riscv64.tar.gz -C scripts/dist/riscv64
- name: Set container metadata
id: meta
Expand Down Expand Up @@ -170,7 +173,7 @@ jobs:
linux/amd64
linux/arm64
linux/riscv64
file: ./Dockerfile-cli
file: ./scripts/Dockerfile-cli
context: .
push: true
tags: |
Expand All @@ -190,7 +193,7 @@ jobs:
linux/amd64
linux/arm64
linux/riscv64
file: ./Dockerfile-cli
file: ./scripts/Dockerfile-cli
context: .
push: true
tags: "ttl.sh/eclipse-kuksa/kuksa-databroker-cli-${{github.sha}}"
Expand Down
27 changes: 16 additions & 11 deletions .github/workflows/kuksa_databroker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: databroker-lint-${{ hashFiles('**/Cargo.lock') }}
- name: Show toolchain information
Expand Down Expand Up @@ -75,6 +77,8 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: databroker-coverage-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
Expand Down Expand Up @@ -109,16 +113,17 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: databroker-release-${{ matrix.platform.name }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install build prerequisites
working-directory: ${{github.workspace}}/
run: |
which cross || cargo install cross
cargo install cargo-license cargo-cyclonedx
cargo install cross cargo-license cargo-cyclonedx
pip install "git+https://github.com/eclipse-kuksa/kuksa-common.git@6f3d7627760582d8ba83cc8a0f7449d00fffee84#subdirectory=sbom-tools"
- name: Build
working-directory: ${{github.workspace}}/
working-directory: ${{github.workspace}}/scripts
env:
KUKSA_DATABROKER_FEATURES: databroker/viss,databroker/tls
KUKSA_DATABROKER_SBOM: y
Expand All @@ -127,15 +132,15 @@ jobs:
- name: "Archiving artifacts"
shell: bash
working-directory: ${{github.workspace}}/dist/${{ matrix.platform.name }}
working-directory: ${{github.workspace}}/scripts/dist/${{ matrix.platform.name }}
run: |
tar -czf ../databroker-${{ matrix.platform.name }}.tar.gz *
- name: "Uploading artifacts"
uses: actions/upload-artifact@v4
with:
name: databroker-${{ matrix.platform.name }}
path: ${{github.workspace}}/dist/databroker-${{ matrix.platform.name}}.tar.gz
path: ${{github.workspace}}/scripts/dist/databroker-${{ matrix.platform.name}}.tar.gz
if-no-files-found: error

check_ghcr_push:
Expand All @@ -160,10 +165,10 @@ jobs:

- name: Unpack binaries
run: |
mkdir -p dist/amd64 dist/arm64 dist/riscv64
tar xf artifacts/databroker-arm64.tar.gz -C dist/arm64
tar xf artifacts/databroker-amd64.tar.gz -C dist/amd64
tar xf artifacts/databroker-riscv64.tar.gz -C dist/riscv64
mkdir -p scripts/dist/amd64 scripts/dist/arm64 scripts/dist/riscv64
tar xf artifacts/databroker-arm64.tar.gz -C scripts/dist/arm64
tar xf artifacts/databroker-amd64.tar.gz -C scripts/dist/amd64
tar xf artifacts/databroker-riscv64.tar.gz -C scripts/dist/riscv64
- name: Set container metadata
id: meta
Expand Down Expand Up @@ -201,7 +206,7 @@ jobs:
linux/amd64
linux/arm64
linux/riscv64
file: ./Dockerfile
file: ./scripts/Dockerfile
context: .
push: true
tags: |
Expand All @@ -221,7 +226,7 @@ jobs:
linux/amd64
linux/arm64
linux/riscv64
file: ./Dockerfile
file: ./scripts/Dockerfile
context: .
push: true
tags: "ttl.sh/eclipse-kuksa/kuksa-databroker-${{github.sha}}"
Expand Down
14 changes: 8 additions & 6 deletions Dockerfile → scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

# You need to run build-databroker.sh first, for all platforms you want to build
# the container for as this docker file just collects the artifacts, i.e.
# ./build-databroker.sh arm64 amd64 riscv64

# $ KUKSA_DATABROKER_SBOM=y ./scripts/build-databroker.sh arm64 amd64 riscv64
#
# This Dockerfile is intended to run inside the root directory, i.e.
# $ docker buildx build --platform linux/amd64 -f scripts/Dockerfile .


# Different targets need different base images, so prepare aliases here
Expand All @@ -31,7 +33,7 @@ ENV BUILDTARGET="aarch64-unknown-linux-musl"
# RISCV is a glibc build. Rust toolchain not supported for MUSL
# Normally we prefer "distroless" base images, i.e.:
# FROM gcr.io/distroless/base-debian12:debug as target-riscv64
# However, distorless has no RISCV support yet,
# However, distroless has no RISCV support yet,
# (Nov 2023). Using debian unstable for now
FROM riscv64/debian:sid-slim as target-riscv64
ENV BUILDTARGET="riscv64gc-unknown-linux-gnu"
Expand All @@ -43,9 +45,9 @@ ARG TARGETARCH

# Before running this file thirdparty files must have been created
# by build-databroker.sh or corresponding command in buildaction
COPY ./dist/$TARGETARCH/databroker /app/databroker
COPY ./dist/$TARGETARCH/sbom.json /app/sbom.json
COPY ./dist/$TARGETARCH/thirdparty-licenses/ /app/thirdparty-licenses
COPY ./scripts/dist/$TARGETARCH/databroker /app/databroker
COPY ./scripts/dist/$TARGETARCH/sbom.json /app/sbom.json
COPY ./scripts/dist/$TARGETARCH/thirdparty-licenses/ /app/thirdparty-licenses


COPY ./data/vss-core/vss_release_3.1.1.json vss_release_3.1.1.json
Expand Down
11 changes: 7 additions & 4 deletions Dockerfile-cli → scripts/Dockerfile-cli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

# You need to run build-databroker-cli.sh first, for all platforms you want to build
# the container for as this docker file just collects the artifacts, i.e.
# ./build-databroker-cli.sh arm64 amd64 riscv64
# $ KUKSA_DATABROKERCLI_SBOM=y ./scripts/build-databroker-cli.sh arm64 amd64 riscv64
#
# This Dockerfile is intended to run inside the root directory, i.e.
# $ docker buildx build --platform linux/amd64 -f scripts/Dockerfile-cli .

# AMD is a statically linked MUSL build
FROM scratch AS target-amd64
Expand Down Expand Up @@ -45,9 +48,9 @@ RUN apk update && apk add ncurses-terminfo-base
FROM target-$TARGETARCH as target
ARG TARGETARCH

COPY ./dist/$TARGETARCH/databroker-cli /app/databroker-cli
COPY ./dist/$TARGETARCH/sbom.json /app/sbom.json
COPY ./dist/$TARGETARCH/thirdparty-licenses/ /app/thirdparty-licenses
COPY ./scripts/dist/$TARGETARCH/databroker-cli /app/databroker-cli
COPY ./scripts/dist/$TARGETARCH/sbom.json /app/sbom.json
COPY ./scripts/dist/$TARGETARCH/thirdparty-licenses/ /app/thirdparty-licenses

# Copy terminfo database
COPY --from=terminfo-donor /etc/terminfo /etc/terminfo
Expand Down
36 changes: 19 additions & 17 deletions build-databroker-cli.sh → scripts/build-databroker-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ set -e
SCRIPT_PATH=$(realpath "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")

cd ${SCRIPT_DIR}

# need a key value matching but no bash 4 an macOS
# so this nice hack works on bash 3 as well
tmprefix=$(basename -- "$0")
Expand Down Expand Up @@ -92,22 +94,6 @@ function build_target() {
target_rust=$1
target_docker=$2

echo "Building databroker-cli for target $target_rust"
cross build --target $target_rust --features $KUKSA_DATABROKERCLI_FEATURES --bin databroker-cli --release

echo "Prepare $target_docker dist folder"
rm -rf ./dist/$target_docker || true
mkdir ./dist/$target_docker
cp ./target/$target_rust/release/databroker-cli ./dist/$target_docker

if [[ $SBOM -eq 1 ]]; then
echo "Create $target_rust SBOM"
cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target $target_rust --manifest-path ./Cargo.toml
cp ./databroker-cli/databroker-cli_bin.cdx.json ./dist/$target_docker/sbom.json
rm -rf ./dist/$target_docker/thirdparty-licenses || true
collectlicensefiles ./databroker-cli/databroker-cli_bin.cdx.json ./dist/$target_docker/thirdparty-licenses --curation ./licensecuration.yaml
fi

# We need to clean this folder in target, otherwise we get weird side
# effects building the aarch image, complaining libc crate can not find
# GLIBC, i.e
Expand All @@ -123,7 +109,23 @@ function build_target() {
# the finished artifact resides in ../target/x86_64-unknown-linux-musl/release
# so deleting the temporary files in target/release is no problem
echo "Cleaning up...."
rm -rf ./target/release
rm -rf ../target/release

echo "Building databroker-cli for target $target_rust"
cross build --target $target_rust --features $KUKSA_DATABROKERCLI_FEATURES --bin databroker-cli --release

echo "Prepare $target_docker dist folder"
rm -rf ./dist/$target_docker || true
mkdir ./dist/$target_docker
cp ../target/$target_rust/release/databroker-cli ./dist/$target_docker

if [[ $SBOM -eq 1 ]]; then
echo "Create $target_rust SBOM"
cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target $target_rust --manifest-path ../Cargo.toml
cp ../databroker-cli/databroker-cli_bin.cdx.json ./dist/$target_docker/sbom.json
rm -rf ./dist/$target_docker/thirdparty-licenses || true
collectlicensefiles ../databroker-cli/databroker-cli_bin.cdx.json ./dist/$target_docker/thirdparty-licenses --curation ./licensecuration.yaml
fi
}


Expand Down
36 changes: 19 additions & 17 deletions build-databroker.sh → scripts/build-databroker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ set -e
SCRIPT_PATH=$(realpath "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")

cd ${SCRIPT_DIR}

# need a key value matching but no bash 4 an macOS
# so this nice hack works on bash 3 as well
tmprefix=$(basename -- "$0")
Expand Down Expand Up @@ -97,22 +99,6 @@ function build_target() {
target_rust=$1
target_docker=$2

echo "Building databroker for target $target_rust"
cross build --target $target_rust --features $KUKSA_DATABROKER_FEATURES --bin databroker --release

echo "Prepare $target_docker dist folder"
rm -rf ./dist/$target_docker || true
mkdir ./dist/$target_docker
cp ./target/$target_rust/release/databroker ./dist/$target_docker

if [[ $SBOM -eq 1 ]]; then
echo "Create $target_rust SBOM"
cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target $target_rust --manifest-path ./Cargo.toml
cp ./databroker/databroker_bin.cdx.json ./dist/$target_docker/sbom.json
rm -rf ./dist/$target_docker/thirdparty-licenses || true
collectlicensefiles ./databroker/databroker_bin.cdx.json ./dist/$target_docker/thirdparty-licenses --curation ./licensecuration.yaml
fi

# We need to clean this folder in target, otherwise we get weird side
# effects building the aarch image, complaining libc crate can not find
# GLIBC, i.e
Expand All @@ -128,7 +114,23 @@ function build_target() {
# the finished artifact resides in ../target/x86_64-unknown-linux-musl/release
# so deleting the temporary files in target/release is no problem
echo "Cleaning up...."
rm -rf ./target/release
rm -rf ../target/release

echo "Building databroker for target $target_rust"
cross build --target $target_rust --features $KUKSA_DATABROKER_FEATURES --bin databroker --release

echo "Prepare $target_docker dist folder"
rm -rf ./dist/$target_docker || true
mkdir ./dist/$target_docker
cp ../target/$target_rust/release/databroker ./dist/$target_docker

if [[ $SBOM -eq 1 ]]; then
echo "Create $target_rust SBOM"
cargo cyclonedx -v -f json --describe binaries --spec-version 1.4 --target $target_rust --manifest-path ../Cargo.toml
cp ../databroker/databroker_bin.cdx.json ./dist/$target_docker/sbom.json
rm -rf ./dist/$target_docker/thirdparty-licenses || true
collectlicensefiles ../databroker/databroker_bin.cdx.json ./dist/$target_docker/thirdparty-licenses --curation ./licensecuration.yaml
fi
}


Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 66df0f4

Please sign in to comment.