diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 215e7a8..39748a6 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -1,4 +1,4 @@ -name: CI for Backend +name: CI/CD for Backend on: push: @@ -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 \ No newline at end of file + run: pytest tests/web_app_tests.py \ No newline at end of file diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 97e62af..0d9874c 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -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/ssh-action@v1.0.3 + # 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 \ No newline at end of file + 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 diff --git a/backend_api/Dockerfile b/backend_api/Dockerfile index 99c08a6..88f76e5 100644 --- a/backend_api/Dockerfile +++ b/backend_api/Dockerfile @@ -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"] diff --git a/web_app/Dockerfile b/web_app/Dockerfile index 2c096b5..8863551 100644 --- a/web_app/Dockerfile +++ b/web_app/Dockerfile @@ -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"]