Home>

Greetings to all who are not indifferent. I want to immediately clarify that I am new to this environment, so do not judge strictly.

Ran into a problem while trying to CI/CD in github-actions. The last jobs throws an error:

======CMD======
sudo docker-compose stop
sudo docker-compose rm web
touch.env
echo DB_ENGINE=*** >> .env
echo DB_NAME=*** >> .env
echo POSTGRES_USER= >> .env
echo POSTGRES_PASSWORD= >> .env
echo DB_HOST=*** >> .env
echo DB_PORT=*** >> .env
sudo docker-compose up -d
======END======
out: No stopped containers
err: Building web
err: unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/Dockerfile: no such file or directory
err: Service 'web' failed to build : Build failed
2022/01/25 11:24:13 Process exited with status 1

The project structure is as follows:

current workflow.yml:

name: Django-app workflow
on: [push]
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
    -uses: actions/[email protected]
    -name: Set up Python
      uses: actions/[email protected]
      with:
        python-version: 3.7
    -name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8 pep8-naming flake8-broken-line flake8-return flake8-isort
        cd api_yamdb/
        pip install -r requirements.txt
    -name: Test with flake8 and django tests
      run: |
        python -m flake8
        pytest
        cd api_yamdb/
        python manage.py test
  build_and_push_to_docker_hub:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    needs: tests
    steps:
      -name: Check out the repo
        uses: actions/[email protected]
      -name: Set up Docker Buildx
        uses: docker/[email protected]
      -name: Login to Docker
        uses: docker/[email protected]
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD}}
      -name: Push to Docker Hub
        uses: docker/[email protected]
        with:
          context: ./api_yamdb
          file: ./api_yamdb/Dockerfile
          push: true
          tags: ${{ secrets.DOCKER_USERNAME }}/yamdb_final:latest
  deploy:
    runs-on: ubuntu-latest
    needs: build_and_push_to_docker_hub
    if: github.ref== 'refs/heads/master' || github.ref== 'refs/heads/main'
    steps:
    -name: executing remote ssh commands to deploy
      uses: appleboy/[email protected]
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USER }}
        key: ${{ secrets.SSH_KEY }}
        passphrase: ${{ secrets.PASSPHRASE }}
        script: |
          sudo docker-compose stop
          sudo docker-compose rm web
          touch.env
          echo DB_ENGINE=${{ secrets.DB_ENGINE }} >> .env
          echo DB_NAME=${{ secrets.DB_NAME }} >> .env
          echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
          echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
          echo DB_HOST=${{ secrets.DB_HOST }} >> .env
          echo DB_PORT=${{ secrets.DB_PORT }} >> .env
          sudo docker-compose up -d

current docker-compose.yml:

version: '3.8'
services:
  db:
    image:postgres:13.0-alpine
    volumes:
      -db_data:/var/lib/postgresql/data/
    env_file:
      -.env
  web:
    image: ${{ secrets.DOCKER_USERNAME }}/yamdb_final:latest
    restart: always
    volumes:
      -static_value:/app/static/
      -media_value:/app/media/
    depends_on:
      -db
    env_file:
      -.env
  nginx:
    image:nginx:1.21.3
    ports:
      -"80:80"
    volumes:
      -./nginx/default.conf:/etc/nginx/conf.d/default.conf
      -static_value:/var/html/static/
      -media_value:/var/html/media/
    depends_on:
      -web
volumes:static_value: media_value:
  db_data:

current Dockerfile:

FROM python:3.7-slim
WORKDIR /app
COPY. .
RUN pip3 install -r /app/requirements.txt --no-cache-dir
CMD ["gunicorn", "api_yamdb.wsgi:application", "--bind", "0:8000" ]

At first glance, the problem is obvious -it does not see the Dockerfile, but what I do -nothing helps, unfortunately.