Skip to content

Merge branch 'main' of https://github.com/InSange/PigBrothers #157

Merge branch 'main' of https://github.com/InSange/PigBrothers

Merge branch 'main' of https://github.com/InSange/PigBrothers #157

name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Check out the repository
- name: Check out repository
uses: actions/checkout@v3
# Set up Python environment
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12
# Install dependencies
- name: Install dependencies
run: |
cd backend
python3 -m venv pig
source pig/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
# Create .env file from GitHub Secrets
- name: Generate .env file
run: |
echo "TYPE=${{ secrets.TYPE }}" >> backend/.env
echo "PROJECT_ID=${{ secrets.PROJECT_ID }}" >> backend/.env
echo "PRIVATE_KEY=${{ secrets.PRIVATE_KEY }}" | sed ':a;N;$!ba;s/\n/\\n/g' >> backend/.env
echo "CLIENT_EMAIL=${{ secrets.CLIENT_EMAIL }}" >> backend/.env
echo "CLIENT_ID=${{ secrets.CLIENT_ID }}" >> backend/.env
echo "AUTH_URI=${{ secrets.AUTH_URI }}" >> backend/.env
echo "TOKEN_URI=${{ secrets.TOKEN_URI }}" >> backend/.env
echo "AUTH_PROVIDER_X509_CERT_URL=${{ secrets.AUTH_PROVIDER_X509_CERT_URL }}" >> backend/.env
echo "CLIENT_X509_CERT_URL=${{ secrets.CLIENT_X509_CERT_URL }}" >> backend/.env
echo "UNIVERSE_DOMAIN=${{ secrets.UNIVERSE_DOMAIN }}" >> backend/.env
echo ".env file created successfully."
# Debug .env file content (temporary for debugging purposes)
- name: Debug .env file
run: |
cat backend/.env || echo "Failed to read .env file."
# Build Docker image
- name: Build Docker image
run: |
cd backend
docker build --no-cache -t pig:latest .
# Run Docker container using .env file
- name: Deploy Docker container
run: |
ls
cat ./backend/.env
docker run -d --name pig_app -p 8000:8000 --env-file backend/.env pig:latest
# Check Docker container logs
- name: Fetch Docker logs
run: |
docker logs pig_app || echo "No logs available."
# Verify if the Docker container is running
- name: Verify Container Status
run: |
if [ -z "$(docker ps -q -f name=pig_app)" ]; then
echo "Container is not running."
docker ps -a
docker logs pig_app || echo "No logs available."
exit 1
else
echo "Container is running."
docker ps
fi
# Test container health (curl HTTP test)
- name: Test Container Health
run: |
curl -I http://localhost:8000 || echo "Application not responding."