Skip to content

Commit

Permalink
Merge pull request clearcontainers#140 from jcvenegas/obs-branch-repo…
Browse files Browse the repository at this point in the history
…-creator

obs: create-repo-branch.sh: New script to create OBS repos.
  • Loading branch information
Julio Montes authored Aug 28, 2018
2 parents c2e2990 + 65c581e commit 65e57d4
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 80 deletions.
8 changes: 8 additions & 0 deletions obs-packaging/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#


clean:
find . -type d -name "*home:katacontainers*" -exec sudo rm -rf {} \;
30 changes: 4 additions & 26 deletions obs-packaging/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,10 @@ set -o pipefail

readonly script_name="$(basename "${BASH_SOURCE[0]}")"
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#Note:Lets update qemu and the kernel first, they take longer to build.
#Note: runtime is build at the end to get the version from all its dependencies.
projects=(
qemu-lite
qemu-vanilla
kernel
kata-containers-image
proxy
shim
ksm-throttler
runtime
)

OSCRC="${HOME}/.oscrc"
# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-pkgs.sh"

PUSH=${PUSH:-""}
LOCAL=${LOCAL:-""}
PUSH_TO_OBS=""
Expand All @@ -36,8 +26,6 @@ export BUILD_DISTROS=${BUILD_DISTROS:-xUbuntu_16.04}
export AUTHOR="${AUTHOR:-user}"
export AUTHOR_EMAIL="${AUTHOR_EMAIL:-user@example.com}"

OBS_API="https://api.opensuse.org"

usage() {
msg="${1:-}"
exit_code=$"${2:-0}"
Expand All @@ -52,19 +40,9 @@ EOT
main() {
local branch="${1:-}"
[ -n "${branch}" ] || usage "missing branch" "1"
if [ -n "${OBS_USER:-}" ] && [ -n "${OBS_PASS:-}" ] && [ ! -e "${OSCRC:-}" ]; then
echo "Creating ${OSCRC} with user $OBS_USER"
cat <<eom >"${OSCRC}"
[general]
apiurl = ${OBS_API}
[${OBS_API}]
user = ${OBS_USER}
pass = ${OBS_PASS}
eom
fi

pushd "${script_dir}"
for p in "${projects[@]}"; do
for p in "${OBS_PKGS_PROJECTS[@]}"; do
if [[ "$GO_ARCH" != "amd64" && "$p" == "qemu-lite" ]]; then
echo "Skipping packaging qemu-lite as its only for amd64 arch"
continue
Expand Down
59 changes: 24 additions & 35 deletions obs-packaging/build_from_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,30 @@ set -o pipefail

script_dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
script_name="$(basename "${BASH_SOURCE[0]}")"
cache_dir=${PWD}/obs-cache
#where packaing repo lives
packaging_repo_dir=$(cd "${script_dir}/.." && pwd)
#where results will be stored
host_datadir="${PWD}/pkgs"
obs_image="obs-kata"
export USE_DOCKER=1
http_proxy=${http_proxy:-}
https_proxy=${https_proxy:-}
no_proxy=${no_proxy:-}
PUSH=${PUSH:-}

# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-docker.sh"

GO_ARCH=$(go env GOARCH)
export GO_ARCH

docker_run() {
local cmd="$@"
sudo docker run \
--rm \
-v "${HOME}/.ssh":/root/.ssh \
-v "${HOME}/.gitconfig":/root/.gitconfig \
-v /etc/profile:/etc/profile \
--env GO_ARCH="${GO_ARCH}" \
--env http_proxy="${http_proxy}" \
--env https_proxy="${https_proxy}" \
--env no_proxy="${no_proxy}" \
--env PUSH="${PUSH}" \
--env DEBUG="${DEBUG:-}" \
--env OBS_SUBPROJECT="${OBS_SUBPROJECT:-}" \
-v "${HOME}/.bashrc":/root/.bashrc \
-v "$cache_dir":/var/tmp/osbuild-packagecache/ \
-v "$packaging_repo_dir":${packaging_repo_dir} \
-v "$host_datadir":/var/packaging \
-v "$HOME/.oscrc":/root/.oscrc \
-ti "$obs_image" bash -c "${cmd}"
}
OSCRC="${HOME}/.oscrc"
OBS_API="https://api.opensuse.org"

usage() {
msg="${1:-}"
exit_code=$"${2:-0}"
cat <<EOT
${msg}
Usage:
${script_name} <kata-branch>
${script_name} <kata-branch/tag>
EOT
exit "${exit_code}"
}
Expand All @@ -69,16 +50,24 @@ main() {
image_tarball=$(find . -name 'kata-containers-'"${branch}"'-*.tar.gz')
[ -f "${image_tarball}" ] || die "image not found"
popd >>/dev/null
sudo docker build \
--build-arg http_proxy="${http_proxy}" \
--build-arg https_proxy="${https_proxy}" \
--build-arg GO_ARCH="${GO_ARCH}" \
-t $obs_image "${script_dir}"

#Create/update OBS repository for branch
#docker_run "${packaging_repo_dir}/obs-packaging/create-pkg-branch.sh ${branch}"
#Build all kata packages
make -f "${script_dir}/Makefile" clean
if [ -n "${OBS_USER:-}" ] && [ -n "${OBS_PASS:-}" ] && [ ! -e "${OSCRC}" ]; then
echo "Creating ${OSCRC} with user $OBS_USER"
cat <<eom >"${OSCRC}"
[general]
apiurl = ${OBS_API}
[${OBS_API}]
user = ${OBS_USER}
pass = ${OBS_PASS}
eom
fi

if [ ! -e "${OSCRC}" ]; then
echo "${OSCRC}, please do 'export OBS_USER=your_user ; export OBS_PASS=your_pass' to configure osc for first time."
exit 1
fi
docker_run "${packaging_repo_dir}/obs-packaging/build_all.sh ${branch}"
}

main $@
main "$@"
147 changes: 147 additions & 0 deletions obs-packaging/create-repo-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/bin/bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
[ -z "${DEBUG}" ] || set -o xtrace

set -o errexit
set -o nounset
set -o pipefail

script_dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
script_name="$(basename "${BASH_SOURCE[0]}")"

# shellcheck source=./../scripts/lib.sh
source "${script_dir}/../scripts/lib.sh"

# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-docker.sh"

readonly home_project="home:katacontainers"
readonly template_pkg="kata-pkg-template"
arch_target=${ARCH:-$(uname -m)}

# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-pkgs.sh"

pkg_exist() {
local project="$1"
local pkg="$2"

docker_run osc list "${project}" | grep "${pkg}" || return 1
return 0

}

# Array of repositories.
#
# Each element is comprised of multiple parts in the form:
#
# name::project::repository
#
typeset -a repos
read_repos(){
while read -r p; do
[[ "$p" != "#"* ]] || continue
repos+=("${p}")
echo "Adding distro: ${p}"
done < "${script_dir}/distros"
}

# Array of maintainers
#
# Each element is comprised of multiple parts in the form:
#
# userid::role
#
typeset -a maintainers

read_maintainers(){
while read -r p; do
[[ "$p" != "#"* ]] || continue
maintainers+=("${p}::maintainer")
echo "Adding mantainer: ${p}"
done < "${script_dir}/maintainers"
}

create_repos_xml_nodes() {
for entry in "${repos[@]}"; do
[ -z "$entry" ] && die "found empty entry"
local name=$(echo "$entry" | awk -F"::" '{print $1;}')
local project=$(echo "$entry" | awk -F"::" '{print $2;}')
local repository=$(echo "$entry" | awk -F"::" '{print $3;}')
[ -z "$name" ] && die "no name for entry '$entry'"
[ -z "$project" ] && die "no project for entry '$entry'"
[ -z "$repository" ] && die "no repository for entry '$entry'"
echo " <repository name=\"${name}\">"
echo " <path project=\"${project}\" repository=\"${repository}\"/>"
arch_target_obs=${arch_target}
if [ "$arch_target" == "ppc64" ]; then
arch_target_obs="ppc64le"
fi
echo " <arch>${arch_target_obs}</arch>"
echo " </repository>"
done
}

create_mantainers_xml_nodes() {
for entry in "${mantainers[@]}"; do
[ -z "$entry" ] && die "found empty entry"
local userid=$(echo "$entry" | awk -F"::" '{print $1;}')
local role=$(echo "$entry" | awk -F"::" '{print $2;}')
[ -z "$userid" ] && die "no userid for entry '$entry'"
[ -z "$role" ] && die "no role for entry '$entry'"
echo " <person userid=\"${userid}\" role=\"${role}\"/>"
done
}

create_meta_xml() {
project="${1:-}"
branch="${2:-}"
[ -n "${project}" ] || die "project is empty"
[ -n "${branch}" ] || die "branch is empty"

read_maintainers
read_repos
cat >meta_project.xml <<EOT
<project name="${project}">
<title>Branch project for Kata Containers branch ${branch}</title>
<description>This project is the Kata Containers branch ${branch}</description>
$(create_mantainers_xml_nodes)
$(create_repos_xml_nodes)
</project>
EOT
}

usage() {
msg="${1:-}"
exit_code=$"${2:-0}"
cat <<EOT
${msg}
Usage:
${script_name} <kata-branch>
EOT
exit "${exit_code}"
}

main() {
local branch="${1:-}"
[ -n "${branch}" ] || usage "missing branch" "1"
project_branch="${home_project}:releases:${arch_target}:${branch}"
create_meta_xml "${project_branch}" "${branch}"
info "Creating/Updating project with name ${project_branch}"
# Update /Create project metadata.
docker_run osc meta prj "${project_branch}" -F meta_project.xml
for pkg in "${OBS_PKGS_PROJECTS[@]}"; do
if ! pkg_exist "${project_branch}" "${pkg}"; then
echo "Package ${pkg} does not exit in ${project_branch}, creating ..."
docker_run osc branch "${home_project}" "${template_pkg}" "${project_branch}" "${pkg}"
fi
pkg_dir="${project_branch}/${pkg}"
[ -d "${pkg_dir}/.osc" ] || docker_run osc co "${pkg_dir}"
done
}

main $@
16 changes: 16 additions & 0 deletions obs-packaging/distros
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Repositories.
#
# Each element is comprised of multiple parts in the form:
#
# name::project::repository
#
CentOS_7::CentOS:CentOS-7::standard
Fedora_26::Fedora:26::standard
Fedora_27::Fedora:27::standard
Fedora_28::Fedora:28::standard
RHEL_7::RedHat:RHEL-7::standard
SLE_12_SP3::SUSE:SLE-12-SP3:GA::standard
openSUSE_Leap_42.3::openSUSE:Leap:42.3::standard
xUbuntu_16.04::Ubuntu:16.04::universe
xUbuntu_17.10::Ubuntu:17.10::universe
xUbuntu_18.04::Ubuntu:18.04::universe
4 changes: 4 additions & 0 deletions obs-packaging/kata-containers-image/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ main() {

#image information
img_distro=$(get_from_kata_deps "assets.image.architecture.${arch_target}.name" "${kata_version}")
#In old branches this is not defined, use a default
img_distro=${img_distro:-clearlinux}
img_os_version=$(get_from_kata_deps "assets.image.architecture.${arch_target}.version" "${kata_version}")

#initrd information
initrd_distro=$(get_from_kata_deps "assets.image.architecture.${arch_target}.name" "${kata_version}")
#In old branches this is not defined, use a default
initrd_distro=${initrd_distro:-alpine}
initrd_os_version=$(get_from_kata_deps "assets.image.architecture.${arch_target}.version" "${kata_version}")

shift "$((OPTIND - 1))"
Expand Down
3 changes: 3 additions & 0 deletions obs-packaging/maintainers
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
egernst
jcvenega
nitkon
39 changes: 39 additions & 0 deletions obs-packaging/scripts/obs-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

_obs_docker_packaging_repo_dir=$(cd $(basename "${BASH_SOURCE[0]}"/../..) && pwd)
GO_ARCH=$(go env GOARCH)

docker_run() {
local cmd="$*"
local obs_image="obs-kata"
#where results will be stored
local host_datadir="${PWD}/pkgs"
local cache_dir=${PWD}/obs-cache
sudo docker build \
--quiet \
--build-arg http_proxy="${http_proxy:-}" \
--build-arg GO_ARCH="${GO_ARCH}" \
--build-arg https_proxy="${https_proxy:-}" \
-t $obs_image "${_obs_docker_packaging_repo_dir}/obs-packaging"

sudo docker run \
--rm \
--env http_proxy="${http_proxy:-}" \
--env https_proxy="${https_proxy:-}" \
--env no_proxy="${no_proxy:-}" \
--env GO_ARCH="${GO_ARCH}" \
--env PUSH="${PUSH:-}" \
--env DEBUG="${DEBUG:-}" \
--env OBS_SUBPROJECT="${OBS_SUBPROJECT:-}" \
-v "${cache_dir}":/var/tmp/osbuild-packagecache/ \
-v "${_obs_docker_packaging_repo_dir}":"${_obs_docker_packaging_repo_dir}" \
-v "${host_datadir}":/var/packaging \
-v "${HOME}/.oscrc":/root/.oscrc \
-v "${PWD}":"${PWD}" \
-w "${PWD}" \
-ti "${obs_image}" bash -c "${cmd}"
}
18 changes: 18 additions & 0 deletions obs-packaging/scripts/obs-pkgs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

#Note:Lets update qemu and the kernel first, they take longer to build.
#Note: runtime is build at the end to get the version from all its dependencies.
OBS_PKGS_PROJECTS=(
qemu-lite
qemu-vanilla
kernel
kata-containers-image
proxy
shim
ksm-throttler
runtime
)
Loading

0 comments on commit 65e57d4

Please sign in to comment.