From 97a776415571df123f6de4b75580b1ff602ca886 Mon Sep 17 00:00:00 2001 From: Aleksandr Meshchriakov Date: Mon, 2 Feb 2026 12:39:06 +0100 Subject: [PATCH] fix(ci): replace GitHub Actions with native bash commands - Remove dependency on GitHub (network blocks access) - Replace actions/checkout@v4 with git clone - Replace actions/setup-python@v4 with apt-get install - Replace docker/build-push-action with native docker commands - Use config.settings.test (SQLite in-memory) for tests Closes: network connectivity issue in CI --- .gitea/workflows/ci-cd.yml | 251 ++++++++++++------------------------- CHANGELOG.md | 13 ++ 2 files changed, 93 insertions(+), 171 deletions(-) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 971d6f7..7560bce 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ main, develop ] +env: + PYTHON_VERSION: "3.11" + jobs: lint: name: Code Quality Checks @@ -13,110 +16,66 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Install uv run: | + git clone --depth=1 --branch=${GITHUB_REF_NAME} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git . + git checkout ${GITHUB_SHA} + + - name: Install Python and uv + run: | + apt-get update && apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-venv curl -LsSf https://astral.sh/uv/install.sh | sh - echo "$HOME/.local/bin" >> $GITHUB_PATH + export PATH="$HOME/.local/bin:$PATH" - - name: Create virtual environment - run: uv venv - - - name: Activate virtual environment and install dependencies + - name: Create virtual environment and install dependencies run: | + export PATH="$HOME/.local/bin:$PATH" + uv venv --python python${PYTHON_VERSION} source .venv/bin/activate uv sync --dev - name: Run Ruff linting run: | + export PATH="$HOME/.local/bin:$PATH" source .venv/bin/activate ruff check . - name: Run Ruff formatting check run: | + export PATH="$HOME/.local/bin:$PATH" source .venv/bin/activate ruff format . --check test: name: Run Tests runs-on: ubuntu-latest - services: - postgres: - image: postgres:15.10 - env: - POSTGRES_DB: test_db - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - redis: - image: redis:7-alpine - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 6379:6379 steps: - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Install uv run: | + git clone --depth=1 --branch=${GITHUB_REF_NAME} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git . + git checkout ${GITHUB_SHA} + + - name: Install Python and uv + run: | + apt-get update && apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-venv curl -LsSf https://astral.sh/uv/install.sh | sh - echo "$HOME/.local/bin" >> $GITHUB_PATH + export PATH="$HOME/.local/bin:$PATH" - - name: Create virtual environment - run: uv venv - - - name: Activate virtual environment and install dependencies + - name: Create virtual environment and install dependencies run: | + export PATH="$HOME/.local/bin:$PATH" + uv venv --python python${PYTHON_VERSION} source .venv/bin/activate uv sync --dev - - name: Wait for services to be ready - run: | - # Wait for PostgreSQL - until pg_isready -h localhost -p 5432 -U postgres; do - echo "Waiting for PostgreSQL..." - sleep 2 - done - - # Wait for Redis - until redis-cli -h localhost -p 6379 ping; do - echo "Waiting for Redis..." - sleep 2 - done - - name: Run Django tests run: | + export PATH="$HOME/.local/bin:$PATH" source .venv/bin/activate cd src python manage.py test --verbosity=2 env: - DJANGO_SETTINGS_MODULE: config.settings.development - DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db - REDIS_URL: redis://localhost:6379/0 - CELERY_BROKER_URL: redis://localhost:6379/0 + DJANGO_SETTINGS_MODULE: config.settings.test SECRET_KEY: test-secret-key-for-ci build: @@ -126,56 +85,21 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Extract metadata for web image - id: meta-web - uses: docker/metadata-action@v5 - with: - images: | - ${{ github.repository_owner }}/mostovik-web - tags: | - type=ref,event=branch - type=ref,event=pr - type=sha,prefix={{branch}}- - - - name: Extract metadata for celery image - id: meta-celery - uses: docker/metadata-action@v5 - with: - images: | - ${{ github.repository_owner }}/mostovik-celery - tags: | - type=ref,event=branch - type=ref,event=pr - type=sha,prefix={{branch}}- + run: | + git clone --depth=1 --branch=${GITHUB_REF_NAME} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git . + git checkout ${GITHUB_SHA} - name: Build web image - uses: docker/build-push-action@v5 - with: - context: . - file: ./docker/Dockerfile.web - push: false - load: true - tags: ${{ steps.meta-web.outputs.tags }} - labels: ${{ steps.meta-web.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + run: | + BRANCH_TAG=$(echo ${GITHUB_REF_NAME} | sed 's/\//-/g') + SHA_SHORT=$(echo ${GITHUB_SHA} | cut -c1-7) + docker build -f ./docker/Dockerfile.web -t mostovik-web:${BRANCH_TAG} -t mostovik-web:${BRANCH_TAG}-${SHA_SHORT} . - name: Build celery image - uses: docker/build-push-action@v5 - with: - context: . - file: ./docker/Dockerfile.celery - push: false - load: true - tags: ${{ steps.meta-celery.outputs.tags }} - labels: ${{ steps.meta-celery.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + run: | + BRANCH_TAG=$(echo ${GITHUB_REF_NAME} | sed 's/\//-/g') + SHA_SHORT=$(echo ${GITHUB_SHA} | cut -c1-7) + docker build -f ./docker/Dockerfile.celery -t mostovik-celery:${BRANCH_TAG} -t mostovik-celery:${BRANCH_TAG}-${SHA_SHORT} . push: name: Push to Gitea Registry @@ -185,63 +109,48 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + run: | + git clone --depth=1 --branch=${GITHUB_REF_NAME} ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git . + git checkout ${GITHUB_SHA} - name: Login to Gitea Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ vars.GITEA_REGISTRY_URL }} - username: ${{ secrets.GITEA_USERNAME }} - password: ${{ secrets.GITEA_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Extract metadata for web image - id: meta-web - uses: docker/metadata-action@v5 - with: - images: | - ${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository_owner }}/mostovik-web - tags: | - type=ref,event=branch - type=sha,prefix={{branch}}- - type=raw,value=latest,enable={{is_default_branch}} - - - name: Extract metadata for celery image - id: meta-celery - uses: docker/metadata-action@v5 - with: - images: | - ${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository_owner }}/mostovik-celery - tags: | - type=ref,event=branch - type=sha,prefix={{branch}}- - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push web image - uses: docker/build-push-action@v5 - with: - context: . - file: ./docker/Dockerfile.web - push: true - tags: ${{ steps.meta-web.outputs.tags }} - labels: ${{ steps.meta-web.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build and push celery image - uses: docker/build-push-action@v5 - with: - context: . - file: ./docker/Dockerfile.celery - push: true - tags: ${{ steps.meta-celery.outputs.tags }} - labels: ${{ steps.meta-celery.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Image digest run: | - echo "Web image digest: ${{ steps.docker_build_web.outputs.digest }}" - echo "Celery image digest: ${{ steps.docker_build_celery.outputs.digest }}" + echo "${{ secrets.GITEA_TOKEN }}" | docker login ${{ vars.GITEA_REGISTRY_URL }} -u ${{ secrets.GITEA_USERNAME }} --password-stdin + + - name: Build and push images + run: | + BRANCH_TAG=$(echo ${GITHUB_REF_NAME} | sed 's/\//-/g') + SHA_SHORT=$(echo ${GITHUB_SHA} | cut -c1-7) + REGISTRY="${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository_owner }}" + + # Build and push web image + docker build -f ./docker/Dockerfile.web \ + -t ${REGISTRY}/mostovik-web:${BRANCH_TAG} \ + -t ${REGISTRY}/mostovik-web:${BRANCH_TAG}-${SHA_SHORT} \ + . + docker push ${REGISTRY}/mostovik-web:${BRANCH_TAG} + docker push ${REGISTRY}/mostovik-web:${BRANCH_TAG}-${SHA_SHORT} + + # Tag as latest if main branch + if [ "${GITHUB_REF_NAME}" = "main" ]; then + docker tag ${REGISTRY}/mostovik-web:${BRANCH_TAG} ${REGISTRY}/mostovik-web:latest + docker push ${REGISTRY}/mostovik-web:latest + fi + + # Build and push celery image + docker build -f ./docker/Dockerfile.celery \ + -t ${REGISTRY}/mostovik-celery:${BRANCH_TAG} \ + -t ${REGISTRY}/mostovik-celery:${BRANCH_TAG}-${SHA_SHORT} \ + . + docker push ${REGISTRY}/mostovik-celery:${BRANCH_TAG} + docker push ${REGISTRY}/mostovik-celery:${BRANCH_TAG}-${SHA_SHORT} + + # Tag as latest if main branch + if [ "${GITHUB_REF_NAME}" = "main" ]; then + docker tag ${REGISTRY}/mostovik-celery:${BRANCH_TAG} ${REGISTRY}/mostovik-celery:latest + docker push ${REGISTRY}/mostovik-celery:latest + fi + + - name: Image summary + run: | + echo "Images pushed to ${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository_owner }}/" diff --git a/CHANGELOG.md b/CHANGELOG.md index 942147a..0bf5a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ --- +## [0.4.1] - 2026-02-02 + +### Исправлено + +#### CI/CD Pipeline +- Удалена зависимость от GitHub Actions (сеть блокирует доступ к GitHub) +- `actions/checkout@v4` → `git clone` с переменными Gitea +- `actions/setup-python@v4` → установка через `apt-get` +- `docker/build-push-action@v5` → чистые `docker build/push` команды +- Тесты используют `config.settings.test` (SQLite in-memory) вместо PostgreSQL service + +--- + ## [0.4.0] - 2026-01-28 ### Добавлено