blob: 0a461153c61f7735295de90ff44d0937af5cc2e9 [file] [log] [blame]
#!/bin/bash
set -ex
KERNEL_SRC_DIR="${KOKORO_ARTIFACTS_DIR}/git/kernel"
CONTAINER_NAME="gcr.io/cloud-kernel-build/cos-kernel-devenv:v20211123"
declare -a CONTAINER_CMD
CONTAINER_CMD=( sudo docker run --rm -v "${KERNEL_SRC_DIR}":/src -w /src "${CONTAINER_NAME}" )
FILE_PREFIX="cos-kernel"
SRC="src"
HEADERS="headers"
DEBUG="debug"
GCS_PATH="gs://cos-kernel-artifacts"
BUILD_OUTPUT="build"
GCS_DIR=""
KERNEL_VERSION=""
cd "${KOKORO_ARTIFACTS_DIR}/git/kernel"
sudo gcloud docker -- pull ${CONTAINER_NAME}
echo "Using devenv container: ${CONTAINER_NAME}"
echo -n "-${KOKORO_BUILD_NUMBER}.${BRANCH}" > localversion
echo "${KOKORO_GIT_COMMIT}" > kernel_commit
# Remove '+' sign from the version
touch .scmversion
echo "COS branch: ${BRANCH}"
echo "Git commit: ${KOKORO_GIT_COMMIT}"
echo "Archiving source code"
# Archive source files before building the kernel.
tar --exclude=.git -czf /tmp/${FILE_PREFIX}-${SRC}.tgz .
for arch in 'x86' 'arm64'
do
"${CONTAINER_CMD[@]}" -k -H -d -A "${arch}" -O "${BUILD_OUTPUT}_${arch}"
# Fixup permissions
sudo chown -R "$(id -u):$(id -g)" .
if [[ -z "${KERNEL_VERSION}" ]]
then
KERNEL_VERSION=$("${CONTAINER_CMD[@]}" -O "${BUILD_OUTPUT}_${arch}" kernelrelease | tail -2 | head -1)
fi
done
if [[ "${KOKORO_JOB_TYPE}" = CONTINUOUS_INTEGRATION ]]; then
GCS_DIR="${GCS_PATH}/${KERNEL_VERSION}"
elif [[ "${KOKORO_JOB_TYPE}" = "PRESUBMIT_GERRIT_ON_BORG" ]]; then
# store presubmit artifacts into dedicated folder
# so they could be used in further tests/qualification
GCS_DIR="${GCS_PATH}/presubmit/${KOKORO_BUILD_ID}"
else
echo "Unknown Kokoro job type: '${KOKORO_JOB_TYPE}'"
exit 1
fi
for arch in 'x86' 'arm64'
do
gsutil cp "${FILE_PREFIX}-${KERNEL_VERSION}-${arch}.txz" "${GCS_DIR}"/
gsutil cp "${FILE_PREFIX}-${HEADERS}-${KERNEL_VERSION}-${arch}.tgz" "${GCS_DIR}"/
gsutil cp "${FILE_PREFIX}-${DEBUG}-${KERNEL_VERSION}-${arch}.txz" "${GCS_DIR}"/
done
gsutil cp kernel_commit "${GCS_DIR}"/
# Rename the source archive with correct kernel version.
gsutil cp "/tmp/${FILE_PREFIX}-${SRC}.tgz" "${GCS_DIR}/${FILE_PREFIX}-${SRC}-${KERNEL_VERSION}.tgz"
rm "/tmp/${FILE_PREFIX}-${SRC}.tgz"