0

I have a Django Project and created a dev branch. In my .gitignore file I have the "media" folder. My project looks like this:

- Django Project/
    - app1/
    - app2/
    - media/
        - profile_pics/
        - default.jpg
    - .gitignore

In my gitignore I added media.

I've been trying to add github actions, so I created this ci.yml

name: Testing
on: push

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.6, 3.7, 3.8]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Run Tests
      run: |
        python manage.py test

When I push the repo I received this message from Github Actions:

FileNotFoundError: [Errno 2] No such file or directory: '****/media/default.jpg'

What is the best way to deal with this?

I could use git add media -f but I do not know if then this file would be in my repo and when I merge it with main and deploy it I would have that folder and overwrites the media in deployment.

1 Answer 1

2

Remove your media directory from .gitignore so that it is tracked by Git. It sounds like you need that directory for your project to successfully build.

If you're concerned about large artifacts, then see also git lfs (large file storage) supported by GitHub. Either way, you need to fix your .gitignore.

2
  • Thank you very much! I'm using media to store pictures of new users. I want to use Github actions to automate the deployment of my app after all tests pass. What would happen if I create a "feature" branch (and when ready I want to merge it and deploy the app) if someone in between has uploaded a new profile picture? Would this branch overwrite the media folder deleting the new profile pics or create other kind of conflict?
    – juancopi81
    Oct 31, 2020 at 20:26
  • That sounds like something that is typically gitignored. I would modify the app so that it references profile pictures in an alternate source such as a CDN (like an Amazon S3 bucket for example). And then your app will not require those to be files on a disk. Your build will pass referencing remote images. That would also require updating how pictures get uploaded so that they're put in a CDN on upload.
    – Sam Gleske
    Nov 2, 2020 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.