Skip to content

Commit

Permalink
Docker image creation script. Makefile updated to let users use 'sudo…
Browse files Browse the repository at this point in the history
… make docker-image' and 'sudo make install-docker-image' to build and create docker image of photon. Currently it uses photon bintray repo instead of using local rpms to create the image. Fix pullsources.py bug that breaks in parallel download. Fix some spec files.
  • Loading branch information
Touseef Liaqat committed Jul 1, 2015
1 parent e97e4fe commit 16934d5
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!stage/photon-rootfs.tar.bz2

2 changes: 1 addition & 1 deletion support/dockerfiles/photon/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
FROM scratch
MAINTAINER [email protected]

ADD rootfs.tar.bz2 /
ADD stage/photon-rootfs.tar.bz2 /

VOLUME /var/lib/docker

Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ clean-install clean-chroot

PARALLEL=False

all: iso micro-iso minimal-iso
all: iso micro-iso minimal-iso docker-image

micro: micro-iso

Expand Down Expand Up @@ -163,6 +163,19 @@ $(PHOTON_STAGE):
@echo "Building LOGS folder..."
@test -d $(PHOTON_LOGS_DIR) || $(MKDIR) -p $(PHOTON_LOGS_DIR)

docker-image:
sudo docker run \
-it \
--rm \
--privileged \
--net=host \
-v `pwd`:/workspace \
toliaqat/photon-dev \
./support/dockerfiles/photon/make-docker-image.sh /workspace

install-docker-image: docker-image
sudo docker build -t photon:base .

clean: clean-install clean-chroot
@echo "Deleting Photon ISO..."
@$(RM) -f $(PHOTON_STAGE)/photon.iso
Expand Down
10 changes: 6 additions & 4 deletions SPECS/apr-util/apr-util.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The Apache Portable Runtime Utility Library.
%setup -q
%build
%configure --with-apr=%{_prefix} \
--includedir=%{_includedir}/apr-%{apuver} \
--includedir=%{_includedir}/apr-%{version} \
--with-ldap --without-gdbm \
--with-sqlite3 --with-pgsql \
--without-sqlite2 \
Expand All @@ -47,10 +47,12 @@ rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
/usr/lib/*
/usr/bin/*
/usr/include/*
%{_libdir}/*
%{_bindir}/*
%{_includedir}/*

%changelog
* Wed Jul 01 2015 Touseef Liaqat <[email protected]> 1.5.2-2
- Fix tags and paths.
* Wed May 20 2015 Touseef Liaqat <[email protected]> 1.5.2-1
- Initial build. First version
14 changes: 8 additions & 6 deletions SPECS/apr/apr.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Summary: The Apache Portable Runtime
Name: apr
Version: 1.5.2
Release: 1%{?dist}
Release: 2%{?dist}
License: Apache License 2.0
URL: https://apr.apache.org/
Group: System Environment/Libraries
Expand All @@ -15,8 +15,8 @@ The Apache Portable Runtime.
%setup -q
%build
./configure --prefix=/usr \
--includedir=%{_includedir}/apr-%{aprver} \
--with-installbuilddir=%{_libdir}/apr/build-%{aprver} \
--includedir=%{_includedir}/apr-%{version} \
--with-installbuilddir=%{_libdir}/apr/build-%{version} \
--with-devrandom=/dev/urandom \
CC=gcc CXX=g++

Expand All @@ -29,10 +29,12 @@ make DESTDIR=%{buildroot} install

%files
%defattr(-,root,root)
/usr/lib/*
/usr/bin/*
/usr/include/*
%{_libdir}/*
%{_bindir}/*
%{_includedir}/*

%changelog
* Wed Jul 01 2015 Touseef Liaqat <[email protected]> 1.5.2-2
- Fix tags and paths.
* Wed May 20 2015 Touseef Liaqat <[email protected]> 1.5.2-1
- Initial build. First version
100 changes: 66 additions & 34 deletions support/dockerfiles/photon/make-docker-image.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,76 @@
#!/bin/bash

if [ "$#" -lt 2 ]; then
echo "Script to create new Photon Docker image."
echo "Usage: $0 <path to workspace> <installation type>"
if [ "$#" -lt 1 ]; then
echo "Script to create new photon base docker image."
echo "Usage: $0 <path to workspace>"
exit -1
fi

set -e
set -x

PROGRAM=$0
ROOT=$1
TYPE=$2
IN_CONTAINER=$3

ROOTFS_TAR_FILENAME=rootfs.tar.bz2
INSTALLER_DIR=/workspace/photon/installer
PACKAGE_BUILDER_DIR=/workspace/photon/support/package-builder
DOCKERFILES_DIR=/workspace/photon/support/dockerfiles/photon/

if [ -z "$IN_CONTAINER" ]
then
rm -f $ROOTFS_TAR_FILENAME
docker run -it --privileged --rm -v $ROOT:/workspace toliaqat/ubuntu-dev bash /workspace/photon/support/dockerfiles/photon/${PROGRAM} $ROOT $TYPE "In Container" && \
[ -e "$ROOTFS_TAR_FILENAME" ] && docker build -t photon:$TYPE .
else

cd $INSTALLER_DIR && \
cp sample_config.json docker_image_config.json && \
sed -i -e "s/minimal/$TYPE/" docker_image_config.json && \
./photonInstaller.py -f -w /mnt/photon-root docker_image_config.json && \
rm docker_image_config.json
cd $PACKAGE_BUILDER_DIR && \
./umount-build-root.sh /mnt/photon-root && \
cd /mnt/photon-root && \
rm -rf tools/
rm -rf usr/src/
rm -rf boot/
rm -rf lib/modules/
tar cpjf /$ROOTFS_TAR_FILENAME . && \
cp /$ROOTFS_TAR_FILENAME $DOCKERFILES_DIR
fi
WORKSPACE_DIR=$1
RPMS_DIR=$WORKSPACE_DIR/stage/RPMS
TEMP_CHROOT=$(pwd)/temp_chroot

ROOTFS_TAR_FILENAME=photon-rootfs.tar.bz2
STAGE_DIR=$WORKSPACE_DIR/stage


sudo createrepo $RPMS_DIR

cat > yum.conf <<- "EOF"
[main]
cachedir=$(pwd)/temp_chroot/var/cache/yum
keepcache=1
debuglevel=2
logfile=$(pwd)/temp_chroot/var/log/yum.log
exactarch=1
obsoletes=1
[photon]
name=VMware Photon Linux 1.0(x86_64)
baseurl=https://dl.bintray.com/vmware/photon_release_1.0_x86_64
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY
gpgcheck=0
enabled=1
skip_if_unavailable=True
EOF

rm -rf $TEMP_CHROOT
mkdir $TEMP_CHROOT

# use host's yum to install in chroot
yum -c yum.conf --installroot=$TEMP_CHROOT install -y filesystem glibc
yum -c yum.conf --installroot=$TEMP_CHROOT install -y bash tdnf coreutils photon-release
yum -c yum.conf clean all
cp /etc/resolv.conf $TEMP_CHROOT/etc/

# reinstalling inside to make sure rpmdb is created for tdnf.
# TODO find better solution.
chroot $TEMP_CHROOT bash -c \
"tdnf install -y filesystem; \
tdnf install -y glibc ; \
tdnf install -y bash ; \
tdnf install -y coreutils ; \
tdnf install -y tdnf ; \
tdnf install -y photon-release; \
rpm -e --nodeps perl"

cd $TEMP_CHROOT
# cleanup anything not needed inside rootfs
rm -rf usr/src/
rm -rf home/*
rm -rf var/lib/yum/*
rm -rf /var/log/*
tar cpjf ../$ROOTFS_TAR_FILENAME .
mv ../$ROOTFS_TAR_FILENAME $STAGE_DIR
cd ..

# cleanup
rm -rf $TEMP_CHROOT
rm yum.conf

14 changes: 1 addition & 13 deletions support/pullsources/pullsources.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ def getFileHash(self, filepath):
f.close()
return sha1.hexdigest()

def downloadExistingFilePrompt(self, filename):
yes = ['yes', 'y']
no = ['no', 'n']
while True:
prompt = "Found a different local copy of {0}. Do you want to replace it? [y/n]:".format(filename)
answer = raw_input(prompt).lower()
if answer in yes:
return True
elif answer in no:
return False

def downloadFile(self, filename, file_path):
print '%s: Downloading %s...' % (str(datetime.datetime.today()), filename)

Expand Down Expand Up @@ -112,8 +101,7 @@ def ProcessDownload(self, package_and_source_dir):
self.downloadFileHelper(package_name, package_path, package_sha1)

elif package_sha1 != self.getFileHash(package_path):
if self.downloadExistingFilePrompt(package_name):
self.downloadFileHelper(package_name, package_path, package_sha1)
self.downloadFileHelper(package_name, package_path, package_sha1)

def _pickle(method):
if method.im_self is None:
Expand Down

0 comments on commit 16934d5

Please sign in to comment.