Commit bfef2bbc authored by BorjaEst's avatar BorjaEst
Browse files

Merge template 'python'

# Conflicts:
#	Jenkinsfile
parents 6d89ee56 25abf02d
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
\ No newline at end of file
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
\ No newline at end of file
# Dockerfile has three Arguments: base, tag, branch
# base - base image (default: debian)
# base - base image (default: python)
# tag - tag for base mage (default: stable-slim)
# branch - user repository branch to clone (default: master)
# branch - user repository branch to clone (default: python)
#
# To build the image:
# $ docker build -t <dockerhub_user>/<dockerhub_repo> --build-arg arg=value .
# or using default args:
# $ docker build -t <dockerhub_user>/<dockerhub_repo> .
# set the base image. default is debian, optional ubuntu
ARG base=debian
# set the tag (e.g. latest, stable, stable-slim : for debian)
ARG tag=stable-slim
# set the base image. default is python
ARG base=python
# set the tag (e.g. latest, 3.8, 3.7 : for python)
ARG tag=3.8-slim
# Base image, e.g. debian:stable-slim
# Base image, e.g. python:3.8-slim
FROM ${base}:${tag}
LABEL maintainer='Borja Esteban'
# What branch to clone (!)
ARG branch=master
ARG branch=python
# Which user and group to use
ARG user=application
......@@ -42,6 +42,10 @@ ENV DEBIAN_FRONTEND=dialog
# Install user app:
RUN git clone --depth 1 -b ${branch} https://github.com/BorjaEst/cicd.git app && \
# Install python application
cd app && \
pip3 install --no-cache-dir -e . && \
pip3 install --no-cache-dir tox && \
# Clean up
rm -rf /root/.cache/pip/* && \
rm -rf /tmp/*
......@@ -58,6 +62,6 @@ RUN groupadd -r ${group} && \
USER ${user}
# Start default script
ENTRYPOINT [ "/app/main" ]
CMD [ "" ]
ENTRYPOINT [ "main" ]
CMD [ "-v 1" ]
......@@ -14,13 +14,13 @@ pipeline {
stage('Unit testing') {
steps {
echo '====================executing unittest================================'
script { customImage.inside("--entrypoint=''") {} }
script { customImage.inside("--entrypoint=''") {sh 'tox'} }
}
}
stage('Docker-hub upload') {
steps {
echo '====================uploading docker-hub=============================='
script { docker.withRegistry('', registryCredential) { customImage.push('master') } }
script { docker.withRegistry('', registryCredential) { customImage.push('python') } }
}
}
}
......
......@@ -61,9 +61,28 @@ until finished
End with an example of getting some data out of the system or using it for a little demo.
Installation is done using
[Setuptools](https://setuptools.readthedocs.io/en/latest/setuptools.html#)
package:
- For installation from sources: `setup.py install`
- For simple installation: `pip install {name}`
## 🔧 Running the tests <a name = "tests"></a>
Explain how to run the automated tests for this system.
Tests run using
[tox](https://tox.readthedocs.io/en/latest/)
package and
[pytest](https://docs.pytest.org/en/stable/)
```sh
$ tox
...
py37: commands succeeded
py38: commands succeeded
```
### Break down into end to end tests
Explain what these tests test and why
......
"""Python module template."""
def hello_world(*arg, **kvarg):
print("Hello World")
if arg or kvarg:
print(f" - Arguments as Inputs: {arg}")
print(f" - Arguments as KeyVal: {kvarg}")
return True
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
#
# Main application script template
#
#!/usr/bin/env python3
"""
Main function description - To show in command help
"""
import sys
import argparse
echo "Hello World!"
from cicd import module_template
def cmdline_args():
p = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument("non_required_int", nargs='?', type=int,
help="non_required_int description")
p.add_argument("-v", "--verbosity", type=int, choices=[0, 1, 2], default=0,
help="increase output verbosity (default: %(default)s)")
group1 = p.add_mutually_exclusive_group(required=False)
group1.add_argument('--enable', action="store_true")
group1.add_argument('--disable', action="store_false")
return(p.parse_args())
if __name__ == '__main__':
args = cmdline_args()
module_template.hello_world(args, **vars(args))
[metadata]
name = cicd
version = 0.1.0
description = My package description
description-file = README.md
author = Borja Esteban
author_email = my_email@outlook.com
classifiers =
License :: TBD-setup.cfg
Programming Language :: Python :: 3.8
[options]
packages = find:
scripts =
main
[options.entry_points]
console_scripts =
hello_world = cicd.module_template:hello_world
#!/usr/bin/env python
"""The setup script."""
from setuptools import setup, find_packages
setup()
"""Unit test package for torch_cd_example."""
"""Unittest module template."""
import unittest
from cicd import module_template
class TestCICD_module_template(unittest.TestCase):
"""Tests for `module_template` package."""
def setUp(self):
"""Set up test fixtures, if any."""
def tearDown(self):
"""Tear down test fixtures, if any."""
def test_000_something(self):
"""Test something."""
self.assertTrue(module_template.hello_world())
self.assertFalse(False)
# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py38
[testenv]
deps =
pytest
commands =
pytest
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment