Migrate from pygit2 to GitPython

Change-Id: Ib477b945e922fd0a1767bd6643c0a45751599fad
This commit is contained in:
Tim Heyer 2017-08-08 18:27:25 +00:00
parent 498cf6c98f
commit ea6ad23672
12 changed files with 23 additions and 79 deletions

View File

@ -6,11 +6,9 @@ python:
- "2.7"
before_install:
- sudo sh tools/libgit2.sh
- pip install -r test-requirements.txt
- pip install -r requirements.txt
- pip install tox
- pip install pygit2==0.25.0
install:
- pip install -e .

View File

@ -3,7 +3,6 @@ FROM ubuntu:16.04
MAINTAINER Armada Team
ENV DEBIAN_FRONTEND noninteractive
ENV LIBGIT_VERSION 0.25.0
COPY . /armada
@ -16,36 +15,23 @@ RUN apt-get update && \
python-setuptools && \
apt-get install -y \
build-essential \
cmake \
curl \
git \
libffi-dev \
python-all-dev && \
useradd -u 1000 -g users -d /armada armada && \
\
curl -sSL https://github.com/libgit2/libgit2/archive/v$LIBGIT_VERSION.tar.gz \
| tar zx -C /tmp && \
cd /tmp/libgit2-$LIBGIT_VERSION && \
cmake . && \
cmake --build . --target install && \
ldconfig && \
\
cd /armada && \
pip install --upgrade pip && \
pip install -r requirements.txt pygit2==$LIBGIT_VERSION && \
pip install -r requirements.txt && \
pip install . && \
\
apt-get purge --auto-remove -y \
build-essential \
cmake \
curl \
git \
libffi-dev \
python-all-dev && \
apt-get clean -y && \
rm -rf \
/root/.cache \
/tmp/libgit2-$LIBGIT_VERSION \
/var/lib/apt/lists/*
EXPOSE 8000

View File

@ -56,7 +56,6 @@ Your output will look something like this:
$ armada apply examples/openstack-helm.yaml 2017-02-10 09:42:36,753
armada INFO Cloning git:
.. _pygit2: http://www.pygit2.org/install.html#libgit2-within-a-virtual-environment
.. _kubectl: https://kubernetes.io/docs/user-guide/kubectl/kubectl_config/
.. |Docker Repository on Quay| image:: https://quay.io/repository/attcomdev/armada/status

View File

@ -303,7 +303,7 @@ class Armada(object):
'''
Operations to run after deployment process has terminated
'''
# Delete git repos cloned for deployment
# Delete temp dirs used for deployment
for group in self.config.get(KEYWORD_ARMADA).get(KEYWORD_GROUPS):
for ch in group.get(KEYWORD_CHARTS):
if ch.get('chart').get('source').get('type') == 'git':

View File

@ -24,10 +24,10 @@ class GitTestCase(unittest.TestCase):
SOURCE_UTILS_LOCATION = 'armada.utils.source'
@mock.patch('armada.utils.source.tempfile')
@mock.patch('armada.utils.source.pygit2')
def test_git_clone_good_url(self, mock_pygit, mock_temp):
@mock.patch('armada.utils.source.Repo')
def test_git_clone_good_url(self, mock_git_repo, mock_temp):
mock_temp.mkdtemp.return_value = '/tmp/armada'
mock_pygit.clone_repository.return_value = "Repository"
mock_git_repo.clone_from.return_value = "Repository"
url = 'http://github.com/att-comdev/armada'
dir = source.git_clone(url)

View File

@ -1,24 +1,29 @@
import pygit2
import os
import requests
import tarfile
import tempfile
import shutil
from git import Repo
from os import path
from ..exceptions import source_exceptions
def git_clone(repo_url, branch='master'):
'''
clones repo to a /tmp/ dir
:params repo_url - URL of git repo to clone
:params branch - branch of the repo to clone
Returns a path to the cloned repo
'''
if repo_url == '':
raise source_exceptions.GitLocationException(repo_url)
os.environ['GIT_TERMINAL_PROMPT'] = '0'
_tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp')
try:
pygit2.clone_repository(repo_url, _tmp_dir, checkout_branch=branch)
Repo.clone_from(repo_url, _tmp_dir, **{'branch': branch})
except Exception:
raise source_exceptions.GitLocationException(repo_url)

View File

@ -25,17 +25,10 @@ To use the docker containter to develop:
Virtualenv
##########
To use VirtualEnv we will need to add some extra steps
To use VirtualEnv:
1. virtualenv venv
2. source ./venv/bin/activate
3. sudo sh ./tools/libgit2.sh
Test that it worked with:
.. code-block:: bash
python -c 'import pygit2'
From the directory of the forked repository:
@ -47,8 +40,8 @@ From the directory of the forked repository:
.. note::
this will install the latest libgit2 library so you have to make sure you
install the same version library with pip ( current version: 0.25.0 )
If building from source, Armada requires that git be installed on
the system.
Kubernetes
##########

View File

@ -13,9 +13,9 @@ Tiller Exceptions
+------------------------------------+--------------------------------------------------------------------------------------------+
| Exception | Error Description |
+====================================+============================================================================================+
| ChartCleanupException | An error occurred removing a chart. |
| ChartCleanupException | An error occurred removing a chart. |
+------------------------------------+--------------------------------------------------------------------------------------------+
| ListChartsException | An error occurred listing helm charts. |
| ListChartsException | An error occurred listing helm charts. |
+------------------------------------+--------------------------------------------------------------------------------------------+
| PostUpdateJobDeleteException | An error occurred deleting a job after an update. |
+------------------------------------+--------------------------------------------------------------------------------------------+
@ -29,7 +29,7 @@ Tiller Exceptions
+------------------------------------+--------------------------------------------------------------------------------------------+
| ReleaseInstallException | A release failed to install. |
+------------------------------------+--------------------------------------------------------------------------------------------+
| ReleaseUpdateException | A release failed to update. |
| ReleaseUpdateException | A release failed to update. |
+------------------------------------+--------------------------------------------------------------------------------------------+
| TillerServicesUnavailableException | Occurs when Tiller services are unavailable. |
+------------------------------------+--------------------------------------------------------------------------------------------+
@ -79,9 +79,9 @@ Lint Exceptions
+----------------------------------+------------------------------+
| InvalidChartNameException | Chart name invalid. |
+----------------------------------+------------------------------+
| InvalidChartDefinitionException | Chart definition invalid. |
| InvalidChartDefinitionException | Chart definition invalid. |
+----------------------------------+------------------------------+
| InvalidReleaseException | Release invalid. |
+----------------------------------+------------------------------+
| InvalidArmadaObjectException | Armada object not declared. |
| InvalidArmadaObjectException | Armada object not declared. |
+----------------------------------+------------------------------+

View File

@ -54,14 +54,12 @@ Usage
docker run -d --net host -p 8000:8000 --name armada -v ~/.kube/config:/root/.kube/config -v $(pwd)/examples/:/examples quay.io/attcomdev/armada:latest
3. Check that tiller is Available
.. code:: bash
docker exec armada armada tiller --status
4. If tiller is up then we can start deploying our armada yamls
.. code:: bash

View File

@ -1,3 +1,4 @@
gitpython==2.1.5
grpc==0.3.post19
grpcio==1.1.3
grpcio-tools==1.1.3

View File

@ -1,32 +0,0 @@
#!/bin/sh
set -ex
# Ubuntu 16.04 Install only
apt-get update
apt-get install -y \
cmake \
git \
libffi-dev \
libssh2-1 \
libssh2-1-dev \
libssl-dev \
libxml2-dev \
libxslt1-dev \
libz-dev \
make \
pkg-config \
python-dev \
python-pip \
wget
LIBGIT_VERSION=${LIBGIT_VERSION:-'0.25.0'}
wget https://github.com/libgit2/libgit2/archive/v${LIBGIT_VERSION}.tar.gz
tar xzf v${LIBGIT_VERSION}.tar.gz
cd libgit2-${LIBGIT_VERSION}/
cmake .
make
make install
ldconfig

View File

@ -8,10 +8,6 @@ deps=
setenv=
PYTHONWARNINGS=all
[testenv:ubuntu]
commands =
sh {toxinidir}/tools/libgit2.sh
[testenv:docs]
commands = python setup.py build_sphinx
@ -26,5 +22,5 @@ commands = nosetest -w armada
[flake8] #TODO: Remove E402
ignore=E302,H306,E402,W503
exclude= libgit2-0.25.0, .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi
exclude= .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi