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

{{defaultContext}} is invalid yaml #541

Closed
deviantintegral opened this issue Jan 18, 2022 · 8 comments · Fixed by #552
Closed

{{defaultContext}} is invalid yaml #541

deviantintegral opened this issue Jan 18, 2022 · 8 comments · Fixed by #552

Comments

@deviantintegral
Copy link

Troubleshooting

Before submitting a bug report please read the Troubleshooting doc.

Behaviour

I'm trying the new {{defaultContext}} variable to build an image in a subdirectory with a git context: https://github.com/marketplace/actions/build-and-push-docker-images#usage

However, even a basic example throws "You have an error in your yaml syntax". I thought perhaps it needed to be a quoted string, and while that resolves the syntax error the action doesn't replace the template variable.

Steps to reproduce this issue

  1. Try to build with the following workflow: https://github.com/pbkhrv/rtl_433-hass-addons/blob/73a51d224f55e2f10d4ed85fd5be7aa76902a8f5/.github/workflows/builder.yml
  2. See the error in the related build log: https://github.com/pbkhrv/rtl_433-hass-addons/actions/runs/1712808308

Expected behaviour

The default string shown in the docs should work.

Configuration

name: Build rtl_433 images

on:
  push:
  pull_request:

jobs:
  build:
    name: Build rtl_433 addon
    runs-on: ubuntu-latest

    steps:

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

    -
      name: Build and push
      uses: docker/build-push-action@v2
      with:
        context: {{defaultContext}}:rtl_433
        platforms: linux/amd64,linux/arm64
        push: false
        tags: |
          ghcr.io/pbkhrv/rtl_433-hass-addons:latest
@crazy-max
Copy link
Member

@deviantintegral Not released yet, you can test with uses: docker/build-push-action@master

@crazy-max
Copy link
Member

@deviantintegral Should be ok now.

@deviantintegral
Copy link
Author

Thanks! I think the docs may be published onto the Marketplace page before the actions are updated, as that's where I originally read about the feature. Regardless, glad this is sorted 🙌

@limbic-derek
Copy link

I'm having the exact same issue. w/ v2.8.0. It immediately fails and says I have a syntax error, like so:

You have an error in your yaml syntax on line 38

Here's my entire .yml:

name: Build Base Docker Container Image
on: [push]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}/base
  
jobs:
  build-and-push:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    
    steps:
      - 
       name: Docker Setup Buildx
       uses: docker/[email protected]

      - 
        name: Log in to GHCR
        uses: docker/[email protected]
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - 
        name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/[email protected]
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      - 
        name: Build and push Docker image
        uses: docker/[email protected]
        with:
          context: {{defaultContext}}:base
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

I'm trying to build a Dockerfile in a subdir called base.

Any guidance?

@limbic-derek
Copy link

So I tried wrapping context in quotes (like so: "{{defaultContext}}:base") and seemed to get further, it seems to be evaluating now, but still failing, now getting:

#1 [internal] load git source https://github.com/OrgName/RepoName.git#a6a9909480743cdce240ffd1824b51adf6d6a2b1:base
#1 0.143 hint: Using 'master' as the name for the initial branch. This default branch name
#1 0.143 hint: is subject to change. To configure the initial branch name to use in all
#1 0.143 hint: of your new repositories, which will suppress this warning, call:
#1 0.143 hint: 
#1 0.143 hint: 	git config --global init.defaultBranch <name>
#1 0.143 hint: 
#1 0.143 hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
#1 0.143 hint: 'development'. The just-created branch can be renamed via this command:
#1 0.143 hint: 
#1 0.143 hint: 	git branch -m <name>
#1 0.144 Initialized empty Git repository in /var/lib/buildkit/runc-overlayfs/snapshots/snapshots/1/fs/
#1 0.159 fatal: Not a valid object name a6a9909480743cdce240ffd1824b51adf6d6a2b1^{commit}
#1 1.490 fatal: could not read Username for 'https://github.com': terminal prompts disabled
#1 ERROR: failed to fetch remote https://github.com/OrgName/RepoName.git: exit status 128
------
 > [internal] load git source https://github.com/OrgName/RepoName.git#a6a9909480743cdce240ffd1824b51adf6d6a2b1:base:
#1 0.143 hint: 
#1 0.143 hint: 	git config --global init.defaultBranch <name>
#1 0.143 hint: 
#1 0.143 hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
#1 0.143 hint: 'development'. The just-created branch can be renamed via this command:
#1 0.143 hint: 
#1 0.143 hint: 	git branch -m <name>
#1 0.144 Initialized empty Git repository in /var/lib/buildkit/runc-overlayfs/snapshots/snapshots/1/fs/
#1 0.159 fatal: Not a valid object name a6a9909480743cdce240ffd1824b51adf6d6a2b1^{commit}
#1 1.490 fatal: could not read Username for 'https://github.com': terminal prompts disabled
------
error: failed to solve: failed to read dockerfile: failed to fetch remote https://github.com/OrgName/RepoName.git: exit status 128

@dimaqq
Copy link

dimaqq commented Jan 21, 2022

Did I read the README correctly that:
if you use context, you must include your own checkout action?

@axisofentropy
Copy link

I also couldn't get this to work using the Git context. As other comments above have noted, it looks like:

  • the docs should be updated to include "" quote marks around the {{ handlebars }}.
  • buildkit does not yet support subdirectories.

This ticket should probably be re-opened.

@crazy-max crazy-max reopened this Jan 27, 2022
@crazy-max
Copy link
Member

  • the docs should be updated to include "" quote marks around the {{ handlebars }}.

Good catch yes, will fix that.

buildkit does not yet support subdirectories.

Actually it is if you're using the docker-container driver with the setup-buildx-action (default). But it's true it's not yet supported for the docker driver. I will add a note about this.

if you use context, you must include your own checkout action?

context can be a local path or a git repo. For a git repo no need to add the actions/checkout step as shown in the README: https://github.com/docker/build-push-action/#git-context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants