File _image.spec.in of Package OBS-source-services-docker

# needsrootforbuild


%define image_name __IMAGE_NAME__

Url:            http://www.suse.com/
Name:           __NAME__
Summary:        Package with __SUSE_PRODUCT_NAME__ __SUSE_VERSION__ docker image
Version:        __VERSION__
Release:        __RELEASE__
Group:          System/Management
License:        SUSE-EULA
Source0:        __SOURCE0__
Source1:        __SOURCE1__
Source2:        __SOURCE2__
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
This package contains the official __SUSE_PRODUCT_NAME__ __SUSE_VERSION__
image for Docker.

%prep
echo __RELEASE__ > BUILD_ID

%build

%install
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native
install -p -D -m 644 %{SOURCE0} $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/
install -p -D -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/
install -p -D -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/
ln -s ./$(basename %{SOURCE0}) $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/__PKG_NAME__
ln -s ./$(basename %{SOURCE1}) $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/__PKG_NAME__.%{_arch}-__VERSION__-Build__RELEASE__.metadata
ln -s ./$(basename %{SOURCE2}) $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/__PKG_NAME__.%{_arch}-__VERSION__-Build__RELEASE__.tag
mkdir -p %{buildroot}/usr/lib/obs/services/
cp BUILD_ID $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/

if [[ -d /usr/src/packages/KIWIROOT ]];then
       KIWIROOT="/usr/src/packages/KIWIROOT"
elif [[ -d /usr/src/packages/KIWIROOT-docker ]];then
       KIWIROOT="/usr/src/packages/KIWIROOT-docker"
fi

if [[ -n $KIWIROOT ]];then
  [[ -d %{buildroot}/usr/lib/obs/service/ ]] || \
       mkdir -p %{buildroot}/usr/lib/obs/service/
  cp $KIWIROOT/usr/lib/obs/service/*.service \
       %{buildroot}/usr/lib/obs/service/ || /bin/true
fi


%files
%defattr(-, root, root)
%{_datadir}/suse-docker-images/native
%dir /usr/lib/obs
/usr/lib/obs/service/

%post
VER=$(docker load -qi %{_datadir}/suse-docker-images/native/__PKG_NAME__.%{_arch}-__VERSION__-Build__RELEASE__.docker.tar.xz |grep "Loaded image:"|cut -f3 -d:)
docker tag __PKG_NAME__:$VER __PKG_NAME__:latest

%changelog
openSUSE Build Service is sponsored by