Files
lenochka/.gitlab-ci.yml
2021-08-08 14:18:38 +04:00

92 lines
2.0 KiB
YAML

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
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
deploy:
stage: deploy
image: docker.le-memese.com/kubectl:1.22.0
tags:
- kube
only:
- tags
environment:
name: production
kubernetes:
namespace: $NAMESPACE
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 -