feat: enhance GitHub Actions workflow to build, scan, and push Docker… #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Scan, and Push Docker Image to GHCR | |
on: | |
push: | |
branches: | |
- main | |
env: | |
REGISTRY: ghcr.io | |
REPOSITORY: ${{ github.repository }} | |
TAG: latest | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pytest | |
- name: Run unit tests | |
run: | | |
pytest --maxfail=1 --disable-warnings || exit 1 | |
- name: Log in to GitHub Container Registry | |
if: success() | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.SCX_GITHUB_USERNAME }} | |
password: ${{ secrets.SCX_GITHUB_TOKEN }} | |
- name: Build Docker image | |
if: success() | |
run: | | |
docker build -t ghcr.io/scholarx-assesment/student-service:latest . | |
- name: Scan Docker image with Trivy | |
if: success() | |
uses: aquasecurity/trivy-action@0.28.0 | |
with: | |
image-ref: ghcr.io/scholarx-assesment/student-service:latest | |
severity: HIGH,CRITICAL | |
- name: Push Docker image | |
if: success() | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/scholarx-assesment/student-service:latest |