Skip to content

Full build with test and removed waiting in deploy.yml #15

Full build with test and removed waiting in deploy.yml

Full build with test and removed waiting in deploy.yml #15

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: ["main"]
jobs:
build-test-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# --- 1. BUILD (Includes your Code + Tests) ---
- name: Build Docker Image
run: docker build -t test-image:latest .
# --- 2. TEST (Inside the container) ---
- name: Run Unit Tests
run: docker run --rm test-image:latest python -m pytest
# --- 3. PUSH (Only if tests passed) ---
- name: Push to Docker Hub
run: |
docker tag test-image:latest aaren17/devops-demo:latest
docker push aaren17/devops-demo:latest
deploy:
needs: build-test-push
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu
docker compose pull
docker compose up -d