Skip to content

Commit

Permalink
Deploy v4.0.0 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 authored Sep 28, 2022
1 parent 7086726 commit 55775ee
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 436 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv/
.github/
.mypy_cache/
build/
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- name: Build and push the image
uses: docker/build-push-action@v2.2.1
with:
file: "./deploy/docker/Dockerfile"
tags: |
certpl/deploy:${{ github.sha }}
certpl/deploy:${{ github.event.release.tag_name }}
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: CERT-Polska/lint-python-action@v1
- uses: CERT-Polska/lint-python-action@v2
with:
source: src/
use-mypy: false
install-requirements: false
install-requirements: 'false'
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Then you can use `deploy build` to build your Docker image. Your image will be t

```
$ deploy build
[INFO] Building image certpl/fancy-service:a2f3d45a4ccfcee03a8a3941ec7177e394626cf2
[INFO] Building image for fancy-service
[INFO] Building certpl/fancy-service:cb85eb9d38c407e462a6681351dfd36331635329
```

If you want to provide alternative version tag, use `--version`. You can provide any tag you want, but few of them are special:
Expand All @@ -41,8 +42,10 @@ Use `deploy push` if you want to push (and build) image to Docker Registry or Do

```
$ deploy push
[INFO] Building image certpl/fancy-service:a2f3d45a4ccfcee03a8a3941ec7177e394626cf2
[INFO] Pushing image certpl/fancy-service:a2f3d45a4ccfcee03a8a3941ec7177e394626cf2
[INFO] Building image for fancy-service
[INFO] Building certpl/fancy-service:cb85eb9d38c407e462a6681351dfd36331635329
[INFO] Pushing image for fancy-service
[INFO] Pushing certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
```

### Make your k8s deployment deploy-enabled
Expand Down Expand Up @@ -75,6 +78,9 @@ A complete example of a `deploy.json` file is presented below:
}
```

Starting from v4.0.0 you can provide `cronjob` instead of `deployment`. `init-container` is also supported if it uses
the same image.

> It's recommended to place your Kubernetes configuration files in the `deploy/k8s` and `deploy/k8s-staging` subdirectories.
This enables you to use `deploy staging` and `deploy production` commands.
Expand All @@ -86,23 +92,26 @@ to new version.

```
$ deploy production
[INFO] Building image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
[INFO] Pushing image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
[INFO] Tagging image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7 as certpl/fancy-service:master
[INFO] Tagging image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7 as certpl/fancy-service:latest
[INFO] Setting image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7 for k8s environment
[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:latest
```

If you don't want to rebuild your Docker images and need just to pull them from the Docker Registry, you can use
`deploy pull` and `deploy production --deploy-only` switch

```
$ docker pull
[INFO] Pulling image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
[INFO] Pulling image for fancy-service
[INFO] Pulling certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7
$ deploy production --deploy-only
[INFO] Tagging image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7 as certpl/fancy-service:master
[INFO] Tagging image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7 as certpl/fancy-service:latest
[INFO] Setting image certpl/fancy-service:7f6dd7010dba1ffdaeb32875e0f71c30c9810df7 for k8s environment
[INFO] Deploying image to k8s
[INFO] Tagging certpl/fancy-service:e12840da50a9426b36de7c0be6dc553cde9923e8 as certpl/fancy-service::latest
[INFO] Pushing certpl/fancy-service:latest
```

### Support for multiple services
Expand All @@ -127,7 +136,7 @@ Deploy will build, push and deploy them all (unless you explicitly select servic
You can automate all these steps with CI/CD. Example `.gitlab-ci.yml` file is presented below:

```yaml
image: certpl/deploy
image: certpl/deploy:v4.0.0

services:
- docker:dind
Expand Down
7 changes: 4 additions & 3 deletions deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM docker:stable
RUN apk update \
&& apk add python3 curl openssh-client git openssl bash python-dev libffi-dev openssl-dev gcc libc-dev make py-pip \
&& apk add python3 curl openssh-client git openssl bash python3-dev libffi-dev openssl-dev gcc libc-dev make py-pip \
&& curl -L https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
&& curl -SL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/kubectl \
&& pip install docker-compose
&& chmod +x /usr/local/bin/docker-compose

COPY . /app/deploy

RUN cd /app/deploy \
&& python3 setup.py install
&& pip install . \
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88

[tool.lint-python]
lint-version = "2"
source = "src/"
extra-requirements = "types-PyYAML"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name="python-deploy",
version="3.0.2",
version="4.0.0",
author="msm, psrok1",
author_email="info@cert.pl",
description="Build, push and deploy k8s services with single "
Expand All @@ -17,6 +17,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=requirements,
python_requires=">=3.8",
package_dir={"deploy": "src"},
url="https://github.com/CERT-Polska/python-deploy",
packages=["deploy"],
Expand Down
24 changes: 2 additions & 22 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
#!/usr/bin/python3

from .deploy import (
build_image,
get_current_git_hash,
get_current_image,
is_clean_repo,
main,
pull_image,
push_image,
set_current_image,
tag_docker_image,
)
from .deploy import Deploy, load_deploy_json, main

__all__ = [
"main",
"get_current_image",
"set_current_image",
"push_image",
"pull_image",
"is_clean_repo",
"get_current_git_hash",
"tag_docker_image",
"build_image",
]
__all__ = ["main", "Deploy", "load_deploy_json"]
3 changes: 3 additions & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .deploy import main

main()
Loading

0 comments on commit 55775ee

Please sign in to comment.