Skip to content

Commit

Permalink
Merge pull request #863 from zmrow/packages-dir
Browse files Browse the repository at this point in the history
Move built rpms to build/packages
  • Loading branch information
zmrow authored Mar 19, 2020
2 parents e849cc9 + 51b33f2 commit 32a43f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ RUN rpmdev-setuptree \

USER root
RUN --mount=target=/host \
ln -s /host/build/*.rpm ./rpmbuild/RPMS \
ln -s /host/build/packages/*.rpm ./rpmbuild/RPMS \
&& createrepo_c \
-o ./rpmbuild/RPMS \
-x '*-debuginfo-*.rpm' \
-x '*-debugsource-*.rpm' \
--no-database \
/host/build \
/host/build/packages \
&& cp .rpmmacros /etc/rpm/macros \
&& dnf -y \
--disablerepo '*' \
Expand Down Expand Up @@ -93,14 +93,14 @@ WORKDIR /root
USER root
RUN --mount=target=/host \
mkdir -p /local/rpms /local/migrations ./rpmbuild/RPMS \
&& ln -s /host/build/*.rpm ./rpmbuild/RPMS \
&& cp /host/build/bottlerocket-${ARCH}-migrations-*.rpm /local/migrations \
&& ln -s /host/build/packages/*.rpm ./rpmbuild/RPMS \
&& cp /host/build/packages/bottlerocket-${ARCH}-migrations-*.rpm /local/migrations \
&& createrepo_c \
-o ./rpmbuild/RPMS \
-x '*-debuginfo-*.rpm' \
-x '*-debugsource-*.rpm' \
--no-database \
/host/build \
/host/build/packages \
&& dnf -y \
--disablerepo '*' \
--repofrompath repo,./rpmbuild/RPMS \
Expand Down
5 changes: 4 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ skip_core_tasks = true
BUILDSYS_ARCH = { script = ["uname -m"] }
BUILDSYS_ROOT_DIR = "${CARGO_MAKE_WORKING_DIRECTORY}"
BUILDSYS_OUTPUT_DIR = "${BUILDSYS_ROOT_DIR}/build"
BUILDSYS_PACKAGES_DIR = "${BUILDSYS_OUTPUT_DIR}/packages"
BUILDSYS_TOOLS_DIR = "${BUILDSYS_ROOT_DIR}/tools"
BUILDSYS_SOURCES_DIR = "${BUILDSYS_ROOT_DIR}/sources"
BUILDSYS_TIMESTAMP = { script = ["date +%s"] }
Expand Down Expand Up @@ -38,6 +39,7 @@ BUILDSYS_DOCKER_RUN_ARGS = { default_value = "--network=host" }
script = [
'''
mkdir -p ${BUILDSYS_OUTPUT_DIR}
mkdir -p ${BUILDSYS_PACKAGES_DIR}
mkdir -p ${GO_MOD_CACHE}
for cmd in bash curl docker gunzip ; do
Expand Down Expand Up @@ -229,9 +231,10 @@ for ws in sources packages variants/* tools/buildsys ; do
cargo clean --manifest-path ${ws}/Cargo.toml
done
rm -f ${BUILDSYS_TOOLS_DIR}/bin/buildsys
for ext in rpm tar lz4 img ; do
for ext in tar lz4 img ; do
rm -f ${BUILDSYS_OUTPUT_DIR}/*.${ext}
done
rm -f ${BUILDSYS_PACKAGES_DIR}/*.rpm
rm -rf ${BUILDSYS_OUTPUT_DIR}/latest
rm -rf html
'''
Expand Down
15 changes: 10 additions & 5 deletions tools/buildsys/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl PackageBuilder {
/// Build RPMs for the specified package.
pub(crate) fn build(package: &str) -> Result<Self> {
let arch = getenv("BUILDSYS_ARCH")?;
let output = getenv("BUILDSYS_PACKAGES_DIR")?;

// We do *not* want to rebuild most packages when the variant changes, becauses most aren't
// affected; packages that care about variant should "echo cargo:rerun-if-env-changed=VAR"
Expand All @@ -42,7 +43,7 @@ impl PackageBuilder {
arch = arch,
);

build(&target, &build_args, &tag)?;
build(&target, &build_args, &tag, &output)?;

Ok(Self)
}
Expand All @@ -60,6 +61,7 @@ impl VariantBuilder {
let variant = getenv("BUILDSYS_VARIANT")?;
let version_image = getenv("BUILDSYS_VERSION_IMAGE")?;
let version_build = getenv("BUILDSYS_VERSION_BUILD")?;
let output = getenv("BUILDSYS_OUTPUT_DIR")?;

// Always rebuild variants since they are located in a different workspace,
// and don't directly track changes in the underlying packages.
Expand All @@ -78,16 +80,20 @@ impl VariantBuilder {
version_image = version_image,
version_build = version_build,
);
let tag = format!("buildsys-var-{variant}-{arch}", variant = variant, arch = arch);
let tag = format!(
"buildsys-var-{variant}-{arch}",
variant = variant,
arch = arch
);

build(&target, &build_args, &tag)?;
build(&target, &build_args, &tag, &output)?;

Ok(Self)
}
}

/// Invoke a series of `docker` commands to drive a package or variant build.
fn build(target: &str, build_args: &str, tag: &str) -> Result<()> {
fn build(target: &str, build_args: &str, tag: &str, output: &str) -> Result<()> {
// Our Dockerfile is in the top-level directory.
let root = getenv("BUILDSYS_ROOT_DIR")?;
std::env::set_current_dir(&root).context(error::DirectoryChange { path: &root })?;
Expand Down Expand Up @@ -122,7 +128,6 @@ fn build(target: &str, build_args: &str, tag: &str) -> Result<()> {
tag = tag,
));

let output = getenv("BUILDSYS_OUTPUT_DIR")?;
let create = args(format!("create --name {tag} {tag} true", tag = tag));
let cp = args(format!("cp {}:/output/. {}", tag, output));
let rm = args(format!("rm --force {}", tag));
Expand Down

0 comments on commit 32a43f5

Please sign in to comment.