Skip to content

Commit

Permalink
Merge pull request #74 from software-students-spring2024/ydo
Browse files Browse the repository at this point in the history
updated deployment
  • Loading branch information
yurawu27 authored May 7, 2024
2 parents c5a4d55 + b68a083 commit d675354
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI for Backend
name: CI/CD for Backend

on:
push:
Expand Down Expand Up @@ -37,20 +37,4 @@ jobs:
- name: Run Black (Check mode)
run: black backend_api/
- name: Run tests
run: pytest tests/web_app_tests.py

# Additional step to log into Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Building Docker image for backend api and push to Docker Hub
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/webapp:latest
context: ./backend_api
file: ./backend_api/Dockerfile
run: pytest tests/web_app_tests.py
33 changes: 22 additions & 11 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,31 @@ jobs:
tags: ${{ secrets.DOCKER_USERNAME }}/webapp:latest
context: ./web_app
file: ./web_app/Dockerfile


# Deploy to Digital Ocean using SSH
- name: Deploy to Digital Ocean
uses: appleboy/[email protected]
# Building Docker image for backend api and push to Docker Hub
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/backend-api:latest
context: ./backend_api
file: ./backend_api/Dockerfile

- name: Deploy to Digital Ocean droplet
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USERNAME }}
key: ${{ secrets.DO_SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
password: ${{ secrets.DO_PWD }}
script: |
echo "MONGODB_USER=${{ secrets.MONGODB_USER }}" >> 5-final-project-spring-2024-berries/.env
echo "MONGO_PWD=${{ secrets.MONGO_PWD }}" >> 5-final-project-spring-2024-berries/.env
echo "DB_HOST=${{ secrets.DB_HOST }}" >> 5-final-project-spring-2024-berries/.env
echo "API_KEY=${{ secrets.API_KEY }}" >> 5-final-project-spring-2024-berries/.env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> 5-final-project-spring-2024-berries/.env
docker pull ${{ secrets.DOCKER_USERNAME }}/webapp:latest
docker stop web-app || true
docker rm web-app || true
docker run -d --name web-app -p 3000:3000 --restart unless-stopped ${{ secrets.DOCKER_USERNAME }}/webapp:latest
sleep 10
# curl http://localhost:3000/healthcheck
docker pull ${{ secrets.DOCKER_USERNAME }}/backend-api:latest
cd 5-final-project-spring-2024-berries
docker-compose down
docker-compose pull
docker-compose up -d
2 changes: 2 additions & 0 deletions backend_api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN pip install -r requirements.txt

COPY . .

ENV FLASK_APP google_api.py

EXPOSE 5002

CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0", "--port=5002"]
2 changes: 2 additions & 0 deletions web_app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN pip install -r requirements.txt

COPY . .

ENV FLASK_APP app.py

EXPOSE 5001

CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0", "--port=5001"]

0 comments on commit d675354

Please sign in to comment.