openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
798 stars 224 forks source link

Question: generating image tags from Git #955

Closed sebastianricaldoni closed 1 year ago

sebastianricaldoni commented 1 year ago

Expected Behaviour

I'm expecting to run faas-cli deploy to successfully deploy my function (pods, replicaset, etc)

Current Behaviour

My pod is not deployed and instead I get the following error

Failed to apply default image tag "myRepo/myService:latest-fatal: detected dubious ownership in repository at '/github/workspace'\nTo add an exception for this directory, call:\n\n\tgit config --global --add safe.directory /github/workspace": couldn't parse image reference "myRepo/myService:latest-fatal: detected dubious ownership in repository at '/github/workspace'\nTo add an exception for this directory, call:\n\n\tgit config --global --add safe.directory /github/workspace": invalid reference format

Why do you need this?

I need to be able to deploy newer versions of my functions. Something to note is that this all started happening a few days ago after faas-cli docker image was removed from Docker Hub and we started pulling the image from ghcr.io instead. It seems that, for some reason, the commit SHA is not properly determined or read and ends up rendering something as -fatal instead of -<COMMIT-SHA>

Who is this for?

What company is this for? Are you listed in the ADOPTERS.md file? I'm using this with my customers. And no, I don't seem to be listed in the adopters.md file

Are you a GitHub Sponsor (Yes/No?)

Check at: https://github.com/sponsors/openfaas

List All Possible Solutions and Workarounds

I'm not sure yet 🤷‍♂️

Which Solution Do You Recommend?

Honestly I've been using faas-cli without an issue. I'm definitely not an expert user. I have never committed any code to the project. I'm only using the "basic" out-of-the-box commands login , build, deploy

Steps to Reproduce (for bugs)

I'm using faas-cli inside a Github Action but not sure it is really a bug on faas-cli.

name: CI/CD on staging

on:
  workflow_dispatch:
  release:
    types: [published]

jobs:
  func-build:
    runs-on: ubuntu-latest    
    defaults:
      run:
        working-directory: './src'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '14'

      - name: Define ENV VARS
        id: define_env
        run:  echo "::set-output name=github-sha-short::$(echo $GITHUB_SHA | cut -c 1-7)"

      - name: Install dependencies
        run: npm install

      - name: Pull template
        uses: actions/checkout@v2
        with:
          repository: 'openfaas/templates'
          path: 'repo-templates'
          token: ${{ secrets.ACTIONS_CI_CD_ACCESS_TOKEN }}
          ref: 'main'

      - run: |
          cp -r ../repo-templates/template ../template
          rm -rf ../repo-templates

      - name: Run shrinkwrap build
        uses: docker://ghcr.io/openfaas/faas-cli:latest-root
        with:
          args: build -f my-function.yml --build-arg --shrinkwrap

      - name: Login to OpenFaaS Gateway
        uses: docker://ghcr.io/openfaas/faas-cli:latest-root
        with:
          args: login -p ${{ secrets.OPENFAAS_GATEWAY_PASSWD }} \
                      -g ${{ secrets.OPENFAAS_GATEWAY_URL }}

      - name: Login to DockerHub
        if: success()
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Build and Push the OpenFaaS function
        uses: docker/build-push-action@v2
        with:
          context: ./build/my-function/
          file: ./build/my-function/Dockerfile
          push: true
          tags: my/services-bulk-import-learners-api:latest-${{ steps.define_env.outputs.github-sha-short }}
          build-args: |
            NPM_AUTH_TOKEN=${{ secrets.NPM_CI_CD_ACCESS_TOKEN }}

      - name: Deploy the function
        uses: docker://ghcr.io/openfaas/faas-cli:latest-root
        with:
          args: deploy -f my-function.yml --tag sha --gateway ${{ secrets.OPENFAAS_GATEWAY_PROD }}

Context

Your Environment

I'm using this within Github Actions using ubuntu-latest (see here)

alexellis commented 1 year ago

/set title: Question: generating image tags from Git

alexellis commented 1 year ago

Hi thanks for your interest in OpenFaaS Community Edition.

I think this may be the first time we've heard about you using OpenFaaS CE as part of your business for your customers.

Could you send us a note to the ADOPTERS.md file?

One thing that looks inefficient is your use of the faas-cli as a container instead of as a binary on the host. It's probably why the tag is failing to resolve, because the .git directory isn't present or in context.

You can find our recommended GitHub Action here: https://docs.actuated.dev/examples/openfaas-publish/#try-out-the-action-on-your-agent

I'd also suggest that since you're using OpenFaaS CE commercially, and I assume want us to continue working on it for your benefit and your customers' benefit, that you review the sponsorship tiers to see what makes sense for you, custom amounts are also enabled.

Also it's worth noting that you may to be leaking the NPM_AUTH_TOKEN value in your images. We addressed that in OpenFaaS Pro.

Thanks

Alex

alexellis commented 1 year ago

One other thing I noticed is that you don't use faas-cli to generate the hash, so I'm going to close this issue.

You're using GitHub Actions to get the hash, and then you're also using the deprecated set-output directive.

Let us know if we can help further.

sebastianricaldoni commented 1 year ago

Thank you @alexellis for the prompt response! Sorry I wasn't able to reply earlier. Please find my comments below.

I think this may be the first time we've heard about you using OpenFaaS CE as part of your business for your customers. Could you send us a note to the ADOPTERS.md file? I will definitely send a note as you suggest. We met back on Nov 25th, 2021 where we held a zoom meeting and I ended up buying your book 🙌 . Back then I think you guys were using Slack?

One thing that looks inefficient is your use of the faas-cli as a container instead of as a binary on the host. It's probably why the tag is failing to resolve, because the .git directory isn't present or in context.

What you say makes total sense however, the "docker way" used to work before moving from docker hub to GHCR. I really don't know why 🤷‍♂️ . Having said that, I did follow your recommendation and now I'm installing faas-cli early on and then just calling faas-cli commands.

Bottomline all is working now! Thanks again!!

alexellis commented 1 year ago

Hi @sebastianricaldoni

There wasn't a change with the CLI, it's still working the same way.

There was a deprecation in GitHub Actions in which they've removed "set-output" as a valid way to set an environment variable. You need to migrate it to use a similar pattern to what we do in the linked docs.

Take a look at the sponsorship options, even if you think 25 USD / mo is the only value you get from our continued work, it all helps contribute to help all the free users like yourself who use the community version to make a business profit.

Alex