Skip to content

Commit cbdb3ec

Browse files
authored
Move Opstool to python 3 (#61)
* Move Opstool to python 3 print unicode fixes Signed-off-by: costimuraru <[email protected]> fix inventory sorting Signed-off-by: costimuraru <[email protected]> publish Signed-off-by: costimuraru <[email protected]> Use python3 docker image Signed-off-by: costimuraru <[email protected]> Add patch version test Signed-off-by: costimuraru <[email protected]> Add patch version [RELEASE] - Release version 1.9.3 Fix travia Fix Signed-off-by: costimuraru <[email protected]> Python3 fixes Fix tests for python3 Fix version check Signed-off-by: costimuraru <[email protected]> [RELEASE] - Release version 1.9.4 Upgrade ops-cli Use six for python3 compat check Implement feedback Show docker build command Signed-off-by: costimuraru <[email protected]> * Implement feedback Signed-off-by: costimuraru <[email protected]>
1 parent 19b3b78 commit cbdb3ec

38 files changed

+215
-141
lines changed

.bumpversion.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[bumpversion]
2-
current_version = 1.9
2+
current_version = 1.9.4
33
commit = True
44
tag = True
55
tag_name = {new_version}
66
message = [RELEASE] - Release version {new_version}
7-
parse = (?P<major>\d+)\.(?P<minor>\d+)
7+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
88
serialize =
9-
{major}.{minor}
9+
{major}.{minor}.{patch}
1010

1111
[bumpversion:file:setup.py]
1212

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@ services:
55
branches:
66
only:
77
- master
8-
- python3
98
- /\d+\.\d+/
9+
- /\d+\.\d+\.\d+/
10+
1011
env:
1112
- BOTO_CONFIG=/dev/null
12-
python:
13-
- '2.7'
13+
1414
script:
1515
# build
1616
- bash build_scripts/freeze_requirements.sh
1717
- bash build_scripts/build_package.sh
1818
# dry run
1919
- pip install --no-cache-dir dist/ops*.tar.gz && ops --verbose -h
20+
21+
# Output something every 5 minutes or Travis kills the job
22+
- while sleep 5m; do echo "=====[ $SECONDS seconds still running ]====="; done &
2023
# build docker image
21-
- travis_wait 30 docker build -f build_scripts/Dockerfile -t ops .
24+
- docker build -f build_scripts/Dockerfile -t ops .
25+
# Killing background sleep loop
26+
- kill %1
27+
2228
deploy:
2329
matrix:
2430
- provider: releases

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,34 @@ Here is a link about how to install and use virtualenv:
7676
https://virtualenv.pypa.io/en/stable/
7777

7878
### Ops tool installation
79+
80+
#### Python 3
7981
```sh
80-
# Ops tool works on python2 only at the moment.
82+
# Make sure pip is up to date
83+
curl https://bootstrap.pypa.io/get-pip.py | python3
84+
85+
# Install virtualenv
86+
pip install --upgrade virtualenv
87+
pip install --upgrade virtualenvwrapper
88+
89+
echo 'export WORKON_HOME=$HOME/.virtualenvs' >> ~/.bash_profile
90+
echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile
91+
source ~/.bash_profile
92+
93+
# create virtualenv
94+
mkvirtualenv ops
95+
workon ops
96+
97+
# uninstall previous `ops` version (if you have it)
98+
pip uninstall ops --yes
8199

82-
# Make sure pip is up to date (min version: 9.0.3)
100+
# install ops-cli v1.9.4 stable release
101+
pip install --upgrade ops-cli
102+
```
103+
104+
#### Python 2
105+
```sh
106+
# Make sure pip is up to date
83107
curl https://bootstrap.pypa.io/2.6/get-pip.py | python2
84108

85109
# Install virtualenv
@@ -89,21 +113,26 @@ pip2 install -U virtualenv
89113
virtualenv ops
90114
source ops/bin/activate
91115

92-
# install opswrapper v1.9 stable release
93-
pip2 install --upgrade https://github.com/adobe/ops-cli/releases/download/1.9/ops-1.9.tar.gz
116+
# uninstall previous `ops` version (if you have it)
117+
pip uninstall ops --yes
94118

95-
# Optionally, install terraform to be able to access terraform plugin
96-
# See https://www.terraform.io/intro/getting-started/install.html
97-
# Also for pretty formatting of terraform plan output you can install https://github.com/coinbase/terraform-landscape (use gem install for MacOS)
119+
# install ops-cli v1.9.4 stable release
120+
pip2 install --upgrade ops-cli
98121
```
99122

123+
124+
### Terraform
125+
Optionally, install terraform to be able to access terraform plugin. See https://www.terraform.io/intro/getting-started/install.html
126+
Also for pretty formatting of terraform plan output you can install https://github.com/coinbase/terraform-landscape (use gem install for MacOS)
127+
128+
100129
## Using docker image
101130

102131
You can try out `ops-cli`, by using docker. The docker image has all required prerequisites (python, terraform, helm, git, ops-cli etc).
103132

104133
To start out a container, running the latest `ops-cli` docker image run:
105134
```sh
106-
docker run -it adobe/ops-cli:1.9 bash
135+
docker run -it adobe/ops-cli:1.9.4 bash
107136
```
108137

109138
After the container has started, you can start using `ops-cli`:

build_scripts/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:2.7.16-alpine3.9 AS compile-image
1+
FROM python:3.7-alpine3.10 AS compile-image
22
ARG TERRAFORM_VERSION="0.12.6"
33
ARG AZURE_CLI_VERSION="2.0.67"
44

@@ -22,7 +22,7 @@ RUN bash build_scripts/build_package.sh
2222
RUN apk del --purge build
2323

2424

25-
FROM python:2.7.16-alpine3.9
25+
FROM python:3.7-alpine3.10
2626
ARG TERRAFORM_VERSION="0.12.6"
2727
ARG VAULT_VERSION="1.1.3"
2828
ARG KUBECTL_VERSION="v1.13.7"
@@ -59,7 +59,7 @@ RUN adduser ops -Du 2342 -h /home/ops \
5959
&& wget -q https://github.com/roboll/helmfile/releases/download/${HELM_FILE_VERSION}/helmfile_linux_amd64 -O /usr/local/bin/helmfile \
6060
&& chmod +x /usr/local/bin/helmfile
6161
# Fix https://github.com/kubernetes-client/python-base/pull/126/files
62-
COPY build_scripts/patches/kube_config.py /usr/local/lib/python2.7/site-packages/kubernetes/config/kube_config.py
62+
COPY build_scripts/patches/kube_config.py /usr/local/lib/python3.7/site-packages/kubernetes/config/kube_config.py
6363

6464
# install utils under `ops` user
6565
USER ops

build_scripts/docker_push.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
set -e
33

44
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
5-
docker tag ops adobe/ops-cli:1.9
6-
docker push adobe/ops-cli:1.9
5+
docker tag ops adobe/ops-cli:1.9.4
6+
docker push adobe/ops-cli:1.9.4

build_scripts/freeze_requirements.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -e
33

44
echo "Freezing requirements.txt"
55
pip install pipenv
6+
67
rm -rf Pipfile* deps
7-
pipenv lock --clear --two --requirements 1>deps
8+
pipenv lock --clear --three --requirements 1>deps
89
grep '==' deps | sed "s/;\\sextra.*//" > requirements.txt

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ hvac==0.9.3
1414
passgen
1515
inflection==0.3.1
1616
kubernetes==9.0.0
17-
himl==0.1.18
17+
himl==0.2.1
18+
six

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
_requires = [ r for r in open(os.path.sep.join((_mydir,'requirements.txt')), "r").read().split('\n') if len(r)>1 ]
2424
setup(
2525
name='ops-cli',
26-
version='1.9',
26+
version='1.9.4',
2727
description='Ops - wrapper for Terraform, Ansible, and SSH for cloud automation',
2828
long_description=_readme + '\n\n',
2929
long_description_content_type='text/markdown',
@@ -38,9 +38,13 @@
3838
'Intended Audience :: Developers',
3939
'License :: OSI Approved :: Apache Software License',
4040
'Operating System :: OS Independent',
41-
'Programming Language :: Python',
4241
'Programming Language :: Python :: 2',
4342
'Programming Language :: Python :: 2.7',
43+
'Programming Language :: Python :: 3',
44+
'Programming Language :: Python :: 3.4',
45+
'Programming Language :: Python :: 3.5',
46+
'Programming Language :: Python :: 3.6',
47+
'Programming Language :: Python :: 3.7',
4448
'Programming Language :: Python :: Implementation :: CPython',
4549
'Programming Language :: Python :: Implementation :: PyPy',
4650
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',

src/ops/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
import re
1313
from distutils.version import StrictVersion
1414
from subprocess import call, Popen, PIPE
15-
from ops.cli import display
15+
16+
from six import PY3
17+
18+
from .cli import display
1619

1720

1821
def validate_ops_version(min_ops_version):
19-
current_ops_version = [x.version for x in pkg_resources.working_set if x.project_name == "ops"][0]
22+
current_ops_version = [x.version for x in pkg_resources.working_set if x.project_name == "ops-cli"][0]
2023
if StrictVersion(current_ops_version) < StrictVersion(min_ops_version):
2124
raise Exception("The current ops version {0} is lower than the minimum required version {1}. "
2225
"Please upgrade by following the instructions seen here: "
@@ -30,7 +33,7 @@ def __call__(self, result, pass_trough=True, cwd=None):
3033
try:
3134
return self._execute(result, pass_trough, cwd)
3235
except Exception as ex:
33-
display(ex.message, stderr=True, color='red')
36+
display(str(ex) if PY3 else ex.message, stderr=True, color='red')
3437
display('------- TRACEBACK ----------', stderr=True, color='dark gray')
3538
import traceback
3639
traceback.print_exc()
@@ -48,7 +51,7 @@ def _execute(self, result, pass_trough=True, cwd=None):
4851
else:
4952
p = Popen(shell_command, shell=True, stdout=PIPE, stderr=PIPE, cwd=cwd)
5053
output, errors = p.communicate()
51-
display(output)
54+
display(str(output))
5255
if errors:
5356
display("%s" % self.shadow_credentials(errors), stderr=True, color='red')
5457
exit_code = p.returncode

src/ops/ansible/filter_plugins/commonfilters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from __future__ import absolute_import
1212
import os
1313
from ops.cli import display
14+
from six import iteritems
15+
1416

1517
def read_file(fname):
1618
if os.path.exists(fname):
@@ -98,7 +100,7 @@ def write_vault(
98100
namespace=None, mount_point=None, auto_prompt=auto_prompt)
99101
new_data = {}
100102
if isinstance(data, dict):
101-
for k,v in data.iteritems():
103+
for k,v in iteritems(data):
102104
new_data[k] = str(v)
103105
elif key:
104106
new_data[key] = str(data)

0 commit comments

Comments
 (0)