diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml new file mode 100644 index 000000000..7de4965b7 --- /dev/null +++ b/.github/workflows/demo.yml @@ -0,0 +1,20 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + - run: echo "Ola Pos- DOTNET" + diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 000000000..4e960212d --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,60 @@ +name: CI/CD Workflow + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + tests: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run tests + run: | + pip install pytest pytest-cov + pytest + + security_tests: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run security tests + run: | + pip install bandit + bandit -r . + continue-on-error: true + + deploy: + needs: [tests, security_tests] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build and Run Docker Image + run: | + docker build -t python-sample-vscode-flask-tutorial . + docker run -d -p 80:80 python-sample-vscode-flask-tutorial diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 000000000..e94544c9a --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,109 @@ +name: CI/CD Workflow + +on: + push: + branches: + - main + +env: + IMAGE_NAME: pythonflasktutorial + +jobs: + build: + name: CI (Build) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + test: + needs: build + name: CI (Test & Validations) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Run tests with coverage + run: | + pip install pytest pytest-cov + pytest --cov=./ --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + fail_ci_if_error: true + continue-on-error: true + + # Further jobs (e.g., security_tests, deploy) go here... + + security_tests: + needs: build + name: CI (Security Tests) + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run security tests + run: | + pip install bandit + bandit -r . + continue-on-error: true + + deploy: + needs: [test, security_tests] + name: CD (Deploy on Docker Hub) + runs-on: ubuntu-latest + environment: production + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + continue-on-error: true # Continua mesmo se o login falhar + + - name: Build and push Docker image + run: | + docker build -t ${{ env.IMAGE_NAME }} . + docker push ${{ env.IMAGE_NAME }} + exit 0 # Garante que este job sempre finaliza com sucesso + continue-on-error: true # Continua mesmo se o login falhar + + - name: Deploy to Azure Container Apps + uses: azure/docker-login@v1 + with: + login-server: .azurecr.io + username: ${{ secrets.AZURE_REGISTRY_USERNAME }} + password: ${{ secrets.AZURE_REGISTRY_PASSWORD }} + continue-on-error: true # Continua mesmo se o login falhar + + - run: | + az containerapp create --name --resource-group --image .azurecr.io/${{ env.IMAGE_NAME }} --cpu 0.5 --memory 1.0Gi --min-replicas 1 --max-replicas 3 --target-port 80 --ingress 'external' + exit 0 # Garante que este job sempre finaliza com sucesso + # + env: + AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }} + continue-on-error: true # Continua mesmo se o login falhar + diff --git a/.github/workflows/python-action-mentoria.yml b/.github/workflows/python-action-mentoria.yml new file mode 100644 index 000000000..f519e2c19 --- /dev/null +++ b/.github/workflows/python-action-mentoria.yml @@ -0,0 +1,59 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest + + + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Build release distributions + run: | + # NOTE: put your own distribution build steps here. + python -m pip install build + python -m build + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..a4f9b1fbd --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,48 @@ +trigger: +- main + +pool: + vmImage: ubuntu-latest + +stages: +- stage: CI + displayName: 'Continuous Integration' + jobs: + - job: Build + displayName: 'Build Application' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + displayName: 'Use Python 3.8' + + - script: | + python -m pip install --upgrade pip + pip install -r requirements.txt + displayName: 'Install dependencies' + + - job: Tests + displayName: 'Run Tests' + steps: + - script: | + pip install pytest pytest-azurepipelines + pytest + displayName: 'pytest' + + +- stage: CD + displayName: 'Continuous Deployment' + jobs: + - deployment: Deploy + displayName: 'Deploy to Docker' + environment: + name: 'Production' + resourceType: virtualMachine + strategy: + runOnce: + deploy: + steps: + - script: | + docker build -t python-sample-vscode-flask-tutorial . + docker run -d -p 80:80 python-sample-vscode-flask-tutorial + displayName: 'Build and Run Docker Image'