-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
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
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 |