Update CI/CD

This commit is contained in:
LeoR156
2026-09-12 18:09:16 +05:00
parent e4806e1e07
commit f86e269d24
2 changed files with 50 additions and 25 deletions
+42 -18
View File
@@ -6,7 +6,6 @@ stages:
- tests - tests
- build-and-push - build-and-push
- deploy - deploy
- notify
tests_job1: tests_job1:
stage: tests stage: tests
@@ -20,22 +19,24 @@ tests_job1:
- pytest tests/ - pytest tests/
push_job: push_job:
stage: build-and-push resource_group: production
image: stage: build-and-push
name: gcr.io/kaniko-project/executor:v1.23.0-debug image:
entrypoint: [""] name: gcr.io/kaniko-project/executor:v1.23.0-debug
before_script: entrypoint: [""]
- mkdir -p /kaniko/.docker before_script:
- cp "$DOCKER_AUTH_CONFIG" /kaniko/.docker/config.json - mkdir -p /kaniko/.docker
script: - cp "$DOCKER_AUTH_CONFIG" /kaniko/.docker/config.json
- > script:
/kaniko/executor - >
--context "${CI_PROJECT_DIR}" /kaniko/executor
--dockerfile "${CI_PROJECT_DIR}/Dockerfile" --context "${CI_PROJECT_DIR}"
--destination "${DOCKERHUB_USER}/quote-bot:${CI_COMMIT_SHORT_SHA}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${DOCKERHUB_USER}/quote-bot:latest" --destination "${DOCKERHUB_USER}/quote-bot:${CI_COMMIT_SHORT_SHA}"
--destination "${DOCKERHUB_USER}/quote-bot:latest"
deploy_to_server: deploy_to_server:
resource_group: production
stage: deploy stage: deploy
image: ghcr.io/ansible/creator-ee:v0.22.0 image: ghcr.io/ansible/creator-ee:v0.22.0
variables: variables:
@@ -49,6 +50,32 @@ deploy_to_server:
script: script:
- cd auto-deployment/ - cd auto-deployment/
- ansible-playbook -i inventory.ini A_deploy.yml - ansible-playbook -i inventory.ini A_deploy.yml
--extra-vars "image_tag=$CI_COMMIT_SHORT_SHA"
environment:
name: production
url: http://$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:
- 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: variables:
MSG_SUCCESS: "✅ <b>Успех!</b> Пайплайн проекта <b>$CI_PROJECT_NAME</b> завершен.\nВетка: $CI_COMMIT_REF_NAME\nКоммит: $CI_COMMIT_MESSAGE" MSG_SUCCESS: "✅ <b>Успех!</b> Пайплайн проекта <b>$CI_PROJECT_NAME</b> завершен.\nВетка: $CI_COMMIT_REF_NAME\nКоммит: $CI_COMMIT_MESSAGE"
@@ -68,17 +95,14 @@ variables:
-d parse_mode="HTML" \ -d parse_mode="HTML" \
-d disable_web_page_preview="true" -d disable_web_page_preview="true"
notify_success: notify_success:
extends: .notify_telegram extends: .notify_telegram
variables: variables:
MESSAGE: $MSG_SUCCESS MESSAGE: $MSG_SUCCESS
when: on_success when: on_success
notify_failure: notify_failure:
extends: .notify_telegram extends: .notify_telegram
variables: variables:
MESSAGE: $MSG_FAILURE MESSAGE: $MSG_FAILURE
when: on_failure when: on_failure
+4 -3
View File
@@ -3,8 +3,9 @@
hosts: all hosts: all
vars: vars:
image_name: "leor156/quote-bot:latest" image_name: "leor156/quote-bot:{{ image_tag | default('latest') }}"
container_name: "quote-bot" container_name: "{{ container_name | default('quote-bot') }}"
container_state: "{{ container_state | default('started') }}"
tasks: tasks:
- name: Убеждаемся, что установлена библиотека Docker для Python - name: Убеждаемся, что установлена библиотека Docker для Python
@@ -22,7 +23,7 @@
community.docker.docker_container: community.docker.docker_container:
name: "{{ container_name }}" name: "{{ container_name }}"
image: "{{ image_name }}" image: "{{ image_name }}"
state: started state: "{{ container_state }}"
restart_policy: unless-stopped restart_policy: unless-stopped
pull: always pull: always
env: env: