Sobes.tech
Middle+

Describe the process of setting up CI/CD for a development team: an application in Python needs to be delivered to a test environment.

sobes.tech AI

Answer from AI

The process of setting up CI/CD for a Python application with deployment to a test environment can be broken down into several stages:

  1. Choosing a CI/CD tool — for example, GitLab CI, Jenkins, GitHub Actions, CircleCI.

  2. Repository setup — the code should be in a version control system (Git).

  3. Pipeline configuration:

    • Build and dependency installation: create a virtual environment, install dependencies from requirements.txt or Pipfile.
    • Run tests: automatically run unit and integration tests.
    • Build artifacts: if needed, package the application (e.g., into a Docker image).
  4. Deployment to the test environment:

    • If the test environment is a server, configure deployment via SSH, SCP, or use Docker/Kubernetes.
    • Automate updating the application on the environment after successful tests.
  5. Monitoring and notifications: set up notifications about build and deployment status.

Example of a simple .gitlab-ci.yml for Python:

stages:
  - test
  - deploy

test_job:
  stage: test
  image: python:3.9
  script:
    - python -m venv venv
    - source venv/bin/activate
    - pip install -r requirements.txt
    - pytest

deploy_job:
  stage: deploy
  script:
    - scp -r ./app user@test-server:/path/to/deploy
  only:
    - main

This pipeline first runs tests, then upon push to the main branch, copies the application to the test server.