https://github.com/hansehe/DockerBuildSystem
A simple library for handling docker commands with python.
https://github.com/hansehe/DockerBuildSystem
buildsystem docker python yml-files
Last synced: 4 months ago
JSON representation
A simple library for handling docker commands with python.
- Host: GitHub
- URL: https://github.com/hansehe/DockerBuildSystem
- Owner: hansehe
- License: mit
- Fork: true (DIPSAS/DockerBuildSystem)
- Created: 2021-09-22T23:40:26.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-02T16:17:54.000Z (9 months ago)
- Last Synced: 2024-11-16T07:47:21.965Z (5 months ago)
- Topics: buildsystem, docker, python, yml-files
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - hansehe/DockerBuildSystem - A simple library for handling docker commands with python. (Python)
README
# Docker Build System
[](https://badge.fury.io/py/DockerBuildSystem)
[](https://travis-ci.com/hansehe/DockerBuildSystem)
[](http://opensource.org/licenses/MIT)A simple library for handling docker commands with python.
## Install Or Upgrade
- pip install --upgrade DockerBuildSystem## Example
- Include DockerBuildSystem tools:
```python
from DockerBuildSystem import DockerComposeTools, DockerImageTools, DockerSwarmTools, TerminalTools, VersionTools
```- Merge, build and run docker-compose.*.yml files:
```python
composeFiles = [
'docker-compose.yml',
'docker-compose.build.yml',
'docker-compose.override.yml'
]
mergedComposeFile = "docker-compose.generated.dev.yml"
DockerComposeTools.MergeComposeFiles(composeFiles, mergedComposeFile)
DockerComposeTools.DockerComposeBuild([mergedComposeFile])
DockerComposeTools.DockerComposeUp([mergedComposeFile])
```- Push and pull images in docker-compose.*.yml files, including additional `latest` tag:
```python
composeFiles = [
'docker-compose.yml'
]
DockerComposeTools.DockerComposePush(composeFiles)
DockerComposeTools.PublishDockerImagesWithNewTag(composeFiles, 'latest')
DockerComposeTools.DockerComposePull(composeFiles)
```- Execute test projects in Docker containers and raise exception if container exits with error code due to failing tests:
```python
composeFiles = [
'docker-compose.tests.yml'
]
testContainerNames = [
'lab-services-tests'
]
DockerComposeTools.ExecuteComposeTests(composeFiles, testContainerNames)
```- Load set of specific environment variables from a `*.env` file:
```python
TerminalTools.LoadEnvironmentVariables('path_to/variables.env')
```- Export top-most version from CHANGELOG.md file (see the example folder) as an environment variable:
```python
VersionTools.ExportVersionFromChangelogToEnvironment("path_to/CHANGELOG.md", "version")
```
- Optionally export versionmajor and versionminor based on the top-most version from CHANGELOG.md file as an environment variable:
```python
VersionTools.ExportVersionFromChangelogToEnvironment("path_to/CHANGELOG.md", "version", "versionmajor", "versionminor")
```- to use the DockerComposeTools.PromoteDockerImages functionality, provide the following parameters:
- composeFile - the compose file containing theimages that should be promoted
- targetTags - the tags you want to use when you push the image to the new feed
- sourceFeed - the feed you want to pull the images from (should match the compose file)
- targetFeed - the feed you want to push to
- user - used for authenticating to sourceFeed and targetFeed
- password - used for authenticating to sourceFeed and targetFeed
- dryRun - boolean. True if you want to do a dryRun, i.e. print what would have happenedPlease have a look at an example of use here:
- https://github.com/hansehe/DockerBuildSystem/tree/master/example## Prerequisites
- Docker:
- https://www.docker.com/get-docker
- Install Dependencies:
- pip install -r requirements.txt## Additional Info
- The pip package may be located at:
- https://pypi.org/project/DockerBuildSystem## Publish New Version.
1. Configure setup.py with new version.
2. Install build tools: `pip install twine wheel`
3. Build: python setup.py bdist_wheel
4. Check: twine check dist/*
5. Publish: twine upload dist/*## Test a new version locally
1. Build: python setup.py bdist_wheel
2. Install from local file with force-reinstall and no-cache-dir options to force reinstallation when you have changed the code without changing the version number: `python -m pip install path\to\yourgitrepo\DockerBuildSystem\dist\DockerBuildSystem-1.1.43-py2.py3-none-any.whl --force-reinstall --no-cache-dir`## Run Unit Tests
- python -m unittest discover -p *Test*.py