Skip to content

Commit

Permalink
add CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfril committed Jun 21, 2024
1 parent aea6e0e commit 8412914
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI/CD Pipeline

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/web-scraping:latest

- name: Deploy to EC2
env:
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
EC2_PORT: ${{ secrets.EC2_PORT }}
run: |
echo "${EC2_SSH_KEY}" > key.pem
chmod 600 key.pem
ssh -o StrictHostKeyChecking=no -i key.pem ${EC2_USER}@${EC2_HOST} -p ${EC2_PORT} << 'EOF'
docker pull ${{ secrets.DOCKER_USERNAME }}/web-scraping:latest
docker stop web-scraping || true
docker rm web-scraping || true
docker run -d -p 3000:3000 --name web-scraping ${{ secrets.DOCKER_USERNAME }}/web-scraping:latest
EOF

0 comments on commit 8412914

Please sign in to comment.