default: tags: - universal stages: - tests - build-and-push - deploy tests_job1: stage: tests image: python:3.11-slim variables: PYTHONPATH: "." before_script: - pip install --no-cache-dir -r requirements.txt - pip install pytest script: - pytest tests/ push_job: resource_group: production stage: build-and-push image: name: gcr.io/kaniko-project/executor:v1.23.0-debug entrypoint: [""] before_script: - mkdir -p /kaniko/.docker - cp "$DOCKER_AUTH_CONFIG" /kaniko/.docker/config.json script: - > /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${DOCKERHUB_USER}/quote-bot:${CI_COMMIT_SHORT_SHA}" --destination "${DOCKERHUB_USER}/quote-bot:latest" deploy_to_server: resource_group: production stage: deploy image: ghcr.io/ansible/creator-ee:v0.22.0 variables: ANSIBLE_HOST_KEY_CHECKING: "False" before_script: - mkdir -p ~/.ssh - chmod 700 ~/.ssh - echo "$ANSIBLE_PRIVATE_KEY" > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - ansible-galaxy collection install community.docker script: - cd auto-deployment/ - ansible-playbook -i inventory.ini A_deploy.yml --extra-vars "image_tag=$CI_COMMIT_SHORT_SHA" environment: name: production url: http://$BOT_SERVER_IP on_stop: stop_production stop_production: stage: deploy image: ghcr.io/ansible/creator-ee:v0.22.0 variables: ANSIBLE_HOST_KEY_CHECKING: "False" before_script: - ansible-galaxy collection install community.docker - mkdir -p ~/.ssh - chmod 700 ~/.ssh - echo "$ANSIBLE_PRIVATE_KEY" > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 script: - cd auto-deployment/ - ansible-playbook -i inventory.ini A_deploy.yml --extra-vars "container_state=absent" when: manual environment: name: production action: stop variables: MSG_SUCCESS: "✅ Успех! Пайплайн проекта $CI_PROJECT_NAME завершен.\nВетка: $CI_COMMIT_REF_NAME\nКоммит: $CI_COMMIT_MESSAGE" MSG_FAILURE: "❌ Ошибка! Пайплайн проекта $CI_PROJECT_NAME упал.\nВетка: $CI_COMMIT_REF_NAME\nСмотреть логи пайплайна" .notify_telegram: stage: .post tags: - tg image: curlimages/curl:latest script: - | curl -s -X POST "https://api.telegram.org/bot$ALERT_TG_BOT/sendMessage" \ -d chat_id="$ADMIN_ID_TG" \ -d text="$MESSAGE" \ -d parse_mode="HTML" \ -d disable_web_page_preview="true" notify_success: extends: .notify_telegram variables: MESSAGE: $MSG_SUCCESS when: on_success notify_failure: extends: .notify_telegram variables: MESSAGE: $MSG_FAILURE when: on_failure mirror_to_gitea: image: name: alpine/git:latest entrypoint: [""] stage: .post variables: GIT_DEPTH: 1 script: - git config user.name "GitLab CI/CD" - git config user.email "ci@leor156.online" - git checkout --orphan showcase - git add -A - git commit -m "Showcase update - ${CI_COMMIT_SHORT_SHA}" - git remote add gitea https://leo:$GITEA_TOKEN@gitea.leor156.online/leo/quote_bot_auto-deployment.git - git push gitea showcase:main --force when: on_success