question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent dockerignore behavior from other builders

See original GitHub issue

⚠️ I’m not entirely sure if this is an issue with GitHub Actions, or this action specifically, but I didn’t know where else to report it so figured this would be a good start. It’s also quite possible that I’m an idiot and I’m doing something wrong that hopefully will be obvious to someone else, but I’m running into a wall with this, so here goes nothing: #insecurities

Behaviour

It appears to me that the .dockerignore is being completely ignored when building using this action, which is an obvious inconsistency from other build[x] build environments (I’ve tested using my local Windows environment, remote ubuntu VM’s, other CI tooling) just to be sure.

Steps to reproduce this issue

I used a whitelist-style .dockerignore to remove any rule parsing inconsistencies that I could, trying to keep it simple:

*
*/

# do not ignore source files and assets - whitelist
!assets/
!cmd/
!internal/
!pkg/
!static/
!tools/

# do not ignore go module files
!go.mod
!go.sum

Expected behaviour

We should respect .dockerignore - He’s tryin his best.

Actual behaviour

The run output shows a lot of files that aren’t whitelisted, highlighted as - diffs. I do not see these files in other build environments using either docker build or docker buildx build

#11 [builder 6/8] COPY . .
#11 DONE 0.1s
#12 [builder 7/8] RUN ls -alh
#12 0.082 total 108K   
#12 0.083 drwxr-xr-x    1 root     root        4.0K Oct 18 15:18 .
#12 0.083 drwxrwxrwx    1 root     root        4.0K Oct 18 15:17 ..
- #12 0.083 -rw-rw-rw-    1 root     root         156 Oct 18 15:17 .dockerignore
- #12 0.083 -rw-rw-rw-    1 root     root         682 Oct 18 15:17 .editorconfig
- #12 0.083 -rw-rw-rw-    1 root     root          68 Oct 18 15:17 .envrc
- #12 0.083 -rw-rw-rw-    1 root     root        1.3K Oct 18 15:17 .gitattributes
- #12 0.083 drwxrwxrwx    3 root     root        4.0K Oct 18 15:17 .github
- #12 0.083 -rw-rw-rw-    1 root     root         468 Oct 18 15:17 .gitignore
- #12 0.083 -rw-rw-rw-    1 root     root         339 Oct 18 15:17 .pre-commit-config.yaml
- #12 0.083 drwxrwxrwx    2 root     root        4.0K Oct 18 15:17 .vscode
- #12 0.083 -rw-rw-rw-    1 root     root         930 Oct 18 15:17 Dockerfile
- #12 0.083 -rw-rw-rw-    1 root     root        1.1K Oct 18 15:17 LICENSE
- #12 0.083 -rw-rw-rw-    1 root     root         131 Oct 18 15:17 README.md
- #12 0.083 -rw-rw-rw-    1 root     root          12 Oct 18 15:17 api.go
#12 0.083 drwxrwxrwx    2 root     root        4.0K Oct 18 15:17 assets
#12 0.083 drwxrwxrwx    3 root     root        4.0K Oct 18 15:17 cmd
- #12 0.084 -rw-rw-rw-    1 root     root         794 Oct 18 15:17 docker-compose.yml
#12 0.084 -rw-rw-rw-    1 root     root         238 Oct 18 15:17 go.mod
#12 0.084 -rw-rw-rw-    1 root     root       11.0K Oct 18 15:17 go.sum
- #12 0.084 -rw-rw-rw-    1 root     root          37 Oct 18 15:17 heroku.yml
#12 0.084 drwxrwxrwx    3 root     root        4.0K Oct 18 15:17 internal
#12 0.084 drwxrwxrwx    3 root     root        4.0K Oct 18 15:17 pkg
#12 0.084 drwxrwxrwx    2 root     root        4.0K Oct 18 15:17 static
#12 0.084 drwxrwxrwx    2 root     root        4.0K Oct 18 15:17 tools
#12 DONE 0.1s

Configuration

name: Build

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      -
        name: Check out source
        uses: actions/checkout@v2
      -
        name: Repo metadata
        id: repo
        uses: actions/github-script@v3
        with:
          script: |
            const repo = await github.repos.get(context.repo)
            return repo.data
      -
        name: Prepare
        id: prep
        run: |
          DOCKER_IMAGE="${DOCKER_IMAGE:-$GITHUB_REPOSITORY}"
          VERSION=noop
          if [[ $GITHUB_REF == refs/tags/* ]]; then
            VERSION=${GITHUB_REF#refs/tags/}
          elif [[ $GITHUB_REF == refs/heads/* ]]; then
            VERSION=$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's#/+#-#g')
            if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
              VERSION=edge
            fi
          elif [[ $GITHUB_REF == refs/pull/* ]]; then
            VERSION=pr-${{ github.event.number }}
          fi
          if [ "$GITHUB_EVENT_NAME" != "pull_request" ]; then
            TAGS="${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
          fi
          TAGS="${DOCKER_IMAGE}:${VERSION}"
          if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
            MINOR=${VERSION%.*}
            MAJOR=${MINOR%.*}
            TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
          fi
          echo ::set-output name=image::"${DOCKER_IMAGE}"
          echo ::set-output name=version::"${VERSION}"
          echo ::set-output name=tags::"${TAGS}"
          echo ::set-output name=created::"$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
      -
        name: Build values
        run: |
          echo Version: ${{ steps.prep.outputs.version }}
          echo Docker Image: ${{ steps.prep.outputs.image }}
          echo Docker Tags: ${{ steps.prep.outputs.tags }}
          echo Created: ${{ steps.prep.outputs.created }}
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-
      -
        name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.prep.outputs.tags }}
          build-args: |-
            version=${{ steps.prep.outputs.version }}
            vcs_ref=${{ github.ref }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache
          labels: |
            org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }}
            org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }}
            org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }}
            org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }}
            org.opencontainers.image.version=${{ steps.prep.outputs.version }}
            org.opencontainers.image.created=${{ steps.prep.outputs.created }}
            org.opencontainers.image.revision=${{ github.sha }}
            org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}
      -
        name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

Logs

logs_27.zip

Please save me 😢

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
sagikazarmarkcommented, Oct 19, 2020

This is a wild guess, but I think it’s because you use git context which is the default.

Try using path context

2reactions
dvalentiatecommented, Jul 13, 2021

I’ve created a PR to detail that .dockerignore is ignored.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do not ignore .dockerignore (it's expensive and potentially ...
In this article we will learn about the docker build context and how to optimize it (using the .dockerignore file).
Read more >
dockerignore - Go Packages
ReadAll reads a . dockerignore file and returns the list of file patterns to ignore. Note this will trim whitespace from each line...
Read more >
Docker best practices with Node.js - DEV Community ‍ ‍
Welcome to our comprehensive list of Docker best practices that are exemplified under the realm of Node.js. Note that each and every bullet...
Read more >
10 best practices to containerize Node.js web applications ...
Docker image builds are inconsistent. Just like we're using lockfiles to get a deterministic npm install behavior every time we install npm ...
Read more >
Docker Compose release notes
Docker Build: added fix to respect dependency order for classic builder. ... Recovered behavior for 'compose up -d' of recreating containers of compose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found