Commit ff99a559 authored by Jon's avatar Jon
Browse files

Merge branch '6-docker-release' into 'development'

Resolve "Docker Release"

See merge request !6
parents 5e3cd9ba ee011f14
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+22 −0
Changes for .dockerignore: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line

# Directories
**/.git
**/.gitlab
bin/
build/
docs/
gitlab_management/
*.egg-info/
include/
lib/
test/


# Files
**/*.md
**/*.py
**/*.pyc
**/*.yml
**/.gitignore
**/pyvenv.cfg
+5 −0
Changes for .gitignore: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
config.yml
*.pyc

#Dont include files generated by buildinit.py
dockerfile
gitlab_management/__init__.py

#Dont include build files
build/
_build/
@@ -11,6 +15,7 @@ dist/
bin/
lib/
include/
pyvenv.cfg


#Don't include the autogenerated Module docs
+138 −30
Changes for .gitlab-ci.yml: 138 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@


stages:
    - package
    - build
    - test
    - validate
@@ -10,72 +11,175 @@ stages:
    - publish


Create_Package:
    stage: build
gitlab-management_package:
    stage: package
    image: python:3.6.9-slim
    variables:
        GIT_PYTHON_GIT_EXECUTABLE: /bin/git
    before_script:
        - apt-get update && apt-get install -y --no-install-recommends git
        - git --version
        - GIT_PYTHON_GIT_EXECUTABLE=$(which git)
        - echo $GIT_PYTHON_GIT_EXECUTABLE
        - echo $PATH
        - PATH=$PATH:$GIT_PYTHON_GIT_EXECUTABLE
        - python3 -m pip install --user --upgrade setuptools wheel
        - python3 -m pip install -r requirements.txt
    script:
        - python3 setup.py sdist bdist_wheel
        - echo $(python3 -B ./GetVersion.py) > dist/version
        - python3 setup.py egg_info sdist bdist_wheel
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH == "master"'
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - setup.py
          - README.md
          - CONTRIBUTING.md
          when: always
    artifacts:
        expire_in: 3 days
        when: on_success
        paths:
            - dist/*
            - gitlab_management/__init__.py
            - dockerfile


Create_Pre-Release-Package:
Docker_Build-Alpine:
    stage: build
    image: python:3.6.9-slim
    image: docker:latest
    services:
        - docker:19.03.11-dind
    before_script:
        - python3 -m pip install --user --upgrade setuptools wheel
        - docker info
        - docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD  
    script:
        - Tag_Build=.rc$(date +%y%m%d%H%M)
        - python3 setup.py egg_info --tag-build=$Tag_Build sdist bdist_wheel
        - echo $(python3 -B ./GetVersion.py)$Tag_Build > dist/version
        - docker build . --no-cache --tag $CI_REGISTRY_IMAGE/gitlab-management:$CI_COMMIT_SHA
    after_script:
        - docker push $CI_REGISTRY_IMAGE/gitlab-management:$CI_COMMIT_SHA
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH == "master"'
          when: never
        - if: '$CI_COMMIT_BRANCH != "master"'
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - setup.py
          - README.md
          - CONTRIBUTING.md
          when: always
    artifacts:
        expire_in: 3 days
          when: on_success
        paths:
            - dist/*
    dependencies:
        - gitlab-management_package
    tags:
        - docker


include:
  - template: Dependency-Scanning.gitlab-ci.yml
  - template: Container-Scanning.gitlab-ci.yml
  - template: License-Scanning.gitlab-ci.yml
  - template: SAST.gitlab-ci.yml


variables:
    SAST_DEFAULT_ANALYZERS: "bandit"

# to activate security MR approvals: https://docs.gitlab.com/ee/user/application_security/index.html#enabling-security-approvals-within-a-project
bandit-sast:
    dependencies:
        - gitlab-management_package
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: $CI_COMMIT_BRANCH
          changes:
          - gitlab_management/*.py
          - setup.py
          when: on_success
          allow_failure: false


Scan gitlab-management-Alpine:
    extends: container_scanning
    variables:
        CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/gitlab-management
    dependencies:
        - gitlab-management_package
        - Docker_Build-Alpine
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: $CI_COMMIT_BRANCH
          changes:
          - gitlab_management/*.py
          - setup.py
          when: on_success
          allow_failure: false


container_scanning:
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: $CI_COMMIT_BRANCH
          when: never

          
gemnasium-python-dependency_scanning:
    variables:
        DS_PYTHON_VERSION: 3
        PIP_REQUIREMENTS_FILE: requirements.txt
    dependencies:
        - gitlab-management_package
        - Docker_Build-Alpine
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: $CI_COMMIT_BRANCH
          changes:
          - gitlab_management/*.py
          - setup.py
          when: on_success
          allow_failure: false

# to activate licence approvals: https://docs.gitlab.com/ee/user/application_security/#enabling-license-approvals-within-a-project
license_scanning:
    variables:
        LM_PYTHON_VERSION: 3
    dependencies:
        - gitlab-management_package
        - Docker_Build-Alpine
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: $CI_COMMIT_BRANCH
          changes:
          - gitlab_management/*.py
          - setup.py
          when: on_success
          allow_failure: false

Documentation:
  stage: validate
  image: readthedocs/build:latest
  script:
    - bash $CI_PROJECT_DIR/test/validation-build-docs.sh
  dependencies:
    - gitlab-management_package
  rules:
    - if: $CI_COMMIT_TAG
      when: never
@@ -90,7 +194,7 @@ Documentation:
      - docs/*
      - README.md
      - CONTRIBUTING.md
      when: always
      when: on_success



@@ -117,17 +221,18 @@ GitLab-Release:
    script:
        - Release_TAG=$(cat $CI_PROJECT_DIR/dist/version)
        - *ReleaseScript
    #dependencies:
    #    - Create_Package
    dependencies:
        - gitlab-management_package
        - Docker_Build-Alpine
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH == "master"'
          when: always
          when: on_success
        - if: '$CI_COMMIT_BRANCH == "development"'
          when: always
          when: on_success
          allow_failure: false
        - if: '$CI_COMMIT_BRANCH != "master"'
          when: never
@@ -143,8 +248,9 @@ Test_Publish:
    script:
        - rm $CI_PROJECT_DIR/dist/version
        - python3 -m twine upload --verbose --username __token__ --password $NFC_TOKEN_TESTPYPI --repository testpypi dist/*
#    dependencies:
#        - Create_Package
    dependencies:
        - gitlab-management_package
        - Docker_Build-Alpine
    rules:
        - if: $CI_COMMIT_TAG
          when: never
@@ -172,14 +278,16 @@ Publish:
    script:
        - rm $CI_PROJECT_DIR/dist/version
        - python3 -m twine upload --verbose --username __token__ --password $NFC_TOKEN_PYPI dist/*
    #dependencies:
    #    - GitLab-Release
    dependencies:
        - gitlab-management_package
        - Docker_Build-Alpine
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH == "master"'
          when: always
          when: on_success
        - if: '$CI_COMMIT_BRANCH == "development"'
          when: always
          when: manual
          allow_failure: true
+29 −6
Changes for CONTRIBUTING.md: 29 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ our development workflow is designed to be easy to setup. For this to occur, the

## Module

Setup the environment to use the local module baing developed. 
Setup the environment to use the local module being developed. 

>**Note:** all commands run from the root of the repository directory.

@@ -27,18 +27,34 @@ bin/python -m pip install --upgrade --no-cache-dir pip
bin/python -m pip install --upgrade --no-cache-dir -r requirements.txt

bin/python setup.py develop install

python3 ./buildinit.py
```

test the module being developed
``` bash
bin/python -B -m gitlab_management -h
bin/gitlab_management -h
```

Clean-up the environment
``` bash
rm -Rf bin dist gitlab_management.egg-info lib include
rm -Rf build bin docs/_build gitlab_management.egg-info lib include pyvenv.cfg
```

>**Note:** you must increment the version in the build script (`buildinit.py`) prior to committing your final changes to the repo.

### Version Changes
Every change, prior to being committed to the `development` branch, must have it's version incremented. In most cases only the `{newfeature}` number will need to be incremented.

if the version is less than `1.0.0` the version number layout is `0.{newfeature}.{bugfix}`

if the version number is more than `1.0.0` the version number layout is `{majorchange}.{newfeature}.{bugfix}`.  
`{majorchange}` should only be incremented if the end user would be required to make a manual adjustments to use the version.

To adjust the version, open `buildinit.py` and edit the `__version__` property at the top of the script.

Regardless of the version until the changes are pushed to the `development` branch, it will be adjusted to be a release candidate. the appended version information will be `.rc` with a formated date i.e. `.rcYYMMDDHHMMSS`.

## Documentation
We use Sphinx for ducumentation. All documentation for the project lives in the `docs/` directory within the repo. Documentation can be written in either RestructureText `.rst` or MarkDown `.md` files. Documentation for the modules however, is written within the code using `NumPy` style `DocBook` code comments. These comments are then rendered to `.rst` via the `sphinx.ext.autodoc` extension.

@@ -136,11 +152,18 @@ Buiding of the docs is part of the *validation* stage of the build pipeline. The
Please build the docs locally before pushing to the repo, this will ensure that they are working befor being committed. After a local build the docs can be found in the repository directory under `docs/_build/html/index.html`


Clean-up the environment prior to building the documentation, with:
``` bash
rm -Rf build bin docs/_build gitlab_management.egg-info lib include pyvenv.cfg
```

To build the documentation run:
``` bash
cd {Repo Directory}
docker run -e CI_PROJECT_DIR=/Repository -w /Repository -v $PWD:/Repository readthedocs/build:latest bash test/validation-build-docs.sh
CI_PROJECT_DIR=/Repository && docker run -e CI_PROJECT_DIR=$CI_PROJECT_DIR -w $CI_PROJECT_DIR -v $PWD:$CI_PROJECT_DIR readthedocs/build:latest bash test/validation-build-docs.sh
```

>**.. Note::**
Substitute `{Repo Directory}` with the actual directory the repository was cloned to. However, you can also miss the `cd` command and adjust `$PWD` to be the `{Repo Directory}`.

>**Tip:**
The above command contains the setting of the environmental variable `CI_PROJECT_DIR`, this is the directory where the repository is to be mounted to within the container. *don't include a trailing `/` slash if you change this.* The variable `$PWD` is to mount the current directory, if you are not running this command from the repo root dir, please set this to the full path of the repo.

GetVersion.py

deleted100644 → 0
+0 −7
Changes for GetVersion.py: 0 added lines, 7 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

with open("gitlab_management/base.py") as f:
    for line in f:
        if line.startswith("__version__"):
            print(eval(line.split("=")[-1]))
 No newline at end of file
Loading