Skip to content

Unexpected dockerignore behaviour #511

@igorGevaerd

Description

@igorGevaerd

Behaviour

The following .dockerignore file produced different docker images when running on github actions than when it was executed on my machine:

/**

!/api
!/config
!/extensions
!/public
!/favicon.ico
!/package.json
!/yarn.lock

Steps to reproduce this issue

  1. clone a Strapi repo (eg https://github.com/kevinadhiguna/strapi-dockerize);
  2. docker build -t local-test-build:1 -f Dockerfile .;
  3. define an github actions job using docker/build-push-action@v2;
  4. compare both images produced, paying attention to the directories defined on the on the .dockerignore file previously described.

Expected behaviour

Both images created should have the same files inside their directories, even the ones defined on the .dockerignore file

Actual behaviour

On the image built locally, directories such as /api or /config have their content copied from the repository. But it is not happening with the images from the workflow, which the directories are completely empty.

Configuration

---
name: CI

# yamllint disable-line rule:truthy
on:
  pull_request:
    paths:
    - api/**
    - config/**
    - extensions/**
    - public/**
    - .dockerignore
    - Dockerfile
    - favicon.ico
    - package.json
    - yarn.lock
  push:
    branches:
    - main
    paths:
    - api/**
    - config/**
    - extensions/**
    - public/**
    - .dockerignore
    - Dockerfile
    - favicon.ico
    - package.json
    - yarn.lock
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Get Short SHA
      id: sha
      run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"

    - name: Checkout Code
      uses: actions/checkout@v2

    - name: Login to GitHub Container Registry
      if: github.ref == 'refs/heads/main'
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ secrets.ABC }}
        password: ${{ secrets.XYZ }}

    - name: Build and Push Docker Image
      uses: docker/build-push-action@v2
      with:
        context: ./
        push: ${{ github.ref == 'refs/heads/main' }}
        tags: |
          ghcr.io/${{ github.repository }}:${{ steps.sha.outputs.sha8 }}
          ghcr.io/${{ github.repository }}:latest

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions