Search code examples
dockergithubgithub-actions

unable to copy folder that has been built with github action into docker image


I'm unable to copy the dist folder that has been built with github action into a docker image...

github action file:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: bahmutov/npm-install@v1
      - run: yarn install
      - run: yarn workspace client build
      - run: bash collectclient.sh

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

      - name: Login to DockerHub
        uses: docker/login-action@v2
        with:
          username: ctrlmaniac
          password: ${{ secrets.DOCKERHUB_PASSWORD }}

      - name: Build and push
        uses: docker/build-push-action@v3
        with:
          push: true
          tags: ctrlmaniac/me:latest

The collectclient.sh file will simply copy the build folder into the root of the project and rename it to public.

#!/usr/bin/bash

echo "Removing old files"
rm -rf public

echo "Copying new files"
cp -r packages/client/build public

However, when I build the docker image, the public folder is not found.

dockerfile

FROM golang:1.19.4-alpine3.17

WORKDIR /home

COPY main/main.go /home/main/main.go
COPY public/ /home/public

RUN go build -o /home/server main/main.go
RUN go install /home/server

CMD ["server"]

What am I missing?


Solution

  • It looks like the behavior of docker/build-push-action.

    Based on their document:

    Be careful because any file mutation in the steps that precede the build step will be ignored, including processing of the .dockerignore file since the context is based on the Git reference. However, you can use the Path context using the context input alongside the actions/checkout action to remove this restriction.

    You can add context: . to include any file mutation in the steps:

          - name: Build and push
            uses: docker/build-push-action@v3
            with:
              context: .
              push: true
              tags: ctrlmaniac/me:latest