Build Output and Dockerfile COPY

My build outputs a dist directory via webpack.

Problem: I’ve tried some COPY commands from the dist directory of my build but for some reason I’m not doing it right and the copy to my Docker container fails.

I get:

Step 3/3 : COPY ./dist ./dist

(https://github.com/xxxx/xxxx/runs/1048806314?check_suite_focus=true#step:4:47)COPY failed: stat /var/lib/docker/tmp/docker-builder088552185/dist: no such file or directory`

Example Dockerfile where I cannot get copy to work:

FROM node:14.8.0-alpine
ENV PORT 80
COPY ./dist ./dist

also tried:

COPY dist dist

and

COPY ./dist dist

and

COPY dist ./dist

I know that the files are there because I ran an ls -la step after my build was done to list out the output of the $GITHUB_WORKSPACE.
Screen Shot 2020-08-30 at 6.12.33 PM

I already read Dockerfile support for GitHub Actions but I must be missing something obvious, just need another set of eyes

Build.yml

name: build-test

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  build:
    name: Build WeDoTDD Server & Client
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Setup node 14
        uses: actions/setup-node@v1
        with:
          node-version: 14.x
      - run: yarn --frozen-lockfile
      - run: yarn build-server
      - run: yarn build-client
      - run: ls ./dist
        env:
          CI: true
  push_to_registry:
    needs: build
    name: Push Docker image to GitHub Packages
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2
      - name: Push to GitHub Packages
        uses: docker/build-push-action@v1
        with:
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
          registry: docker.pkg.github.com
          # OWNER/REPOSITORY/IMAGE_NAME
          repository: xxxx/xxxx/staging
          tag_with_sha: true
1 Like

Hi. :wave:

My knowledge of Docker is limited, but looking at the documentation for COPY, it copies files from the <src> into the container at the given <dest>, now I’m not 100% sure if the output from the run command in a GitHub Actions, places the build in the <src> that Docker uses, but if it does, then I’m guessing the COPY you want would be this.

COPY dist /dist

Which from my understanding would copy the contents of the dist source folder to the /dist folder in the container. :thinking:

Hope that helps. :+1:

Thanks tried it but no luck. I wonder if it’s because I’m calling actions/checkout@v2 twice and the second time wipes out the workflow?

Yea the docs on build-push-action are lacking as to what the context is that the copy is done from.

I think the issue is that you’re using two jobs, so the build from one job isn’t shared to the next job, what you wanna use actions/upload-artifact and actions/download-artifact to share the build between jobs, there was also some changes to the download experience you would wanna read as well.

Thanks I’ll check that out.

I assume I’d use download instead of checkout on the second job.

Got it working. First part was getting the artifact transfered, so thanks much!

Second part was getting the Dockerfile right:

Dockerfile - I added WORKDIR and then used current directory off the working directory:

FROM node:14.8.0-alpine
ENV PORT 80
WORKDIR dist
COPY . dist

Thanks for the tip on the artifacts!

Congratulations. :tada:

I’m glad I could provide some help that led to your solution, I wish you luck in further endeavors. :slightly_smiling_face:

1 Like