Added CI.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2023-09-21 23:37:17 +04:00
parent f6ad89ebb8
commit d9e0285bb3
9 changed files with 261 additions and 105 deletions

View File

@ -1,91 +1,45 @@
stages:
- test
- build
- 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:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.6.0-debug
entrypoint: [ "" ]
tags:
- kube
only:
- tags
refs:
- master
image:
name: alpine:3.18
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
# Create authentication rule to publish image.
- echo "$DOCKER_AUTH_CONFIG" > /kaniko/.docker/config.json
# Build actual image.
- /kaniko/executor --context .
--dockerfile deploy/Dockerfile
--destination "$IMAGE_NAME:$APP_VERSION"
--force
- apk add --no-cache img
- img login --password "${DOCKER_PASSWORD}" --username "${DOCKER_USER}" "${DOCKER_REGISTRY}"
- img build --no-console -t "docker.le-memese.com/bots/lenochka-bot:latest" .
- img push "docker.le-memese.com/bots/lenochka-bot:latest"
deploy:
stage: deploy
image: docker.le-memese.com/kubectl:1.22.0
tags:
- kube
only:
- tags
environment:
name: production
kubernetes:
namespace: $NAMESPACE
refs:
- master
image:
name: alpine/helm:3.7.1
entrypoint: ["/bin/sh", "-c"]
script:
# Save all lenochka's variables in a file.
- env | grep "^LENOCHKA_" > .deploy-env
# Recreate envconfig for pod.
- kubectl delete configmap "$ENVCONF" || true
- kubectl create configmap "$ENVCONF" --from-env-file=.deploy-env
# Create secret for pulling images.
- 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
# Substitute env variables and apply them in kubectl.
- find deploy/kube -name "*.yml" | xargs cat | envsubst | kubectl apply -f -
- helm
upgrade
lenochka
./helm
--install
--wait
--create-namespace
--atomic
--timeout 2m
--namespace "$NAMESPACE"
-f "$HELM_CONFIG"
--set "podAnnotations.deployed_at=$(date +%Y.%m.%d-%H:%M)"