From 22378cf133cb6019d535dd10e89fcf377655636f Mon Sep 17 00:00:00 2001 From: kleph Date: Tue, 25 Feb 2020 01:46:56 +0100 Subject: [PATCH 1/6] [CI] Tag docker image to deploy it --- .drone.yml | 9 +++++++-- kube/beer-deployment.yaml | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6315c91..1bbe67c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -48,7 +48,7 @@ steps: image: plugins/docker settings: repo: kleph/beer - tags: latest + tags: ${DRONE_COMMIT_SHA:0:8} username: from_secret: dockerhub_username password: @@ -71,11 +71,16 @@ steps: from_secret: kubectl_cert kubernetes_token: from_secret: kubectl_token + environment: + IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} commands: + - echo "== pre deploy status:" - kubectl get pods --namespace=beer - kubectl get deployments --namespace=beer - kubectl get svc --namespace=beer - - kubectl apply -f kube/beer-deployment.yaml --namespace=beer + - cat kube/beer-deployment.yaml > kube/beer-deployment-${IMAGE_TAG}.yaml + - kubectl apply -f kube/beer-deployment-${IMAGE_TAG}.yaml --namespace=beer + - echo "== post deploy status:" depends_on: - build diff --git a/kube/beer-deployment.yaml b/kube/beer-deployment.yaml index bf08ebb..83e916d 100644 --- a/kube/beer-deployment.yaml +++ b/kube/beer-deployment.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: beer - image: kleph/beer + image: kleph/beer:${IMAGE_TAG} imagePullPolicy: Always ports: - containerPort: 5000 -- 2.45.2 From 16117618e1d52f7c4878cbf1deb900a3163023ca Mon Sep 17 00:00:00 2001 From: kleph Date: Tue, 25 Feb 2020 02:03:01 +0100 Subject: [PATCH 2/6] [CI] Try to create staging namespace --- .drone.yml | 120 ++++++++++++++++++++++++++------------- kube/beer-namespace.yaml | 4 +- 2 files changed, 81 insertions(+), 43 deletions(-) diff --git a/.drone.yml b/.drone.yml index 1bbe67c..e89f9ab 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,43 +1,43 @@ ---- -kind: pipeline -name: lint - -steps: -- name: yaml lint - image: cytopia/yamllint - commands: - - yamllint . - -- name: docker lint - image: hadolint/hadolint - commands: - - hadolint Dockerfile # ignore pinning version in pip - -- name: w3c validator - image: validator/validator:latest - commands: - - vnu static/*.html - -- name: markdown lint - image: pipelinecomponents/markdownlint:latest - commands: - - mdl --style all --warnings . - ---- -kind: pipeline -name: unit tests - -steps: -- name: unit test - image: python:slim - commands: - - pip install -r requirements.txt - - pip install pylint - - pylint beer/*.py tests/*.py - - python -m pytest tests - -depends_on: -- lint +#--- +#kind: pipeline +#name: lint +# +#steps: +#- name: yaml lint +# image: cytopia/yamllint +# commands: +# - yamllint . +# +#- name: docker lint +# image: hadolint/hadolint +# commands: +# - hadolint Dockerfile # ignore pinning version in pip +# +#- name: w3c validator +# image: validator/validator:latest +# commands: +# - vnu static/*.html +# +#- name: markdown lint +# image: pipelinecomponents/markdownlint:latest +# commands: +# - mdl --style all --warnings . +# +#--- +#kind: pipeline +#name: unit tests +# +#steps: +#- name: unit test +# image: python:slim +# commands: +# - pip install -r requirements.txt +# - pip install pylint +# - pylint beer/*.py tests/*.py +# - python -m pytest tests +# +#depends_on: +#- lint --- kind: pipeline @@ -54,8 +54,42 @@ steps: password: from_secret: dockerhub_password +#depends_on: +#- unit tests + +--- +kind: pipeline +name: deploy + +steps: +- name: deploy + image: sinlead/drone-kubectl + settings: + kubernetes_server: + from_secret: kubectl_uri + kubernetes_cert: + from_secret: kubectl_cert + kubernetes_token: + from_secret: kubectl_token + environment: + IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} + NAMESPACE: beer-staging-${DRONE_COMMIT_SHA:0:4} + commands: + - echo "== create staging namespace ${NAMESPACE}" + - kubectl get svc --namespace=${NAMESPACE} + - cat kube/beer-deployment.yaml > kube/beer-namespace.yaml + - kubectl apply -f kube/beer-namespace.yaml + - echo "== deploy staging" + - cat kube/beer-deployment.yaml > kube/beer-deployment-${IMAGE_TAG}.yaml + - kubectl apply -f kube/beer-deployment-${IMAGE_TAG}.yaml --namespace=beer + depends_on: -- unit tests +- build + +when: + branch: + exclude: + - master --- kind: pipeline @@ -84,3 +118,7 @@ steps: depends_on: - build + +when: + branch: + - master diff --git a/kube/beer-namespace.yaml b/kube/beer-namespace.yaml index 119770a..899e8fa 100644 --- a/kube/beer-namespace.yaml +++ b/kube/beer-namespace.yaml @@ -2,6 +2,6 @@ apiVersion: v1 kind: Namespace metadata: - name: beer + name: ${NAMESPACE} labels: - name: beer + name: ${NAMESPACE} -- 2.45.2 From 43f338ecf3c442216c742ffa66ead7e9ee3d7255 Mon Sep 17 00:00:00 2001 From: kleph Date: Tue, 25 Feb 2020 02:08:18 +0100 Subject: [PATCH 3/6] [CI] Fix templating --- .drone.yml | 179 ++++++++++++++++++++------------------ kube/beer-deployment.yaml | 4 +- kube/beer-namespace.yaml | 4 +- 3 files changed, 99 insertions(+), 88 deletions(-) diff --git a/.drone.yml b/.drone.yml index e89f9ab..0cb88bb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,3 +1,98 @@ +--- +kind: pipeline +name: build + +steps: +- name: build image + image: plugins/docker + settings: + repo: kleph/beer + tags: ${DRONE_COMMIT_SHA:0:8} + username: + from_secret: dockerhub_username + password: + from_secret: dockerhub_password + +#depends_on: +#- unit tests + +--- +kind: pipeline +name: deploy-staging + +steps: +- name: deploy-staging + image: sinlead/drone-kubectl + settings: + kubernetes_server: + from_secret: kubectl_uri + kubernetes_cert: + from_secret: kubectl_cert + kubernetes_token: + from_secret: kubectl_token + environment: + IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} + commands: + - export NAMESPACE=beer-staging-${DRONE_COMMIT_SHA:0:4} + - echo "== create staging namespace $${NAMESPACE}" + - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-namespace.yaml > kube/beer-namespace-staging.yaml + - kubectl apply -f kube/beer-namespace-staging.yaml + - echo "== deploy staging" + - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment.yaml > kube/beer-deployment-staging.yaml + - kubectl apply -f kube/beer-deployment-staging.yaml --namespace=$${NAMESPACE} + - echo "== post deploy status:" + - kubectl get deployments --namespace=$${NAMESPACE} + - kubectl get pods --namespace=$${NAMESPACE} + +depends_on: +- build + +when: + branch: + exclude: + - master + +--- +kind: pipeline +name: deploy + +steps: +- name: deploy + image: sinlead/drone-kubectl + settings: + kubernetes_server: + from_secret: kubectl_uri + kubernetes_cert: + from_secret: kubectl_cert + kubernetes_token: + from_secret: kubectl_token + environment: + IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} + NAMESPACE: beer + commands: + - echo "== pre deploy status:" + - kubectl get pods --namespace=beer + - kubectl get deployments --namespace=beer + - kubectl get svc --namespace=beer + - cat kube/beer-deployment.yaml + - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment.yaml > kube/beer-deployment-prod.yaml + - cat kube/beer-deployment-prod.yaml + - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-prod.yaml > kube/beer-deployment-prod2.yaml + - echo "applying" + - cat kube/beer-deployment-prod2.yaml + - kubectl apply -f kube/beer-deployment-prod2.yaml --namespace=beer + - echo "== post deploy status:" + - kubectl get deployments --namespace=beer + - kubectl get pods --namespace=beer + +depends_on: +- build + +when: + branch: + include: + - master + #--- #kind: pipeline #name: lint @@ -38,87 +133,3 @@ # #depends_on: #- lint - ---- -kind: pipeline -name: build - -steps: -- name: build image - image: plugins/docker - settings: - repo: kleph/beer - tags: ${DRONE_COMMIT_SHA:0:8} - username: - from_secret: dockerhub_username - password: - from_secret: dockerhub_password - -#depends_on: -#- unit tests - ---- -kind: pipeline -name: deploy - -steps: -- name: deploy - image: sinlead/drone-kubectl - settings: - kubernetes_server: - from_secret: kubectl_uri - kubernetes_cert: - from_secret: kubectl_cert - kubernetes_token: - from_secret: kubectl_token - environment: - IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} - NAMESPACE: beer-staging-${DRONE_COMMIT_SHA:0:4} - commands: - - echo "== create staging namespace ${NAMESPACE}" - - kubectl get svc --namespace=${NAMESPACE} - - cat kube/beer-deployment.yaml > kube/beer-namespace.yaml - - kubectl apply -f kube/beer-namespace.yaml - - echo "== deploy staging" - - cat kube/beer-deployment.yaml > kube/beer-deployment-${IMAGE_TAG}.yaml - - kubectl apply -f kube/beer-deployment-${IMAGE_TAG}.yaml --namespace=beer - -depends_on: -- build - -when: - branch: - exclude: - - master - ---- -kind: pipeline -name: deploy - -steps: -- name: deploy - image: sinlead/drone-kubectl - settings: - kubernetes_server: - from_secret: kubectl_uri - kubernetes_cert: - from_secret: kubectl_cert - kubernetes_token: - from_secret: kubectl_token - environment: - IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} - commands: - - echo "== pre deploy status:" - - kubectl get pods --namespace=beer - - kubectl get deployments --namespace=beer - - kubectl get svc --namespace=beer - - cat kube/beer-deployment.yaml > kube/beer-deployment-${IMAGE_TAG}.yaml - - kubectl apply -f kube/beer-deployment-${IMAGE_TAG}.yaml --namespace=beer - - echo "== post deploy status:" - -depends_on: -- build - -when: - branch: - - master diff --git a/kube/beer-deployment.yaml b/kube/beer-deployment.yaml index 83e916d..5d4aa79 100644 --- a/kube/beer-deployment.yaml +++ b/kube/beer-deployment.yaml @@ -3,7 +3,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: beer-deployment - namespace: beer + namespace: __NAMESPACE__ spec: selector: matchLabels: @@ -16,7 +16,7 @@ spec: spec: containers: - name: beer - image: kleph/beer:${IMAGE_TAG} + image: kleph/beer:__IMAGE_TAG__ imagePullPolicy: Always ports: - containerPort: 5000 diff --git a/kube/beer-namespace.yaml b/kube/beer-namespace.yaml index 899e8fa..9120a41 100644 --- a/kube/beer-namespace.yaml +++ b/kube/beer-namespace.yaml @@ -2,6 +2,6 @@ apiVersion: v1 kind: Namespace metadata: - name: ${NAMESPACE} + name: __NAMESPACE__ labels: - name: ${NAMESPACE} + name: __NAMESPACE__ -- 2.45.2 From 758dc6ffce676f9c13974b9c3d348b132cc8959d Mon Sep 17 00:00:00 2001 From: kleph Date: Wed, 26 Feb 2020 00:45:40 +0100 Subject: [PATCH 4/6] [CI] remove debug and bring back the linter --- .drone.yml | 90 ++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/.drone.yml b/.drone.yml index 0cb88bb..4f5ad22 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,3 +1,44 @@ +--- +kind: pipeline +name: lint + +steps: +- name: yaml lint + image: cytopia/yamllint + commands: + - yamllint . + +- name: docker lint + image: hadolint/hadolint + commands: + - hadolint Dockerfile # ignore pinning version in pip + +- name: w3c validator + image: validator/validator:latest + commands: + - vnu static/*.html + +- name: markdown lint + image: pipelinecomponents/markdownlint:latest + commands: + - mdl --style all --warnings . + +--- +kind: pipeline +name: unit tests + +steps: +- name: unit test + image: python:slim + commands: + - pip install -r requirements.txt + - pip install pylint + - pylint beer/*.py tests/*.py + - python -m pytest tests + +depends_on: +- lint + --- kind: pipeline name: build @@ -13,8 +54,8 @@ steps: password: from_secret: dockerhub_password -#depends_on: -#- unit tests +depends_on: +- unit tests --- kind: pipeline @@ -73,13 +114,9 @@ steps: - echo "== pre deploy status:" - kubectl get pods --namespace=beer - kubectl get deployments --namespace=beer - - kubectl get svc --namespace=beer - - cat kube/beer-deployment.yaml - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-deployment.yaml > kube/beer-deployment-prod.yaml - - cat kube/beer-deployment-prod.yaml - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment-prod.yaml > kube/beer-deployment-prod2.yaml - echo "applying" - - cat kube/beer-deployment-prod2.yaml - kubectl apply -f kube/beer-deployment-prod2.yaml --namespace=beer - echo "== post deploy status:" - kubectl get deployments --namespace=beer @@ -92,44 +129,3 @@ when: branch: include: - master - -#--- -#kind: pipeline -#name: lint -# -#steps: -#- name: yaml lint -# image: cytopia/yamllint -# commands: -# - yamllint . -# -#- name: docker lint -# image: hadolint/hadolint -# commands: -# - hadolint Dockerfile # ignore pinning version in pip -# -#- name: w3c validator -# image: validator/validator:latest -# commands: -# - vnu static/*.html -# -#- name: markdown lint -# image: pipelinecomponents/markdownlint:latest -# commands: -# - mdl --style all --warnings . -# -#--- -#kind: pipeline -#name: unit tests -# -#steps: -#- name: unit test -# image: python:slim -# commands: -# - pip install -r requirements.txt -# - pip install pylint -# - pylint beer/*.py tests/*.py -# - python -m pytest tests -# -#depends_on: -#- lint -- 2.45.2 From 522f1db38b5fc81f6a2fd65cfab5a76d83c22b7b Mon Sep 17 00:00:00 2001 From: kleph Date: Wed, 26 Feb 2020 00:48:28 +0100 Subject: [PATCH 5/6] [lint] mandatory lint configuration ;) --- .yamllint | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.yamllint b/.yamllint index 9eaf5ea..35c26b0 100644 --- a/.yamllint +++ b/.yamllint @@ -4,3 +4,6 @@ extends: default rules: indentation: indent-sequences: consistent + line-length: + max: 120 + level: warning -- 2.45.2 From 5c21884be4a5933e90cb596e3b2ab97b88d51b70 Mon Sep 17 00:00:00 2001 From: kleph Date: Wed, 26 Feb 2020 01:24:32 +0100 Subject: [PATCH 6/6] [CI] Remove staging - will do in another branch --- .drone.yml | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/.drone.yml b/.drone.yml index 4f5ad22..356e1f6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -57,42 +57,6 @@ steps: depends_on: - unit tests ---- -kind: pipeline -name: deploy-staging - -steps: -- name: deploy-staging - image: sinlead/drone-kubectl - settings: - kubernetes_server: - from_secret: kubectl_uri - kubernetes_cert: - from_secret: kubectl_cert - kubernetes_token: - from_secret: kubectl_token - environment: - IMAGE_TAG: ${DRONE_COMMIT_SHA:0:8} - commands: - - export NAMESPACE=beer-staging-${DRONE_COMMIT_SHA:0:4} - - echo "== create staging namespace $${NAMESPACE}" - - sed "s/__NAMESPACE__/$${NAMESPACE}/g" kube/beer-namespace.yaml > kube/beer-namespace-staging.yaml - - kubectl apply -f kube/beer-namespace-staging.yaml - - echo "== deploy staging" - - sed "s/__IMAGE_TAG__/$${IMAGE_TAG}/g" kube/beer-deployment.yaml > kube/beer-deployment-staging.yaml - - kubectl apply -f kube/beer-deployment-staging.yaml --namespace=$${NAMESPACE} - - echo "== post deploy status:" - - kubectl get deployments --namespace=$${NAMESPACE} - - kubectl get pods --namespace=$${NAMESPACE} - -depends_on: -- build - -when: - branch: - exclude: - - master - --- kind: pipeline name: deploy -- 2.45.2