Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect .funcignore file rules #36

Closed
petyunchik opened this issue Jun 24, 2020 · 13 comments · Fixed by #56
Closed

Respect .funcignore file rules #36

petyunchik opened this issue Jun 24, 2020 · 13 comments · Fixed by #56
Assignees
Labels
bug Something isn't working

Comments

@petyunchik
Copy link

Patterns of .funcignore file are ignored during deployment and everything is included under package folder.
Would be nice to exclude files in accordance to .funcignore rules as it's implemented in Azure Functions Core Tools

@petyunchik
Copy link
Author

If someone looking for workaround try this:

    - name: Create Deployment Package
      shell: pwsh
      run: |
        npm install -g azure-functions-core-tools@3
        func pack

    - name: Deploy To Azure Functions
      uses: Azure/functions-action@v1
      with:
        app-name: your-app-name
        package: ${{ github.event.repository.name }}.zip

It will create and deploy package using Azure Functions Core Tools, which respects rules from .funcignore

@AmrutaKawade AmrutaKawade added bug Something isn't working and removed bug Something isn't working labels Sep 17, 2020
@aaronadamsCA
Copy link

aaronadamsCA commented Nov 22, 2020

Note the workaround does work, but it has to download the entire azure-functions-core-tools ZIP file on every run, which is also not ideal.

@aksm-ms
Copy link
Contributor

aksm-ms commented Dec 3, 2020

@N-Usha Can we mark this as an enhancement?

@maximivanov
Copy link

Here's a rsync trick I've used to exclude files listed in .funcignore from deployment. In your workflow file:

...

env:
  ...
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
  RELEASE_BUNDLE_PATH: 'release-bundle' # This is a new env var

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      ... checkout code, install, build ...

      # A new step to exclude files from deployment
      - name: Copy files to release bundle
        shell: bash
        run: |
          pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
          rsync -av --prune-empty-dirs --exclude-from .funcignore ./ ${{ env.RELEASE_BUNDLE_PATH }}
          popd

      - name: Run Azure Functions action
        uses: Azure/functions-action@v1
        id: fa
        with:
          app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
          package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/${{ env.RELEASE_BUNDLE_PATH }}' 
          publish-profile: ....

But I agree with @aaronadamsCA it should work out of the box without any tricks.

Rsync solution works well but unfortunately I've hit another blocker which is files do not get removed from the Azure Function App instance when they're removed in code: #33 (comment)

@aaronadamsCA
Copy link

@maximivanov I can confirm that with the workaround I'm using, files also don't get deleted during Kudu ZIP deploy, so I believe yours is definitely the cleaner solution until this issue is fixed.

For the other issue, I think projectkudu/kudu#3183 is the relevant issue to follow.

@N-Usha
Copy link
Contributor

N-Usha commented Dec 7, 2020

@Hazhzeng @anirudhgarg - Can you please confirm if this is a product limitation?

@Hazhzeng
Copy link
Contributor

Hazhzeng commented Dec 7, 2020

Thanks @petyunchik, I will look into this in the upcoming weeks

@maximivanov
Copy link

Thanks for looking into this.

I gave it a try and I can still see .funcignored files deployed to the target host.

Here's the repo to reproduce: https://github.com/maximivanov/azure-functions-cd-github-actions
respect-funcignore: true is set on the functions-action in the workflow file.
Among others, .funcignore includes .gitignore.

Once cloud resources are provisioned (I use Terraform for that), I trigger the CD workflow in the repo.

Expected: .gitignore is not deployed.
Actual: I can see .gitignore in the app files section in the Portal.

Screen Shot 2020-12-18 at 22 34 42

@N-Usha @Hazhzeng

@hcs-bernardo-rufino
Copy link

hcs-bernardo-rufino commented Sep 9, 2022

@petyunchik

Yes, .funcignore is not respected. But that doesn't mean you can't do it with other standard ways to ignore any unwanted file.

The following workflow build and deploy a python app to a dev slot on Azure Function app, when pushed to main branch on GitHub, without a .funcignore file (you can adapt it to your app), and without the rync trick (@maximivanov).

The main part for ignoring is the last part on build stage (specifically the path part):

- name: Upload artifact for deployment job
  uses: actions/upload-artifact@v2
  with:
    name: ${{ env.APP_INTERNAL_NAME }}
    path: |
      . 
      !venv/
      !README.md
      !.gitignore

It adds everything (with .), and ignores '.venv' folder, README.md (which is only important for GitHub), and .gitignore (which also is only important for GitHub).

name: Deploy Python app to Azure Function app (dev/stage slot)

on:
  push:
    branches:
      - main
    workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_NAME: test-app 
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
  PYTHON_VERSION: '3.9'
  APP_INTERNAL_NAME: 'test-app'

jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Setup Python ${{ env.PYTHON_VERSION }} Enviroment
        uses: actions/setup-python@v1
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate

      - name: Install dependencies
        run: pip install -r requirements.txt
        
      # Tests here

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: ${{ env.APP_INTERNAL_NAME }}
          path: |
            . 
            !venv/
            !README.md
            !.gitignore

  deploy:
    runs-on: ubuntu-20.04
    needs: build
    environment: 'dev'

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: ${{ env.APP_INTERNAL_NAME }}
          path: .

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
          slot-name: 'dev'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE_DEV }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

@ericthomas1
Copy link

Ideally, developers would be able to .funcignore files rather then involving DevOps and editing pipelines.

Example:

  • After a Function is deployed, end-to-end through DevOps pipelines, the developer adds a /docs directory to the repo.
  • Ideally we don't need to involve DevOps with this simple change (no ticket needed, no testing needed, etc.).
  • Developer just adds a /docs to the .funcignore file
  • Later down the road, a /tools directory is added to the repo for debugging / validation /etc.
  • Dev adds /tools to the .funcignore file and all good

Can files and directories be added to .funcignore to omit them from the deployed Function? Or does the DevOps pipeline need to be edited whenever a file/directory needs to be omitted?

@ethanabrooks
Copy link

Why is this issue closed? As far as I can tell, .funcignore is still not respected.

@cicorias
Copy link
Member

why even create the .funcignore file?

@tomvsaji
Copy link

this is still an issue when pushing code to azure functions from vs code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.