updated ci.yml #65
This file contains hidden or 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: CI Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
# Build Stage | |
build: | |
name: Build and Push Docker Image to Docker Hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker Hub Login | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_API_KEY }} | |
- name: Build and Push Docker image | |
run: | | |
docker buildx build \ | |
--platform linux/amd64 \ | |
--file development/Dockerfile.prod \ | |
--tag ${{ secrets.DOCKER_USERNAME }}/myapp:latest \ | |
--push \ | |
. | |
# Test Stage | |
test: | |
name: Test and Lint | |
runs-on: ubuntu-latest | |
needs: build # Wait for build stage to complete | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_DB: users | |
POSTGRES_USER: runner | |
POSTGRES_PASSWORD: runner | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd="pg_isready -U runner" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
env: | |
DATABASE_URL: ${{ vars.DATABASE_URL}} | |
DJANGO_ALLOWED_HOSTS: ${{ vars.DJANGO_ALLOWED_HOSTS }} | |
SECRET_KEY: ${{ secrets.SECRET_KEY }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' # Adjust as needed | |
- name: Install dependencies | |
run: | | |
pip install -r app/requirements.txt | |
- name: Run tests with Pytest | |
run: | | |
cd app | |
pytest -p no:warnings --cov=. | |
- name: Run Black | |
run: | | |
cd app | |
black --check . --exclude 'movies/migrations' | |
- name: Run Ruff (including isort) | |
run: | | |
cd app | |
ruff check . --fix --exclude 'tests/*,movies/migrations/*,tasks.py,drf_project/settings.py' | |
# Release Stage | |
release: | |
name: Release Docker Image | |
runs-on: ubuntu-latest | |
needs: test # Wait for test job to complete | |
steps: | |
- name: Docker Hub Login | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_API_KEY }} | |
- name: Pull Docker image | |
run: | | |
docker pull ${{ secrets.DOCKER_USERNAME }}/myapp:latest | |
- name: Deploy to Heroku | |
run: | | |
heroku container:push web --app ${{ secrets.HEROKU_APP_NAME }} | |
heroku container:release web --app ${{ secrets.HEROKU_APP_NAME }} |