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" - "2.7"
before_install: before_install:
- sudo sh tools/libgit2.sh
- pip install -r test-requirements.txt - pip install -r test-requirements.txt
- pip install -r requirements.txt - pip install -r requirements.txt
- pip install tox - pip install tox
- pip install pygit2==0.25.0
install: install:
- pip install -e . - pip install -e .

View File

@ -3,7 +3,6 @@ FROM ubuntu:16.04
MAINTAINER Armada Team MAINTAINER Armada Team
ENV DEBIAN_FRONTEND noninteractive ENV DEBIAN_FRONTEND noninteractive
ENV LIBGIT_VERSION 0.25.0
COPY . /armada COPY . /armada
@ -16,36 +15,23 @@ RUN apt-get update && \
python-setuptools && \ python-setuptools && \
apt-get install -y \ apt-get install -y \
build-essential \ build-essential \
cmake \
curl \ curl \
git \ git \
libffi-dev \
python-all-dev && \ python-all-dev && \
useradd -u 1000 -g users -d /armada armada && \ 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 && \ cd /armada && \
pip install --upgrade pip && \ pip install --upgrade pip && \
pip install -r requirements.txt pygit2==$LIBGIT_VERSION && \ pip install -r requirements.txt && \
pip install . && \ pip install . && \
\ \
apt-get purge --auto-remove -y \ apt-get purge --auto-remove -y \
build-essential \ build-essential \
cmake \
curl \ curl \
git \
libffi-dev \
python-all-dev && \ python-all-dev && \
apt-get clean -y && \ apt-get clean -y && \
rm -rf \ rm -rf \
/root/.cache \ /root/.cache \
/tmp/libgit2-$LIBGIT_VERSION \
/var/lib/apt/lists/* /var/lib/apt/lists/*
EXPOSE 8000 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 apply examples/openstack-helm.yaml 2017-02-10 09:42:36,753
armada INFO Cloning git: 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/ .. _kubectl: https://kubernetes.io/docs/user-guide/kubectl/kubectl_config/
.. |Docker Repository on Quay| image:: https://quay.io/repository/attcomdev/armada/status .. |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 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 group in self.config.get(KEYWORD_ARMADA).get(KEYWORD_GROUPS):
for ch in group.get(KEYWORD_CHARTS): for ch in group.get(KEYWORD_CHARTS):
if ch.get('chart').get('source').get('type') == 'git': 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' SOURCE_UTILS_LOCATION = 'armada.utils.source'
@mock.patch('armada.utils.source.tempfile') @mock.patch('armada.utils.source.tempfile')
@mock.patch('armada.utils.source.pygit2') @mock.patch('armada.utils.source.Repo')
def test_git_clone_good_url(self, mock_pygit, mock_temp): def test_git_clone_good_url(self, mock_git_repo, mock_temp):
mock_temp.mkdtemp.return_value = '/tmp/armada' 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' url = 'http://github.com/att-comdev/armada'
dir = source.git_clone(url) dir = source.git_clone(url)

View File

@ -1,24 +1,29 @@
import pygit2 import os
import requests import requests
import tarfile import tarfile
import tempfile import tempfile
import shutil import shutil
from git import Repo
from os import path from os import path
from ..exceptions import source_exceptions from ..exceptions import source_exceptions
def git_clone(repo_url, branch='master'): 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 == '': if repo_url == '':
raise source_exceptions.GitLocationException(repo_url) raise source_exceptions.GitLocationException(repo_url)
os.environ['GIT_TERMINAL_PROMPT'] = '0'
_tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp') _tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp')
try: try:
pygit2.clone_repository(repo_url, _tmp_dir, checkout_branch=branch) Repo.clone_from(repo_url, _tmp_dir, **{'branch': branch})
except Exception: except Exception:
raise source_exceptions.GitLocationException(repo_url) raise source_exceptions.GitLocationException(repo_url)

View File

@ -25,17 +25,10 @@ To use the docker containter to develop:
Virtualenv Virtualenv
########## ##########
To use VirtualEnv we will need to add some extra steps To use VirtualEnv:
1. virtualenv venv 1. virtualenv venv
2. source ./venv/bin/activate 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: From the directory of the forked repository:
@ -47,8 +40,8 @@ From the directory of the forked repository:
.. note:: .. note::
this will install the latest libgit2 library so you have to make sure you If building from source, Armada requires that git be installed on
install the same version library with pip ( current version: 0.25.0 ) the system.
Kubernetes Kubernetes
########## ##########

View File

@ -13,9 +13,9 @@ Tiller Exceptions
+------------------------------------+--------------------------------------------------------------------------------------------+ +------------------------------------+--------------------------------------------------------------------------------------------+
| Exception | Error Description | | 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. | | PostUpdateJobDeleteException | An error occurred deleting a job after an update. |
+------------------------------------+--------------------------------------------------------------------------------------------+ +------------------------------------+--------------------------------------------------------------------------------------------+
@ -29,7 +29,7 @@ Tiller Exceptions
+------------------------------------+--------------------------------------------------------------------------------------------+ +------------------------------------+--------------------------------------------------------------------------------------------+
| ReleaseInstallException | A release failed to install. | | 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. | | TillerServicesUnavailableException | Occurs when Tiller services are unavailable. |
+------------------------------------+--------------------------------------------------------------------------------------------+ +------------------------------------+--------------------------------------------------------------------------------------------+
@ -79,9 +79,9 @@ Lint Exceptions
+----------------------------------+------------------------------+ +----------------------------------+------------------------------+
| InvalidChartNameException | Chart name invalid. | | InvalidChartNameException | Chart name invalid. |
+----------------------------------+------------------------------+ +----------------------------------+------------------------------+
| InvalidChartDefinitionException | Chart definition invalid. | | InvalidChartDefinitionException | Chart definition invalid. |
+----------------------------------+------------------------------+ +----------------------------------+------------------------------+
| InvalidReleaseException | Release 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 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 3. Check that tiller is Available
.. code:: bash .. code:: bash
docker exec armada armada tiller --status docker exec armada armada tiller --status
4. If tiller is up then we can start deploying our armada yamls 4. If tiller is up then we can start deploying our armada yamls
.. code:: bash .. code:: bash

View File

@ -1,3 +1,4 @@
gitpython==2.1.5
grpc==0.3.post19 grpc==0.3.post19
grpcio==1.1.3 grpcio==1.1.3
grpcio-tools==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= setenv=
PYTHONWARNINGS=all PYTHONWARNINGS=all
[testenv:ubuntu]
commands =
sh {toxinidir}/tools/libgit2.sh
[testenv:docs] [testenv:docs]
commands = python setup.py build_sphinx commands = python setup.py build_sphinx
@ -26,5 +22,5 @@ commands = nosetest -w armada
[flake8] #TODO: Remove E402 [flake8] #TODO: Remove E402
ignore=E302,H306,E402,W503 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