Skip to content

Commit

Permalink
Wrap new detection logic in simple tool
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcilvaney committed Nov 13, 2024
1 parent 29f8095 commit 6bb80e1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion toolkit/scripts/chroot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ worker_chroot_rpm_paths := $(shell sed -nr $(sed_regex_full_path) < $(WORKER_CHR
worker_chroot_deps := \
$(WORKER_CHROOT_MANIFEST) \
$(worker_chroot_rpm_paths) \
$(go-containercheck) \
$(PKGGEN_DIR)/worker/create_worker_chroot.sh
ifeq ($(REFRESH_WORKER_CHROOT),y)
$(chroot_worker): $(worker_chroot_deps) $(depend_REBUILD_TOOLCHAIN) $(depend_TOOLCHAIN_ARCHIVE)
else
$(chroot_worker):
endif
$(PKGGEN_DIR)/worker/create_worker_chroot.sh $(BUILD_DIR)/worker $(WORKER_CHROOT_MANIFEST) $(TOOLCHAIN_RPMS_DIR) $(LOGS_DIR)
$(PKGGEN_DIR)/worker/create_worker_chroot.sh $(BUILD_DIR)/worker $(WORKER_CHROOT_MANIFEST) $(TOOLCHAIN_RPMS_DIR) $(go-containercheck) $(LOGS_DIR)
validate-chroot: $(go-validatechroot) $(chroot_worker)
$(go-validatechroot) \
Expand Down
1 change: 1 addition & 0 deletions toolkit/scripts/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif
go_tool_list = \
bldtracker \
boilerplate \
containercheck \
depsearch \
downloader \
grapher \
Expand Down
33 changes: 33 additions & 0 deletions toolkit/tools/containercheck/containercheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// Returns true (exit code 0) if the current build is a container build, false (exit code 1) otherwise

package main

import (
"os"

"github.com/microsoft/azurelinux/toolkit/tools/internal/buildpipeline"
"github.com/microsoft/azurelinux/toolkit/tools/internal/exe"
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger"

"gopkg.in/alecthomas/kingpin.v2"
)

var (
app = kingpin.New("containercheck", "Returns true (0) if the current build is a container build, false (1) otherwise")
logFlags = exe.SetupLogFlags(app)
)

func main() {
app.Version(exe.ToolkitVersion)
kingpin.MustParse(app.Parse(os.Args[1:]))
logger.InitBestEffort(logFlags)

if buildpipeline.IsRegularBuild() {
os.Exit(1)
} else {
os.Exit(0)
}
}
9 changes: 5 additions & 4 deletions toolkit/tools/pkggen/worker/create_worker_chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ set -o pipefail
# $3 path to find RPMs. May be in PATH/<arch>/*.rpm
# $4 path to log directory

[ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ] && [ -n "$4" ] || { echo "Usage: create_worker.sh <./worker_base_folder> <rpms_to_install.txt> <./path_to_rpms> <./log_dir>"; exit; }
[ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ] && [ -n "$4" ] && [ -n "$4" ] || { echo "Usage: create_worker.sh <./worker_base_folder> <rpms_to_install.txt> <./path_to_rpms> <./containercheck> <./log_dir>"; exit; }

chroot_base=$1
packages=$2
rpm_path=$3
log_path=$4
container_check_tool=$4
log_path=$5

chroot_name="worker_chroot"
chroot_builder_folder=$chroot_base/$chroot_name
Expand Down Expand Up @@ -121,8 +122,8 @@ HOME=$ORIGINAL_HOME

# In case of Docker based build do not add the below folders into chroot tarball
# otherwise safechroot will fail to "untar" the tarball
DOCKERCONTAINERONLY=/.dockerenv
if [[ -f "$DOCKERCONTAINERONLY" ]]; then
if $container_check_tool; then
echo "Removing /dev, /proc, /run, /sys from chroot tarball for container based build." | tee -a "$chroot_log"
rm -rf "${chroot_base:?}/$chroot_name"/dev
rm -rf "${chroot_base:?}/$chroot_name"/proc
rm -rf "${chroot_base:?}/$chroot_name"/run
Expand Down

0 comments on commit 6bb80e1

Please sign in to comment.