Update CI/CD
This commit is contained in:
+46
-22
@@ -6,36 +6,37 @@ stages:
|
|||||||
- tests
|
- tests
|
||||||
- build-and-push
|
- build-and-push
|
||||||
- deploy
|
- deploy
|
||||||
- notify
|
|
||||||
|
|
||||||
tests_job1:
|
tests_job1:
|
||||||
stage: tests
|
stage: tests
|
||||||
image: python:3.11-slim
|
image: python:3.11-slim
|
||||||
variables:
|
variables:
|
||||||
PYTHONPATH: "."
|
PYTHONPATH: "."
|
||||||
before_script:
|
before_script:
|
||||||
- pip install --no-cache-dir -r requirements.txt
|
- pip install --no-cache-dir -r requirements.txt
|
||||||
- pip install pytest
|
- pip install pytest
|
||||||
script:
|
script:
|
||||||
- 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"
|
||||||
@@ -57,7 +84,7 @@ variables:
|
|||||||
|
|
||||||
.notify_telegram:
|
.notify_telegram:
|
||||||
stage: .post
|
stage: .post
|
||||||
tags:
|
tags:
|
||||||
- tg
|
- tg
|
||||||
image: curlimages/curl:latest
|
image: curlimages/curl:latest
|
||||||
script:
|
script:
|
||||||
@@ -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
|
||||||
|
|
||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user