Files
Discord-Twitch-Live-Notifier/.gitlab-ci.yml
2023-03-04 11:10:50 +01:00

116 lines
2.7 KiB
YAML

stages:
- lint
- test
- build
- deploy
.install-deps-script: &install-deps
- curl -sSL https://install.python-poetry.org | python -
- export PATH=$PATH:$HOME/.local/bin
- poetry --version
- poetry install
.base:
image: python:3.11.2
only:
changes:
- "poetry.lock"
- "pyproject.toml"
- "app/*"
.test:
extends: .base
stage: test
before_script:
- *install-deps
.lint:
extends: .base
stage: lint
before_script:
- *install-deps
######################################
# #
# LINT STEPS #
# #
######################################
black:
extends: .lint
script:
- poetry run black . --check --verbose --diff
flake8:
extends: .lint
script:
- poetry run flake8
isort:
extends: .lint
script:
- poetry run isort --check .
######################################
# #
# TEST STEPS #
# #
######################################
test:
extends: .test
coverage: '/TOTAL.*\s+(\d+\%)/'
script:
- poetry run pytest --cov -v
######################################
# #
# BUILD STEPS #
# #
######################################
build:
stage: build
image: docker:23.0.1
services:
- name: docker:23.0.1-dind
alias: docker
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -f Dockerfile -t $IMAGE_TAG --build-arg version=$CI_COMMIT_SHA .
- docker push $IMAGE_TAG
only:
changes:
- "Dockerfile"
- "poetry.lock"
- "pyproject.toml"
- "app/*"
######################################
# #
# DEPLOY STEPS #
# #
######################################
deploy:
stage: deploy
image: debian:latest
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- chmod 400 "$SSH_PRIVATE_KEY"
- ssh-add "$SSH_PRIVATE_KEY"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $REMOTE_HOST 2>/dev/null >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh $SSH_USER@$REMOTE_HOST "sudo /etc/discord-twitch-live-notifier/start.sh"
only:
- main