Skip to content

Commit

Permalink
Issue minishift#6 add ci for fedora iso
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar authored and gbraad committed Sep 28, 2018
1 parent f2797da commit 65268b6
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 187 deletions.
11 changes: 7 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
config.vm.box = "fedora/28"
config.vm.box = "generic/fedora28"

config.vm.provider "virtualbox" do |v, override|
v.memory = 2048
Expand All @@ -23,11 +23,14 @@ Vagrant.configure(2) do |config|
target_path = ENV['USERPROFILE'].gsub(/\\/,'/').gsub(/[[:alpha:]]{1}:/){|s|'/' + s.downcase.sub(':', '')}
config.vm.synced_folder ENV['USERPROFILE'], target_path, type: 'sshfs', sshfs_opts_append: '-o umask=000 -o uid=1000 -o gid=1000'
else
config.vm.synced_folder ENV['HOME'], ENV['HOME'], type: 'sshfs', sshfs_opts_append: '-o umask=000 -o uid=1000 -o gid=1000'
config.vm.synced_folder "/opt/fedora", "/opt", type: 'sshfs', sshfs_opts_append: '-o umask=000 -o uid=1000 -o gid=1000'
end

config.vm.provision "shell", inline: <<-SHELL
# Docker and parted is required to get selinux context: https://bugzilla.redhat.com/show_bug.cgi?id=1303565
sudo dnf install -y git livecd-tools docker parted
# Docker and parted packages are required to get selinux context: https://bugzilla.redhat.com/show_bug.cgi?id=1303565
sudo dnf -y update
sudo dnf install -y git livecd-tools docker parted make sudo gettext
cd /opt/
make
SHELL
end
218 changes: 164 additions & 54 deletions centos_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,172 @@ set -x
# Exit on error
set -e

# GitHub user
REPO_OWNER="minishift"
REPO_NAME="minishift-centos-iso"

########################################################
# Exit with message on failure of last executed command
# Arguments:
# $1 - Exit code of last executed command
# $2 - Error message
########################################################
function exit_on_failure() {
if [[ "$1" != 0 ]]; then
echo "$2"
exit 1
fi
}

# Source environment variables of the jenkins slave
# that might interest this worker.
if [ -e "jenkins-env" ]; then
cat jenkins-env \
| grep -E "(JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY)=" \
| sed 's/^/export /g' \
> ~/.jenkins-env
source ~/.jenkins-env
fi
function load_jenkins_vars() {
if [ -e "jenkins-env" ]; then
cat jenkins-env \
| grep -E "(JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY|GITHUB_TOKEN|JOB_NAME|RELEASE_VERSION)=" \
| sed 's/^/export /g' \
> ~/.jenkins-env
source ~/.jenkins-env
fi

echo 'CICO: Jenkins ENVs loaded'
}

function install_required_packages() {
# Install EPEL repo
yum -y install epel-release
# Get all the deps in
yum -y install make \
git \
curl \
kvm \
qemu-kvm \
libvirt \
python-requests \
libvirt-devel \
git \
jq \
gcc \
https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.rpm

echo 'CICO: Required packages installed'
}

function create_required_files() {
mkdir -p /opt/fedora
cp -r * /opt/fedora
cd /opt/fedora
}

function start_libvirt() {
systemctl start libvirtd
}

function install_vagrant_plugin() {
vagrant plugin install vagrant-libvirt
vagrant plugin install vagrant-sshfs
}

function vagrant_up_and_destroy() {
vagrant up
vagrant destroy -f || true
}

function setup_kvm_machine_driver() {
curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-centos7 > /usr/local/bin/docker-machine-driver-kvm && \
chmod +x /usr/local/bin/docker-machine-driver-kvm
}

function perform_artifacts_upload() {
rm -rf build/bin # Don't upload bin folder
set +x

# For PR build, GIT_BRANCH is set to branch name other than origin/master
if [[ "$GIT_BRANCH" = "origin/master" ]]; then
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p minishift-centos-iso/master/$BUILD_NUMBER/
cp build/* minishift-centos-iso/master/$BUILD_NUMBER/
RSYNC_PASSWORD=$1 rsync -a --relative minishift-centos-iso/master/$BUILD_NUMBER/ [email protected]::minishift/
echo "Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER}/${REPO_NAME}/master/$BUILD_NUMBER ."
else
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p minishift-centos-iso/pr/$ghprbPullId/
cp build/* minishift-centos-iso/pr/$ghprbPullId/
RSYNC_PASSWORD=$1 rsync -a --relative minishift-centos-iso/pr/$ghprbPullId/ [email protected]::minishift/
echo "Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER}/${REPO_NAME}/pr/$ghprbPullId ."
fi
}

function create_release_commit() {
# Create master branch as git clone in CI doesn't create it
git checkout -b master
# Bump version and commit
sed -i "s|VERSION=.*|VERSION=$RELEASE_VERSION|" Makefile
git add Makefile
git commit -m "cut v$RELEASE_VERSION"
git push https://$REPO_OWNER:$GITHUB_TOKEN@github.com/$REPO_OWNER/$REPO_NAME master
}

function add_release_notes() {
release_id=$(curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases" | jq --arg release "v$RELEASE_VERSION" -r ' .[] | if .name == $release then .id else empty end')

if [[ "$release_id" != "" ]]; then
MILESTONE_ID=`curl -s https://api.github.com/repos/minishift/${REPO_NAME}/milestones?state=all | jq --arg version "v$RELEASE_VERSION" -r ' .[] | if .title == $version then .number else empty end'`

if [[ "$MILESTONE_ID" != "" ]]; then
# Generate required json payload for release note
./scripts/release/issue-list.sh -r $REPO_NAME -m $MILESTONE_ID | jq -Rn 'inputs + "\n"' | jq -s '{body: add }' > json_payload.json
# Add release notes
curl -H "Content-Type: application/json" -H "Authorization: token $GITHUB_TOKEN" \
--data @json_payload.json https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/$release_id

echo "Release notes of Minishift CentOS ISO v$RELEASE_VERSION has been successfully updated. Find the release notes here https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/v$RELEASE_VERSION."
else
echo "Failed to get milestone ID for Minishift CentOS ISO v$RELEASE_VERSION. Use manual approach to update the release notes here https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/v$RELEASE_VERSION."
fi
else
return 1
fi
}

function perform_release() {
create_release_commit
exit_on_failure "$?" "Unable to create release commit."

make release
exit_on_failure "$?" "Failed to release Minishift CentOS ISO v$RELEASE_VERSION. Try to release manually."
echo "Minishift CentOS ISO v$RELEASE_VERSION has been successfully released. Find the latest release here https://github.com/$REPO_OWNER/$REPO_NAME/releases/tag/v$RELEASE_VERSION."

add_release_notes;
exit_on_failure "$?" "Failed to update release notes of Minishift CentOS ISO v$RELEASE_VERSION. Try to manually update the release notes here - https://github.com/$REPO_OWNER/$REPO_NAME/releases/tag/v$RELEASE_VERSION."
}

# Execution starts here
load_jenkins_vars
install_required_packages
create_required_files
start_libvirt
install_vagrant_plugin
vagrant_up_and_destroy
setup_kvm_machine_driver

# Set Terminal
export TERM=xterm-256color
# Add git a/c identity
git config --global user.email "[email protected]"
git config --global user.name "Minishift Bot"

# Build ISO and test
make test

# Retrieve password for rsync
CICO_PASS=$(echo $CICO_API_KEY | cut -d'-' -f1-2)
# Export GITHUB_ACCESS_TOKEN to prevent Github rate limit and push to master during release job
export GITHUB_ACCESS_TOKEN=$GITHUB_TOKEN

# Get all the deps in
yum -y install \
make \
git \
epel-release \
livecd-tools \
curl \
docker \
parted \
kvm \
qemu-kvm \
libvirt

# Start Libvirt
sudo systemctl start libvirtd

# Install Avocado
sudo curl https://repos-avocadoproject.rhcloud.com/static/avocado-el.repo -o /etc/yum.repos.d/avocado.repo
sudo yum install -y avocado

# Setup test drivers
curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.7.0/docker-machine-driver-kvm > /usr/local/bin/docker-machine-driver-kvm && \
chmod +x /usr/local/bin/docker-machine-driver-kvm

# Prepare ISO for testing
make centos_iso

# Let's test with showing log enabled
SHOW_LOG=--show-job-log make test

# On reaching successfully at this point, upload artifacts
PASS=$(echo $CICO_API_KEY | cut -d'-' -f1-2)

rm -rf build/bin # Don't upload bin folder
set +x
# For PR build, GIT_BRANCH is set to branch name other than origin/master
if [[ "$GIT_BRANCH" = "origin/master" ]]; then
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p minishift-centos-iso/master/$BUILD_NUMBER/
cp build/* minishift-centos-iso/master/$BUILD_NUMBER/
RSYNC_PASSWORD=$PASS rsync -a --relative minishift-centos-iso/master/$BUILD_NUMBER/ [email protected]::minishift/
echo "Find Artifacts here http://artifacts.ci.centos.org/minishift/minishift-centos-iso/master/$BUILD_NUMBER ."
if [[ "$JOB_NAME" = "minishift-centos-iso-release" ]]; then
perform_release
else
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p minishift-centos-iso/pr/$ghprbPullId/
cp build/* minishift-centos-iso/pr/$ghprbPullId/
RSYNC_PASSWORD=$PASS rsync -a --relative minishift-centos-iso/pr/$ghprbPullId/ [email protected]::minishift/
echo "Find Artifacts here http://artifacts.ci.centos.org/minishift/minishift-centos-iso/pr/$ghprbPullId ."
# Runs for both PR and master jobs
perform_artifacts_upload $CICO_PASS
fi
127 changes: 0 additions & 127 deletions tests/test.py

This file was deleted.

Loading

0 comments on commit 65268b6

Please sign in to comment.