Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/push-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
IMAGE_NAME: 'python-fastapi'
IMAGE_OWNER: 'alexjelani'


jobs:
Expand All @@ -27,7 +28,7 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
images: ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}

# Login against a Docker registry
- name: Log into registry ${{ env.REGISTRY }}
Expand All @@ -42,17 +43,17 @@ jobs:
# Build and tag Docker Image
- name: Build Docker Image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
docker build -t ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .

- name: Tag Docker Image
run: |
docker tag ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
docker tag ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:testing
docker tag ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ github.sha }} ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:latest
docker tag ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ github.sha }} ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:testing


# Push the Docker image to the registry
- name: Push Docker Image to GHCR
run: |
docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:testing
docker push ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker push ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:latest
docker push ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:testing
47 changes: 47 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SonarCloud Scan

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
sonarcloud:
name: SonarCloud Scan
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov

- name: Run tests with coverage
run: |
pytest --cov=./ --cov-report=xml

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v5
with:
projectBaseDir: .
extraProperties: |
sonar.projectKey=alexjelani_python-fastapi
sonar.sources=.
sonar.python.coverage.reportPaths=coverage.xml
sonar.tests=tests
sonar.test.inclusions=tests/**/*.py
sonar.sourceEncoding=UTF-8
sonar.exclusions=.github/**,tests/**
sonar.login=${{ secrets.SONAR_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/unit-sec-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Build Docker Image
run: |
docker build -t python-fastapi:${{ github.sha }} .
docker run -d -p 8080:8080 python-fastapi:${{ github.sha }}
docker run -d -p 8000:8000 python-fastapi:${{ github.sha }}

- name: Wait for Docker container to be ready
run: sleep 30
Expand All @@ -72,7 +72,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
docker_name: 'ghcr.io/zaproxy/zaproxy:stable'
format: openapi
target: 'http://0.0.0.0:8080'
target: 'http://127.0.0.1:8000'
rules_file_name: '.zap/rules.tsv'
cmd_options: '-a'
allow_issue_writing: false
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ RUN pip install --no-cache-dir -r requirements.txt
# Copy the current directory contents into the container
COPY . .

# Expose port 8080 to the outside world
EXPOSE 8080
# Expose port 8000 to the outside world
EXPOSE 8000

# Run app.py when the container launches
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]