Package: python-deploy
deployBuild, push and deploy k8s services with single deploy.json file to provide common convention for
multiple production services.pip install python-deployMake your Docker setup deploy-enabledFirst of all, create a file underdeploy/deploy.jsonpath pointing at your Dockerfile.It's recommended to place your Dockerfile in adeploy/dockersubdirectory.{"fancy-service":{"docker":{"image":"certpl/fancy-service","dockerfile":"deploy/docker/Dockerfile","dir":"."}}}Then you can usedeploy buildto build your Docker image. Your image will be tagged using Git commit hash.$ deploy build
[INFO] Building image for fancy-service
[INFO] Building certpl/fancy-service:cb85eb9d38c407e462a6681351dfd36331635329If you want to provide alternative version tag, use--version. You can provide any tag you want, but few of them are special:dateuses current timestamp (e.g.v20200302170007)commitis defaultother strings are used "as is"Usedeploy pushif you want to push (and build) image to Docker Registry or Docker Hub with all provided tags:$ deploy push
[INFO] Building image for fancy-service
[INFO] Building certpl/fancy-service:cb85eb9d38c407e462a6681351dfd36331635329
[INFO] Pushing image for fancy-service
[INFO] Pushing certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7Make your k8s deployment deploy-enabledEnhance yourdeploy/deploy.jsonwith configuration of k8s deployment.Deploy supports two environments:k8s(production) andk8s-staging(staging).A complete example of adeploy.jsonfile is presented below:{
    "fancy-service": {
        "docker": {
            "image": "certpl/fancy-service",
            "dockerfile": "deploy/docker/Dockerfile",
            "dir": "."
        },
        "k8s": {
            "namespace": "service-prod",
            "deployment": "deployment-fancy-service",
            "container": "container-fancy-service"
        },
        "k8s-staging": {
            "namespace": "service-st",
            "deployment": "deployment-fancy-service",
            "container": "container-fancy-service"
        }
    }
}Starting from v4.0.0 you can providecronjobinstead ofdeployment.init-containeris also supported if it uses
the same image.It's recommended to place your Kubernetes configuration files in thedeploy/k8sanddeploy/k8s-stagingsubdirectories.This enables you to usedeploy staginganddeploy productioncommands.deploy stagingbuilds and pushes Docker image with version tag andlatesttag. After all, updates the image name used by staging container
to new version.deploy productiondoes the same thing, but images are additionally tagged  asmaster. Then it updates the production container.$ deploy production
[INFO] Building image for fancy-service
[INFO] Building certpl/fancy-service:cb85eb9d38c407e462a6681351dfd36331635329
[INFO] Pushing image for fancy-service
[INFO] Pushing certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
[INFO] Deploying image to k8s
[INFO] Tagging certpl/fancy-service:e12840da50a9426b36de7c0be6dc553cde9923e8 as certpl/fancy-service::latest
[INFO] Pushing certpl/fancy-service:latestIf you don't want to rebuild your Docker images and need just to pull them from the Docker Registry, you can usedeploy pullanddeploy production --deploy-onlyswitch$ docker pull
[INFO] Pulling image for fancy-service
[INFO] Pulling certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
$ deploy production --deploy-only
[INFO] Deploying image to k8s
[INFO] Tagging certpl/fancy-service:e12840da50a9426b36de7c0be6dc553cde9923e8 as certpl/fancy-service::latest
[INFO] Pushing certpl/fancy-service:latestSupport for multiple servicesIf your app is built using multiple containers, just specify more services as top-level keys ofdeploy.json.{"fancy-service":{...},"fancy-service-web":{...}}Deploy will build, push and deploy them all (unless you explicitly select services using--service/-soption).Make your Gitlab CI deploy-enabledYou can automate all these steps with CI/CD. Example.gitlab-ci.ymlfile is presented below:image:certpl/deploy:v4.0.0services:-docker:dindstages:-build-test-deploybuild:stage:buildscript:-git submodule init-git submodule update --recursive# Build and push images to Docker Registry-deploy pushtest:stage:testscript:# Pull images and run unit tests-deploy pull-deploy run -- python -m unittest discoverdeploy:stage:deployonly:-masterscript:# Set default token, pull images and deploy them-kubernetes_use_token https://kapi.example.com "$KUBE_TOKEN"-deploy pull-deploy production --deploy-onlyIf you don't have tests and you just want to build and deploy everything in one step: invokedeploy productionFull usageKeep in mind that some optional arguments are only relevant for some commandsusage: deploy [-h] {build,push,pull,staging,production,image,run} ...

Deploy the application.

positional arguments:
  {build,push,pull,staging,production,image,run}
                        Deploy commands
    build               Only build images
    push                Build and push images
    pull                Pull images from registry
    staging             Build, push and deploy images to the staging
                        environment
    production          Build, push and deploy images to the PRODUCTION
                        environment
    image               Show image names
    run                 Run interactive command for service images

optional arguments:
  -h, --help            show this help message and exit

  --tag TAG, -t TAG     Alternative tags for image
  --no-cache            Pass --no-cache to docker build
  --service SERVICE, -s SERVICE
                        Specify services to perform action (default: all)
  --force, -f           Don't perform check-ups, force deploy (not
                        recommended)
  --verbose, -v         Print spawned subcommands and their outputs
  --version {commit,date,latest}
                        Alternative version tag