diff --git a/.gitignore b/.gitignore index a5aaed3b4d792a623e6b054770db6468d411964b..6f1621b734becc730c18110755daa4b49a5162df 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,4 @@ dmypy.json # Cython debug symbols cython_debug/ +*.local.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3697087dbb4a893a2f1ee5819034cc7e8e45b2d1..0350071ce4473a6cf3e3768c10a035588ad39a65 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,34 +41,39 @@ build: tags: - kube only: - - tags + - master script: - mkdir -p /kaniko/.docker - echo "$DOCKER_AUTH_CONFIG" > /kaniko/.docker/config.json - /kaniko/executor --context . --dockerfile deploy/Dockerfile - --destination "$IMAGE_NAME:$APP_VERSION" + --destination "docker.le-memese.com/bots/s3rius-bot:latest" --force deploy: stage: deploy - image: docker.le-memese.com/kubectl:1.22.0 + image: + name: alpine/helm:3.7.1 + entrypoint: ["/bin/sh", "-c"] tags: - kube only: - - tags + - master environment: - name: production - url: https://${BOT_HOST}/ + name: s3rius-production kubernetes: - namespace: $NAMESPACE + namespace: "$NAMESPACE" + action: start + url: "https://{BOT_UI_HOST}" script: - - env | grep "^BOT_" > .deploy-env - - kubectl delete configmap "$CONFIG_MAP" || true - - kubectl create configmap "$CONFIG_MAP" --from-env-file=.deploy-env - - echo "$DOCKER_AUTH_CONFIG" > .dockerauth.json - - kubectl delete secret "$PULL_SECRET" || true - - kubectl create secret generic "$PULL_SECRET" - --from-file=.dockerconfigjson=.dockerauth.json - --type=kubernetes.io/dockerconfigjson - - find deploy/kube -name "*.yml" | xargs cat | envsubst | kubectl apply -f - + - helm + upgrade + "$HELM_APP_NAME" + ./deploy/helm + --install + --wait + --create-namespace + --atomic + --timeout 2m + --namespace "$NAMESPACE" + -f "$HELM_CONFIG" diff --git a/deploy/helm/.helmignore b/deploy/helm/.helmignore new file mode 100644 index 0000000000000000000000000000000000000000..0e8a0eb36f4ca2c939201c0d54b5d82a1ea34778 --- /dev/null +++ b/deploy/helm/.helmignore @@ -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/ diff --git a/deploy/helm/Chart.yaml b/deploy/helm/Chart.yaml new file mode 100644 index 0000000000000000000000000000000000000000..20c9412d96aabc1ebe64b08757d4df8ad6403c98 --- /dev/null +++ b/deploy/helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: s3rius_bot +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" diff --git a/deploy/helm/files/dockerauth.json b/deploy/helm/files/dockerauth.json new file mode 100644 index 0000000000000000000000000000000000000000..ece91464237bdc03fa69c437bf63c121ea91da6f --- /dev/null +++ b/deploy/helm/files/dockerauth.json @@ -0,0 +1,8 @@ +{ + "auths": { + {{ .Values.image.pullSecret.registry | quote}}: { + "username": {{.Values.image.pullSecret.username | quote }}, + "password": {{.Values.image.pullSecret.password | quote }} + } + } +} diff --git a/deploy/helm/templates/deployment.yml b/deploy/helm/templates/deployment.yml new file mode 100644 index 0000000000000000000000000000000000000000..0347e85248ed0ad1a41b5b1aa6048b4bcf22c92b --- /dev/null +++ b/deploy/helm/templates/deployment.yml @@ -0,0 +1,41 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.bot.name }} + annotations: + {{- .Values.annotations | toYaml | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Values.bot.name }} + template: + metadata: + labels: + app: {{ .Values.bot.name }} + annotations: + deployed_at: {{ now | quote }} + spec: + {{- with .Values.image.pullSecret }} + imagePullSecrets: + - name: {{ .name | quote }} + {{- end }} + containers: + - name: bot + image: {{ .Values.image.name }} + imagePullPolicy: Always + {{- with .Values.resources }} + resources: + {{- . | toYaml | nindent 12 }} + {{- end }} + {{- with .Values.env }} + env: + {{- range $key, $val := . }} + - name: {{$key | quote }} + value: {{$val | quote }} + {{- end }} + {{- end }} + ports: + - containerPort: {{ .Values.env.BOT_FLASK_PORT | default 8080 }} + name: "botport" diff --git a/deploy/helm/templates/ingress.yml b/deploy/helm/templates/ingress.yml new file mode 100644 index 0000000000000000000000000000000000000000..91382673a03a4fd367e8984b4d7f17ecad8e7a9d --- /dev/null +++ b/deploy/helm/templates/ingress.yml @@ -0,0 +1,7 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Values.bot.name }} +spec: + {{- .Values.ingress | toYaml | nindent 2 }} \ No newline at end of file diff --git a/deploy/helm/templates/pull_secret.yml b/deploy/helm/templates/pull_secret.yml new file mode 100644 index 0000000000000000000000000000000000000000..16a7e449ea370645046ea651fcdc778ea24a570c --- /dev/null +++ b/deploy/helm/templates/pull_secret.yml @@ -0,0 +1,9 @@ +{{- if .Values.image.pullSecret }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Values.image.pullSecret.name }} +data: + .dockerconfigjson: {{tpl (.Files.Get "files/dockerauth.json") . | b64enc | quote}} +type: kubernetes.io/dockerconfigjson +{{- end }} diff --git a/deploy/helm/templates/service.yml b/deploy/helm/templates/service.yml new file mode 100644 index 0000000000000000000000000000000000000000..6d801206205f8ca4b8b645e18e63d04cd448940d --- /dev/null +++ b/deploy/helm/templates/service.yml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.bot.name }} +spec: + selector: + app: {{ .Values.bot.name }} + ports: + - port: 80 + name: bot + targetPort: "botport" diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ba5b1f9b9bdc83c7197f66df627cadafa5bb2152 --- /dev/null +++ b/deploy/helm/values.yaml @@ -0,0 +1,46 @@ +# Default values for s3rius_bot. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +bot: + name: s3rius + +image: + name: some-image + pullSecret: {} + # name + # secretName: + # registry + # username + # password + +env: {} +# TELEGRAM_ACCOUNT_PHONE: +# TELEGRAM_API_HASH: +# TELEGRAM_APP_ID: + +annotations: + app.gitlab.com/env: $CI_ENVIRONMENT_SLUG + app.gitlab.com/app: $CI_PROJECT_PATH_SLUG + + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +ingress: {} + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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 diff --git a/deploy/kube/deployment.yml b/deploy/kube/deployment.yml deleted file mode 100644 index 18f943e410345e67089408f524da84fd62a0eed5..0000000000000000000000000000000000000000 --- a/deploy/kube/deployment.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: s3riusbot - annotations: - app.gitlab.com/env: $CI_ENVIRONMENT_SLUG - app.gitlab.com/app: $CI_PROJECT_PATH_SLUG -spec: - replicas: 1 - selector: - matchLabels: - app: s3rius-bot - template: - metadata: - annotations: - app.gitlab.com/env: $CI_ENVIRONMENT_SLUG - app.gitlab.com/app: $CI_PROJECT_PATH_SLUG - labels: - app: s3rius-bot - spec: - imagePullSecrets: - - name: "$PULL_SECRET" - containers: - - name: s3rius-bot - image: docker.le-memese.com/bots/s3rius-bot:$APP_VERSION - resources: - limits: - cpu: "$K8S_CPU_LIMITS" - memory: "$K8S_MEM_LIMITS" - envFrom: - - configMapRef: - name: "$CONFIG_MAP" - ports: - - containerPort: $BOT_FLASK_PORT diff --git a/deploy/kube/ingress.yml b/deploy/kube/ingress.yml deleted file mode 100644 index d6bc67d2b52e1765e89487cb103d6360c804c886..0000000000000000000000000000000000000000 --- a/deploy/kube/ingress.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: s3rius-bot-ui -spec: - tls: - - secretName: $TLS_SECRET - rules: - - host: $BOT_HOST - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: s3rius-bot - port: - name: web diff --git a/deploy/kube/service.yml b/deploy/kube/service.yml deleted file mode 100644 index 50f71dfa0d936fbc1d25e04bbb783df9f90bb28d..0000000000000000000000000000000000000000 --- a/deploy/kube/service.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: s3rius-bot -spec: - selector: - app: s3rius-bot - ports: - - port: 80 - name: web - targetPort: $BOT_FLASK_PORT