102
.gitlab-ci.yml
102
.gitlab-ci.yml
@ -1,91 +1,45 @@
|
|||||||
stages:
|
stages:
|
||||||
- test
|
|
||||||
- build
|
- build
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
variables:
|
|
||||||
APP_VERSION: ${CI_COMMIT_REF_SLUG}
|
|
||||||
DOCKER_AUTH_CONFIG: "{\"auths\":{\"$DOCKER_REGISTRY\":{\"username\":\"$DOCKER_USER\",\"password\":\"$DOCKER_PASSWORD\"}}}"
|
|
||||||
|
|
||||||
.test-template:
|
|
||||||
image: python:3.9-buster
|
|
||||||
stage: test
|
|
||||||
tags:
|
|
||||||
- kube
|
|
||||||
except:
|
|
||||||
- tags
|
|
||||||
before_script:
|
|
||||||
- pip install poetry==1.1.6
|
|
||||||
- poetry config virtualenvs.create false
|
|
||||||
- poetry install
|
|
||||||
|
|
||||||
flake8:
|
|
||||||
stage: test
|
|
||||||
extends:
|
|
||||||
- .test-template
|
|
||||||
script:
|
|
||||||
- flake8 --count .
|
|
||||||
|
|
||||||
pytest:
|
|
||||||
extends:
|
|
||||||
- .test-template
|
|
||||||
script:
|
|
||||||
- pytest -vv
|
|
||||||
|
|
||||||
black:
|
|
||||||
extends:
|
|
||||||
- .test-template
|
|
||||||
script:
|
|
||||||
- black --check .
|
|
||||||
|
|
||||||
mypy:
|
|
||||||
stage: test
|
|
||||||
extends:
|
|
||||||
- .test-template
|
|
||||||
script:
|
|
||||||
- mypy .
|
|
||||||
|
|
||||||
image-builder:
|
image-builder:
|
||||||
stage: build
|
stage: build
|
||||||
image:
|
|
||||||
name: gcr.io/kaniko-project/executor:v1.6.0-debug
|
|
||||||
entrypoint: [ "" ]
|
|
||||||
tags:
|
tags:
|
||||||
- kube
|
- kube
|
||||||
only:
|
only:
|
||||||
- tags
|
refs:
|
||||||
|
- master
|
||||||
|
image:
|
||||||
|
name: alpine:3.18
|
||||||
|
entrypoint: [""]
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p /kaniko/.docker
|
- apk add --no-cache img
|
||||||
# Create authentication rule to publish image.
|
- img login --password "${DOCKER_PASSWORD}" --username "${DOCKER_USER}" "${DOCKER_REGISTRY}"
|
||||||
- echo "$DOCKER_AUTH_CONFIG" > /kaniko/.docker/config.json
|
- img build --no-console -t "docker.le-memese.com/bots/lenochka-bot:latest" .
|
||||||
# Build actual image.
|
- img push "docker.le-memese.com/bots/lenochka-bot:latest"
|
||||||
- /kaniko/executor --context .
|
|
||||||
--dockerfile deploy/Dockerfile
|
|
||||||
--destination "$IMAGE_NAME:$APP_VERSION"
|
|
||||||
--force
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
image: docker.le-memese.com/kubectl:1.22.0
|
|
||||||
tags:
|
tags:
|
||||||
- kube
|
- kube
|
||||||
only:
|
only:
|
||||||
- tags
|
refs:
|
||||||
environment:
|
- master
|
||||||
name: production
|
image:
|
||||||
kubernetes:
|
name: alpine/helm:3.7.1
|
||||||
namespace: $NAMESPACE
|
entrypoint: ["/bin/sh", "-c"]
|
||||||
script:
|
script:
|
||||||
# Save all lenochka's variables in a file.
|
- helm
|
||||||
- env | grep "^LENOCHKA_" > .deploy-env
|
upgrade
|
||||||
# Recreate envconfig for pod.
|
lenochka
|
||||||
- kubectl delete configmap "$ENVCONF" || true
|
./helm
|
||||||
- kubectl create configmap "$ENVCONF" --from-env-file=.deploy-env
|
--install
|
||||||
# Create secret for pulling images.
|
--wait
|
||||||
- echo "$DOCKER_AUTH_CONFIG" > .dockerauth.json
|
--create-namespace
|
||||||
- kubectl delete secret "$PULL_SECRET" || true
|
--atomic
|
||||||
- kubectl create secret generic "$PULL_SECRET"
|
--timeout 2m
|
||||||
--from-file=.dockerconfigjson=.dockerauth.json
|
--namespace "$NAMESPACE"
|
||||||
--type=kubernetes.io/dockerconfigjson
|
-f "$HELM_CONFIG"
|
||||||
# Substitute env variables and apply them in kubectl.
|
--set "podAnnotations.deployed_at=$(date +%Y.%m.%d-%H:%M)"
|
||||||
- find deploy/kube -name "*.yml" | xargs cat | envsubst | kubectl apply -f -
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: lenochka
|
|
||||||
annotations:
|
|
||||||
app.gitlab.com/env: $CI_ENVIRONMENT_SLUG
|
|
||||||
app.gitlab.com/app: $CI_PROJECT_PATH_SLUG
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: lenochka-bot
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
annotations:
|
|
||||||
app.gitlab.com/env: $CI_ENVIRONMENT_SLUG
|
|
||||||
app.gitlab.com/app: $CI_PROJECT_PATH_SLUG
|
|
||||||
labels:
|
|
||||||
app: lenochka-bot
|
|
||||||
spec:
|
|
||||||
imagePullSecrets:
|
|
||||||
- name: "$PULL_SECRET"
|
|
||||||
containers:
|
|
||||||
- name: lenochka-bot
|
|
||||||
image: docker.le-memese.com/bots/lenochka-bot:$APP_VERSION
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpu: "$K8S_CPU_LIMITS"
|
|
||||||
memory: "$K8S_MEM_LIMITS"
|
|
||||||
envFrom:
|
|
||||||
- configMapRef:
|
|
||||||
name: "$ENVCONF"
|
|
23
helm/.helmignore
Normal file
23
helm/.helmignore
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Patterns to ignore when building packages.
|
||||||
|
# This supports shell glob matching, relative path matching, and
|
||||||
|
# negation (prefixed with !). Only one pattern per line.
|
||||||
|
.DS_Store
|
||||||
|
# Common VCS dirs
|
||||||
|
.git/
|
||||||
|
.gitignore
|
||||||
|
.bzr/
|
||||||
|
.bzrignore
|
||||||
|
.hg/
|
||||||
|
.hgignore
|
||||||
|
.svn/
|
||||||
|
# Common backup files
|
||||||
|
*.swp
|
||||||
|
*.bak
|
||||||
|
*.tmp
|
||||||
|
*.orig
|
||||||
|
*~
|
||||||
|
# Various IDEs
|
||||||
|
.project
|
||||||
|
.idea/
|
||||||
|
*.tmproj
|
||||||
|
.vscode/
|
24
helm/Chart.yaml
Normal file
24
helm/Chart.yaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
name: lenochka
|
||||||
|
description: A Helm chart for Kubernetes
|
||||||
|
|
||||||
|
# A chart can be either an 'application' or a 'library' chart.
|
||||||
|
#
|
||||||
|
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||||
|
# to be deployed.
|
||||||
|
#
|
||||||
|
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||||
|
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||||
|
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||||
|
type: application
|
||||||
|
|
||||||
|
# This is the chart version. This version number should be incremented each time you make changes
|
||||||
|
# to the chart and its templates, including the app version.
|
||||||
|
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
# This is the version number of the application being deployed. This version number should be
|
||||||
|
# incremented each time you make changes to the application. Versions are not expected to
|
||||||
|
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||||
|
# It is recommended to use it with quotes.
|
||||||
|
appVersion: "1.16.0"
|
62
helm/templates/_helpers.tpl
Normal file
62
helm/templates/_helpers.tpl
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
{{/*
|
||||||
|
Expand the name of the chart.
|
||||||
|
*/}}
|
||||||
|
{{- define "lenochka.name" -}}
|
||||||
|
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Create a default fully qualified app name.
|
||||||
|
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
|
||||||
|
If release name contains chart name it will be used as a full name.
|
||||||
|
*/}}
|
||||||
|
{{- define "lenochka.fullname" -}}
|
||||||
|
{{- if .Values.fullnameOverride }}
|
||||||
|
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||||
|
{{- if contains $name .Release.Name }}
|
||||||
|
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Create chart name and version as used by the chart label.
|
||||||
|
*/}}
|
||||||
|
{{- define "lenochka.chart" -}}
|
||||||
|
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Common labels
|
||||||
|
*/}}
|
||||||
|
{{- define "lenochka.labels" -}}
|
||||||
|
helm.sh/chart: {{ include "lenochka.chart" . }}
|
||||||
|
{{ include "lenochka.selectorLabels" . }}
|
||||||
|
{{- if .Chart.AppVersion }}
|
||||||
|
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||||
|
{{- end }}
|
||||||
|
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Selector labels
|
||||||
|
*/}}
|
||||||
|
{{- define "lenochka.selectorLabels" -}}
|
||||||
|
app.kubernetes.io/name: {{ include "lenochka.name" . }}
|
||||||
|
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Create the name of the service account to use
|
||||||
|
*/}}
|
||||||
|
{{- define "lenochka.serviceAccountName" -}}
|
||||||
|
{{- if .Values.serviceAccount.create }}
|
||||||
|
{{- default (include "lenochka.fullname" .) .Values.serviceAccount.name }}
|
||||||
|
{{- else }}
|
||||||
|
{{- default "default" .Values.serviceAccount.name }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
54
helm/templates/deployment.yaml
Normal file
54
helm/templates/deployment.yaml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: {{ include "lenochka.fullname" . }}
|
||||||
|
labels:
|
||||||
|
{{- include "lenochka.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "lenochka.selectorLabels" . | nindent 6 }}
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
{{- with .Values.podAnnotations }}
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
labels:
|
||||||
|
{{- include "lenochka.selectorLabels" . | nindent 8 }}
|
||||||
|
spec:
|
||||||
|
{{- with .Values.imagePullSecrets }}
|
||||||
|
imagePullSecrets:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
serviceAccountName: {{ include "lenochka.serviceAccountName" . }}
|
||||||
|
securityContext:
|
||||||
|
{{- toYaml .Values.podSecurityContext | nindent 8 }}
|
||||||
|
containers:
|
||||||
|
- name: {{ .Chart.Name }}
|
||||||
|
securityContext:
|
||||||
|
{{- toYaml .Values.securityContext | nindent 12 }}
|
||||||
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||||
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
|
resources:
|
||||||
|
{{- toYaml .Values.resources | nindent 12 }}
|
||||||
|
{{- with .Values.env }}
|
||||||
|
env:
|
||||||
|
{{- range $key, $val := . }}
|
||||||
|
- name: {{ $key | quote }}
|
||||||
|
value: {{ $val | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.nodeSelector }}
|
||||||
|
nodeSelector:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.affinity }}
|
||||||
|
affinity:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.tolerations }}
|
||||||
|
tolerations:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
12
helm/templates/serviceaccount.yaml
Normal file
12
helm/templates/serviceaccount.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{{- if .Values.serviceAccount.create -}}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: {{ include "lenochka.serviceAccountName" . }}
|
||||||
|
labels:
|
||||||
|
{{- include "lenochka.labels" . | nindent 4 }}
|
||||||
|
{{- with .Values.serviceAccount.annotations }}
|
||||||
|
annotations:
|
||||||
|
{{- toYaml . | nindent 4 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
58
helm/values.yaml
Normal file
58
helm/values.yaml
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Default values for lenochka.
|
||||||
|
# This is a YAML-formatted file.
|
||||||
|
# Declare variables to be passed into your templates.
|
||||||
|
|
||||||
|
image:
|
||||||
|
repository: docker.le-memese.com/bots/lenochka-bot
|
||||||
|
pullPolicy: Always
|
||||||
|
# Overrides the image tag whose default is the chart appVersion.
|
||||||
|
tag: ""
|
||||||
|
|
||||||
|
env: {}
|
||||||
|
|
||||||
|
imagePullSecrets: []
|
||||||
|
nameOverride: ""
|
||||||
|
fullnameOverride: ""
|
||||||
|
|
||||||
|
serviceAccount:
|
||||||
|
# Specifies whether a service account should be created
|
||||||
|
create: true
|
||||||
|
# Annotations to add to the service account
|
||||||
|
annotations: {}
|
||||||
|
# The name of the service account to use.
|
||||||
|
# If not set and create is true, a name is generated using the fullname template
|
||||||
|
name: ""
|
||||||
|
|
||||||
|
podAnnotations: {}
|
||||||
|
|
||||||
|
podSecurityContext:
|
||||||
|
{}
|
||||||
|
# fsGroup: 2000
|
||||||
|
|
||||||
|
securityContext:
|
||||||
|
{}
|
||||||
|
# capabilities:
|
||||||
|
# drop:
|
||||||
|
# - ALL
|
||||||
|
# readOnlyRootFilesystem: true
|
||||||
|
# runAsNonRoot: true
|
||||||
|
# runAsUser: 1000
|
||||||
|
|
||||||
|
resources:
|
||||||
|
{}
|
||||||
|
# We usually recommend not to specify default resources and to leave this as a conscious
|
||||||
|
# choice for the user. This also increases chances charts run on environments with little
|
||||||
|
# resources, such as Minikube. If you do want to specify resources, uncomment the following
|
||||||
|
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
|
||||||
|
# limits:
|
||||||
|
# cpu: 100m
|
||||||
|
# memory: 128Mi
|
||||||
|
# requests:
|
||||||
|
# cpu: 100m
|
||||||
|
# memory: 128Mi
|
||||||
|
|
||||||
|
nodeSelector: {}
|
||||||
|
|
||||||
|
tolerations: []
|
||||||
|
|
||||||
|
affinity: {}
|
Reference in New Issue
Block a user