File containerd.spec of Package containerd

# spec file for package containerd
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# Check if go_arches is defined in the project configuration
# Otherwise, define it here
# In order to define it in the project configuration, see
# The Macros tag is the one that defines the go_arches variable to be used
# in the spec file.
# The "define" one is to help the specfile parser of the buildservice
# to see what packages are being built. You also want to define it here
# for keeping things consistent.

%{!?go_arches: %global go_arches %ix86 x86_64 aarch64 ppc64le}

%ifarch %go_arches
%define go_tool go
%define GO_BUILD_FLAGS %{nil}
%define go_tool go-6
%define GO_BUILD_FLAGS "-gccgoflags=-Wl,--add-needed -Wl,--no-as-needed -static-libgo -ldl"

# MANUAL: Update the git_version and git_revision
%define git_version 2a5e70c
# How to get the git_revision
# git clone containerd-upstream
# cd containerd
# git checkout $git_version
# git_revision=r$(git rev-list HEAD | wc -l)
%define git_revision r569
%define version_unconverted %{git_version}

Name:           containerd
Version:        0.2.5+git%{git_revision}_%{git_version}
Release:        0
Summary:        Standalone OCI Container Daemon
License:        Apache-2.0
Group:          System/Management
Source:         %{name}-git.%{git_version}.tar.xz
Source1:        %{name}.service
Source2:        %{name}.socket
Source3:        sysconfig.%{name}
%ifarch %go_arches
BuildRequires:  go >= 1.5
BuildRequires:  gcc6-go >= 6.1
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# Currently runC is the only supported runtime for containerd. NOTE:
# This version pinning is done to follow (as well as we can) upstream's
# Dockerfile.  However, for some reason the Dockerfile for containerd
# diverges from the one for Docker. As such, this cannot be a hard
# requirement (that would break Docker).
Requires:       runc = 0.1.1+gitr2819_50a19c6
Requires(post): %fillup_prereq

%define client ctr
%define daemon %{name}
%define shim %{name}-shim

Containerd is a daemon with an API and a command line client, to manage
containers on one machine. It uses runC to run containers according to the OCI
specification. Containerd has advanced features such as seccomp and user
namespace support as well as checkpoint and restore for cloning and live
migration of containers.

%package ctr
Summary:        Client for %{name}
Group:          System/Management
Requires:       %{name} = %{version}
%ifarch %go_arches
BuildRequires:  go >= 1.5
BuildRequires:  gcc6-go >= 6.1

%description ctr
Standalone client for containerd, which allows management of containerd containers
separately from Docker.

%package test
Summary:        Test package for containerd
Group:          System/Management
%ifarch %go_arches
Requires:       go >= 1.5
Requires:       gcc5-go >= 5.0
BuildArch:      noarch

%description test
Test package for containerd. It contains the source code and the tests.

%setup -q -n %{name}-git.%{git_version}

# Do not use symlinks. If you want to run the unit tests for this package at
# some point during the build and you need to directly use go list directly it
# will get confused by symlinks.
export GOPATH=${HOME}/go:${HOME}/go/src/
mkdir -pv $HOME/go/src/
rm -rf $HOME/go/src/*
cp -avr * $HOME/go/src/

# Build daemon.
%go_tool build %GO_BUILD_FLAGS -x -o %{daemon}-%{version}{name}/%{daemon}

# Build shim.
%go_tool build %GO_BUILD_FLAGS -x -o %{shim}-%{version}{name}/%{shim}

# Build client.
%go_tool build %GO_BUILD_FLAGS -x -o %{client}-%{version}{name}/%{client}

%ifarch %go_arches
export GOPATH=$HOME/go/src/$GOPATH
cd $HOME/go/src/
go test -v $(go list ./... | grep | grep -v /integration-test)

%{__install} -D -m755 %{daemon}-%{version} %{buildroot}/%{_sbindir}/%{daemon}
%{__install} -D -m755 %{shim}-%{version} %{buildroot}/%{_sbindir}/%{shim}
%{__install} -D -m755 %{client}-%{version} %{buildroot}/%{_sbindir}/%{name}-%{client}

# Add service and sysconfig.
%{__install} -D -m644 %SOURCE1 %{buildroot}/%{_unitdir}/%{name}.service
%{__install} -D -m644 %SOURCE2 %{buildroot}/%{_unitdir}/%{name}.socket
ln -sf %{_sbindir}/service %{buildroot}/%{_sbindir}/rccontainerd
%{__install} -D -m644 %SOURCE3 %{buildroot}/var/adm/fillup-templates/sysconfig.%{name}

install -d -m755 %{buildroot}/usr/src/containerd/
cp -avr $HOME/go/src/* %{buildroot}/usr/src/containerd/

%service_add_pre %{name}.service %{name}.socket

%service_add_post %{name}.service %{name}.socket
%{fillup_only -n containerd}

%service_del_preun %{name}.service %{name}.socket

%service_del_postun %{name}.service %{name}.socket

%doc LICENSE.code

%files ctr

%files test
%exclude /usr/src/containerd/bin

openSUSE Build Service is sponsored by