Skip to content

Commit

Permalink
Remove j2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
xumia committed Nov 18, 2020
1 parent 532efcc commit c912a8f
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 62 deletions.
47 changes: 25 additions & 22 deletions files/build/scripts/apt-get
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
#!/bin/bash

INSTALL=
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh

VERSION_FILE="/usr/local/share/buildinfo/base-versions/versions-deb"
for para in $@
do
if [[ "$para" != -* ]]; then
continue
fi
if [ ! -z "$INSTALL" ]; then
if [[ "$para" == *=* ]]; then
if [ "$ENABLE_VERSION_CONTROL_DEB" == "y" ]; then
for para in $@
do
if [[ "$para" != -* ]]; then
continue
package=$(echo "$para" | cut -d= -f1)
version=$(echo "$para" | cut -d= -f2)
if grep "^${package}=" $VERSION_FILE; then
if ! grep "^${package}==${version}$" $VERSION_FILE; then
EXPECTED_VERSION=$(grep "^${package}=" $VERSION_FILE | cut -d= -f3)
echo "${package}=${version}, expected version is ${EXPECTED_VERSION}"
fi
if [ ! -z "$INSTALL" ]; then
if [[ "$para" == *=* ]]; then
continue
package=$(echo "$para" | cut -d= -f1)
version=$(echo "$para" | cut -d= -f2)
if grep "^${package}=" $VERSION_FILE; then
if ! grep "^${package}==${version}$" $VERSION_FILE; then
EXPECTED_VERSION=$(grep "^${package}=" $VERSION_FILE | cut -d= -f3)
echo "${package}=${version}, expected version is ${EXPECTED_VERSION}"
exit 1
fi
fi
else
if ! grep "^${package}=" $VERSION_FILE; then
echo "The version of the package ${package} is not specified."
exit 1
fi
fi
else
if ! grep "^${package}=" $VERSION_FILE; then
echo "The version of the package ${package} is not specified."
exit 1
fi
elif [[ "$para" == "install" ]]; then
INSTALL=y
fi
elif [[ "$para" == "install" ]]; then
INSTALL=y
fi
done
done
fi


/usr/bin/apt-get $@
4 changes: 2 additions & 2 deletions files/build/templates/buildinfo.config.j2 → files/build/scripts/buildinfo_base.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ BUILD_VERSION_PATH=$BUILDINFO_PATH/build-versions
POST_VERSION_PATH=$BUILDINFO_PATH/post-versions
VERSION_DEB_PREFERENCE=$BUILDINFO_PATH/versions/01-versions-deb

PACKAGE_URL_PREFIX={{ PACKAGE_URL_PREFIX }}
SONIC_VERSION_CONTROL_COMPONENTS={{ SONIC_VERSION_CONTROL_COMPONENTS }}
. $BUILDINFO_PATH/config/buildinfo.config

URL_PREFIX=$(echo "${PACKAGE_URL_PREFIX}" | sed -E "s#(//[^/]*/).*#\1#")

log_err()
Expand Down
4 changes: 2 additions & 2 deletions files/build/scripts/pip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
. /usr/local/share/buildinfo/config/buildinfo.config

. /usr/local/share/buildinfo/scripts/buildinfo_base.sh


if [ -z "$PIP_COMMAND" ]; then
Expand Down
2 changes: 1 addition & 1 deletion files/build/scripts/post_run_buildinfo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. /usr/local/share/buildinfo/config/buildinfo.config
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh

[ -d $POST_VERSION_PATH ] && rm -rf $POST_VERSION_PATH

Expand Down
2 changes: 1 addition & 1 deletion files/build/scripts/pre_run_buildinfo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. /usr/local/share/buildinfo/config/buildinfo.config
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh

[ -d $DIFF_VERSION_PATH ] && rm -rf $DIFF_VERSION_PATH
mkdir -p $DIFF_VERSION_PATH
Expand Down
2 changes: 1 addition & 1 deletion files/build/scripts/wget
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. /usr/local/share/buildinfo/config/buildinfo.config
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
COMPONENT=web
VERSION_FILE=$VERSION_PATH/versions-web
BUILD_VERSION_FILE=$BUILD_VERSION_PATH/versions-web
Expand Down
13 changes: 0 additions & 13 deletions files/build/templates/dockerfile_auto_generate.j2

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/build_host_base_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ http_proxy=$4
TARGET=$TARGET_PATH
[ -z "$TARGET" ] && TARGET=target

. /usr/local/share/buildinfo/config/buildinfo.config
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh

TARGET_BASEIMAGE_PATH=$TARGET/versions/host-base-image
mkdir -p $TARGET_BASEIMAGE_PATH
Expand Down
2 changes: 1 addition & 1 deletion scripts/collect_build_version_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BLDENV=$2
TARGET_PATH=$3

TIMESTAMP=$(date +"%Y%m%d%H%M%S")
. /usr/local/share/buildinfo/config/buildinfo.config
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh

[ -z "$BLDENV" ] && BLDENV=$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2)
[ -z "$BLDENV" ] && exit $RET
Expand Down
10 changes: 2 additions & 8 deletions scripts/generate_buildinfo_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ BUILDINFO_PATH=files/build

TRUSTED_GPG_PATH=$BUILDINFO_PATH/buildinfo/trusted.gpg.d
BUILDINFO_CONFIG=$BUILDINFO_PATH/buildinfo/config/buildinfo.config
BUILDINFO_CONFIG_TEMPLATE=$BUILDINFO_PATH/templates/buildinfo.config.j2

AUTO_GENERATE_CODE_TEXT="Begin Auto-Generated Code"
DOCKERFILE_TEMPLATE="files/build/templates/dockerfile_auto_generate.j2"

[ -d $TRUSTED_GPG_PATH ] && rm -rf $TRUSTED_GPG_PATH
mkdir -p $TRUSTED_GPG_PATH
mkdir -p $BUILDINFO_PATH/buildinfo/config

# Generate build info config file
PACKAGE_URL_PREFIX=${PACKAGE_URL_PREFIX} \
j2 $BUILDINFO_CONFIG_TEMPLATE > $BUILDINFO_CONFIG

echo "PACKAGE_URL_PREFIX=$PACKAGE_URL_PREFIX" > $BUILDINFO_CONFIG
echo "SONIC_VERSION_CONTROL_COMPONENTS=$SONIC_VERSION_CONTROL_COMPONENTS" >> $BUILDINFO_CONFIG


# Download trusted gpgs
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare_base_image_buildinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARCH=$1
DISTRO=$2
FILESYSTEM_ROOT=$3

. /usr/local/share/buildinfo/config/buildinfo.config
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
VERSION_DEB_PREFERENCE="01-versions-deb"
BUILDINFO_PATH=${FILESYSTEM_ROOT}/usr/local/share/buildinfo
BUILDINFO_INSTALL_PATH=${FILESYSTEM_ROOT}/usr/local/sbin
Expand Down
24 changes: 15 additions & 9 deletions scripts/prepare_docker_buildinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ DISTRO=$5
DOCKERFILE_PATH=$(dirname "$DOCKERFILE_TARGE")
BUILDINFO_PATH="${DOCKERFILE_PATH}/buildinfo"
BUILDINFO_VERSION_PATH="${BUILDINFO_PATH}/versions"
BUILDINFO_CONFIG=$BUILDINFO_PATH/scripts/buildinfo.config

AUTO_GENERATE_CODE_TEXT="Begin Auto-Generated Code"
DOCKERFILE_TEMPLATE="files/build/templates/dockerfile_auto_generate.j2"
[ -d $BUILDINFO_PATH ] && rm -rf $BUILDINFO_PATH
mkdir -p $BUILDINFO_VERSION_PATH

Expand All @@ -24,18 +21,27 @@ if [ -z "$DISTRO" ]; then
[ -z "$DISTRO" ] && DISTRO=jessie
fi

DOCKERFILE_PRE_SCRIPT='# Auto-Generated for buildinfo
COPY ["buildinfo", "/usr/local/share/buildinfo"]
ENV OLDPATH=$PATH
ENV PATH="/usr/local/share/buildinfo/scripts:$PATH"
RUN pre_run_buildinfo'

DOCKERFILE_POST_SCRIPT="RUN post_run_buildinfo"
[ "$BUILD_SLAVE" != "y" ] && DOCKERFILE_POST_SCRIPT="$DOCKERFILE_POST_SCRIPT
ENV PATH=\$OLDPATH"


# Add the auto-generate code if it is not added in the target Dockerfile
if [ ! -f $DOCKERFILE_TARGE ] || ! grep -q "$AUTO_GENERATE_CODE_TEXT" $DOCKERFILE_TARGE; then
if [ ! -f $DOCKERFILE_TARGE ] || ! grep -q "Auto-Generated for buildinfo" $DOCKERFILE_TARGE; then
# Insert the docker build script before the RUN command
LINE_NUMBER=$(grep -Fn -m 1 'RUN' $DOCKERFILE | cut -d: -f1)
DOCKERFILE_BEFORE_RUN_SCRIPT=$(generate_code="before_run" j2 $DOCKERFILE_TEMPLATE)
TEMP_FILE=$(mktemp)
awk -v text="${DOCKERFILE_BEFORE_RUN_SCRIPT}" -v linenumber=$LINE_NUMBER 'NR==linenumber{print text}1' $DOCKERFILE > $TEMP_FILE
awk -v text="${DOCKERFILE_PRE_SCRIPT}" -v linenumber=$LINE_NUMBER 'NR==linenumber{print text}1' $DOCKERFILE > $TEMP_FILE

# Append the docker build script at the end of the docker file
SET_ENV_PATH=y
[ "$BUILD_SLAVE" == "y" ] && SET_ENV_PATH=n
generate_code="after_run" set_env_path=$SET_ENV_PATH j2 $DOCKERFILE_TEMPLATE >> $TEMP_FILE
echo "RUN post_run_buildinfo" >> $TEMP_FILE
[ "$BUILD_SLAVE" != "y" ] && echo "ENV PATH=\$OLDPATH" >> $TEMP_FILE

cat $TEMP_FILE > $DOCKERFILE_TARGE
rm -f $TEMP_FILE
Expand Down
8 changes: 8 additions & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ list :
include $(RULES_PATH)/config
-include $(RULES_PATH)/config.user


###############################################################################
## Version control relatived exports
###############################################################################
export PACKAGE_URL_PREFIX
export TRUSTED_GPG_URLS
export SONIC_VERSION_CONTROL_COMPONENTS

ifeq ($(SONIC_ENABLE_PFCWD_ON_START),y)
ENABLE_PFCWD_ON_START = y
endif
Expand Down

0 comments on commit c912a8f

Please sign in to comment.