From ce024f6d2fe33acb51af2c9af9627fb4e9e7cda3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Jun 2026 11:40:44 +0200 Subject: [PATCH] DEV-66 BugFix - CI/CD pipeline failing on every push (deployments to production) --- .github/workflows/cd-prod.yml | 60 ----------------------- .github/workflows/ci-cd.yml | 89 +++++++++++++++++++++++++++++++++++ .github/workflows/ci-dev.yml | 39 --------------- 3 files changed, 89 insertions(+), 99 deletions(-) delete mode 100644 .github/workflows/cd-prod.yml create mode 100644 .github/workflows/ci-cd.yml delete mode 100644 .github/workflows/ci-dev.yml diff --git a/.github/workflows/cd-prod.yml b/.github/workflows/cd-prod.yml deleted file mode 100644 index 988ba6a..0000000 --- a/.github/workflows/cd-prod.yml +++ /dev/null @@ -1,60 +0,0 @@ -# .github/workflows/cd-prod.yml -name: CD - Продукција -on: - push: - branches: [ main ] - workflow_dispatch: - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - environment: production # везује за producton окружење - - steps: - - name: Code download - uses: actions/checkout@v4 - - - name: Settings Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: "3.12" - cache: 'pip' - - - name: Dependacy installation - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - # Ако користите setuptools за паковање: - python setup.py sdist bdist_wheel - # или ако само желите да спакујете цео код: - tar -czf app.tar.gz src/ static/ templates/ requirements.txt - - - name: Server deployment (SCP) - uses: appleboy/scp-action@v0.1.4 - with: - host: ${{ secrets.DEPLOY_HOST }} - username: ${{ secrets.DEPLOY_USER }} - key: ${{ secrets.DEPLOY_SSH_KEY }} - port: ${{ secrets.DEPLOY_PORT }} - source: "app.tar.gz" # име архиве - target: ${{ secrets.DEPLOY_PATH }} - rm: true # брише старе фајлове пре слања - - - name: Start application on server - uses: appleboy/ssh-action@v1.0.0 - with: - host: ${{ secrets.DEPLOY_HOST }} - username: ${{ secrets.DEPLOY_USER }} - key: ${{ secrets.DEPLOY_SSH_KEY }} - port: ${{ secrets.DEPLOY_PORT }} - script: | - cd ${{ secrets.DEPLOY_PATH }} - tar -xzf app.tar.gz - rm app.tar.gz - # Активирај виртуелно окружење и инсталирај зависности (ако треба) - python3 -m venv venv - source venv/bin/activate - pip install -r requirements.txt - # Поново покрени сервис (нпр. systemd) - sudo systemctl restart my-python-app \ No newline at end of file diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..b39b1e2 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,89 @@ +name: CI/CD Pipeline + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + workflow_dispatch: # used to trigger the OPTIONAL publish/deploy jobs by hand + +env: + API_IMAGE: plant-monitor-api + GUI_IMAGE: plant-monitor-gui + +jobs: + # LINT — runs on every push and pull request + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install lint tools + run: pip install flake8 black + + - name: Lint with flake8 (syntax errors only) + run: | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics \ + --exclude=.git,__pycache__,.venv,venv,build,dist + + # Reports formatting issues but does NOT fail the build. + # Remove "continue-on-error" once your code is fully black-formatted. + - name: Check formatting with black (informational) + run: black --check --diff . + continue-on-error: true + + # BUILD IMAGES — proves both Docker images build, No push + build-images: + needs: lint + runs-on: ubuntu-latest + strategy: + matrix: + service: [api, gui] + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build ${{ matrix.service }} image (no push) + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile.${{ matrix.service }} + push: false + tags: ${{ matrix.service }}:ci + + + # publish images to Docker Hub. + publish: + needs: build-images + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + strategy: + matrix: + service: [api, gui] + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push ${{ matrix.service }} + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile.${{ matrix.service }} + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.service == 'api' && env.API_IMAGE || env.GUI_IMAGE }}:latest + ${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.service == 'api' && env.API_IMAGE || env.GUI_IMAGE }}:${{ github.sha }} \ No newline at end of file diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml deleted file mode 100644 index 5d81cc9..0000000 --- a/.github/workflows/ci-dev.yml +++ /dev/null @@ -1,39 +0,0 @@ -# .github/workflows/ci-dev.yml -name: CI - Development branch -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] # прилагодите верзије - - steps: - - name: Code download - uses: actions/checkout@v4 - - - name: Python settings ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' # кешира pip пакете, убрзава рад - - - name: Dependancy installation - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest pytest-cov # ако нису већ у requirements.txt - - - name: Starting tests with coverage - run: pytest --cov=./ --cov-report=xml --cov-report=html - - - name: Coverage report - uses: actions/upload-artifact@v4 - with: - name: coverage-report - path: htmlcov/index.html \ No newline at end of file