Skip to content

Commit 35d93f0

Browse files
jlevequelguohan
authored andcommitted
[build] Remove sudo calls from build process (#2015)
* [build] Remove sudo calls from build process * Make regex more strict
1 parent 4715dbb commit 35d93f0

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Makefile.work

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ SLAVE_IMAGE = sonic-slave-$(USER)
4848
SLAVE_DIR = sonic-slave
4949
endif
5050

51-
INSMOD_OVERLAY := sudo modprobe overlay
51+
OVERLAY_MODULE_CHECK := lsmod | grep "^overlay " > /dev/null 2>&1 || (echo "ERROR: Module 'overlay' not loaded. Try running 'sudo modprobe overlay'."; exit 1)
52+
5253
DOCKER_RUN := docker run --rm=true --privileged \
5354
-v $(PWD):/sonic \
5455
-w /sonic \
@@ -94,13 +95,13 @@ SONIC_BUILD_INSTRUCTION := make \
9495
.DEFAULT_GOAL := all
9596

9697
%::
98+
@$(OVERLAY_MODULE_CHECK)
9799
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
98100
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
99101
$(DOCKER_BASE_BUILD) ; }
100102
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
101103
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
102104
$(DOCKER_BUILD) ; }
103-
@$(INSMOD_OVERLAY)
104105
ifeq "$(KEEP_SLAVE_ON)" "yes"
105106
ifdef SOURCE_FOLDER
106107
@$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
@@ -116,13 +117,13 @@ sonic-slave-build :
116117
$(DOCKER_BUILD)
117118

118119
sonic-slave-bash :
120+
@$(OVERLAY_MODULE_CHECK)
119121
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
120122
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
121123
$(DOCKER_BASE_BUILD) ; }
122124
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
123125
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
124126
$(DOCKER_BUILD) ; }
125-
@$(INSMOD_OVERLAY)
126127
@$(DOCKER_RUN) -t $(SLAVE_IMAGE):$(SLAVE_TAG) bash
127128

128129
showtag:

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,25 @@ To clone the code repository recursively, assuming git version 1.9 or newer:
4747

4848
To build SONiC installer image and docker images, run the following commands:
4949

50+
# Ensure the 'overlay' module is loaded on your development system
51+
sudo modprobe overlay
52+
53+
# Enter the source directory
5054
cd sonic-buildimage
5155

5256
# (Optional) Checkout a specific branch. By default, it uses master branch
5357
git checkout [branch_name]
5458

55-
# Execute make init once after cloning the repo, or fetched remote repo with submodule updates
59+
# Execute make init once after cloning the repo, or after fetching remote repo with submodule updates
5660
make init
5761

5862
# Execute make configure once to configure ASIC
5963
make configure PLATFORM=[ASIC_VENDOR]
6064

61-
# build debian stretch required targets (optional)
65+
# Build Debian Stretch required targets (Manual execution optional; will also be executed as part of the build)
6266
BLDENV=stretch make stretch
6367

64-
# build SONiC image
68+
# Build SONiC image
6569
make all
6670

6771
**NOTE**:

0 commit comments

Comments
 (0)