COPY failed: no source files were specified with github actions - docker

Error Description
While running command git push, I am getting following error: COPY failed: no source files were specified
Dockerfile
Dockerfile is like it:
# 拉取node:14作为构建工具
FROM node:14 AS build
# 工作目录为 app
WORKDIR /app
# 将以package结尾的json文件拷贝
COPY package*.json ./
RUN npm install -g pnpm
# 执行 安装依赖
RUN pnpm install
# 将 ts配置文件拷贝过去
COPY tsconfig.json ./
# 将public目录拷贝过去
COPY public public/
# 将src目录拷贝过去
COPY src src/
# 执行构建脚本
RUN pnpm run build
# 拉取nginx
FROM nginx:alpine
# 将构建好的文件夹拷贝到nginx中
COPY --from=build /app/build/ /usr/share/nginx/html
# 暴露端口9567
EXPOSE 9567
# 运行nginx
CMD ["nginx", "-g", "daemon off;"]
Github Actions Yaml
dev.yml(github actions)is like as shown below::
# This is a basic workflow to help you get started with Actions
name: Deploy Web De
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "deploy-web-dev"
deploy-web-dev:
environment:
development
# The type of runner that the job will run on
runs-on:
ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout#v3
- name: Install pnpm
uses: pnpm/action-setup#v2
with:
version: 6
- name: Install dependencies
run: pnpm install
- name: Build web dev
run: pnpm run build
- name: Log in to Docker Hub
uses: docker/login-action#v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Reset dockerignore
run: |
echo "*" > .dockerignore
echo "!dist" >> .dockerignore
- name: Build and push images
env:
COMMIT_SHA_TAG: development-${{ github.sha }}
LATEST_DEV_TAG: dev-latest
PRIVATE_DOCKERHUB_REGISTRY: ${{ secrets.PRIVATE_DOCKERHUB_REGISTRY }}
PRIVATE_DOCKERHUB_USERNAME: ${{ secrets.PRIVATE_DOCKERHUB_USERNAME }}
PRIVATE_DOCKERHUB_PASSWORD: ${{ secrets.PRIVATE_DOCKERHUB_PASSWORD }}
run: |
docker build . -t cloud-music:$COMMIT_SHA_TAG -t cloud-music:$LATEST_DEV_TAG -t $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$COMMIT_SHA_TAG -t $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$LATEST_DEV_TAG
docker push cloud-music:$COMMIT_SHA_TAG
docker push cloud-music:$LATEST_DEV_TAG
docker login -u $PRIVATE_DOCKERHUB_USERNAME -p $PRIVATE_DOCKERHUB_PASSWORD $PRIVATE_DOCKERHUB_REGISTRY
docker push $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$COMMIT_SHA_TAG
docker push $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$LATEST_DEV_TAG
Jobs Log
Jobs log:
Error Position
Error in line 23
1
Run docker build . -t cloud-music:$COMMIT_SHA_TAG -t cloud-music:$LATEST_DEV_TAG -t $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$COMMIT_SHA_TAG -t $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$LATEST_DEV_TAG
2
docker build . -t cloud-music:$COMMIT_SHA_TAG -t cloud-music:$LATEST_DEV_TAG -t $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$COMMIT_SHA_TAG -t $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$LATEST_DEV_TAG
3
docker push cloud-music:$COMMIT_SHA_TAG
4
docker push cloud-music:$LATEST_DEV_TAG
5
6
docker login -u $PRIVATE_DOCKERHUB_USERNAME -p $PRIVATE_DOCKERHUB_PASSWORD $PRIVATE_DOCKERHUB_REGISTRY
7
docker push $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$COMMIT_SHA_TAG
8
docker push $PRIVATE_DOCKERHUB_REGISTRY/cloud-music:$LATEST_DEV_TAG
9
shell: /usr/bin/bash -e {0}
10
env:
11
PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
12
COMMIT_SHA_TAG: development-6ba24b062419ef744d2642e2f9eee97dabb9a63e
13
LATEST_DEV_TAG: dev-latest
14
PRIVATE_DOCKERHUB_REGISTRY: ***
15
PRIVATE_DOCKERHUB_USERNAME: ***
16
PRIVATE_DOCKERHUB_PASSWORD: ***
17
Sending build context to Docker daemon 3.584kB
18
19
Step 1/12 : FROM node:14 AS build
20
---> 903c2c873ea4
21
Step 2/12 : WORKDIR /app
22
---> Running in f80bdf0901cf
23
COPY failed: no source files were specified
24
Removing intermediate container f80bdf0901cf
25
---> 3221d5124e85
26
Step 3/12 : COPY package*.json ./
27
Error: Process completed with exit code 1.
Project Structure
Here is my project structure.
enter image description here
Please help me in solving this error.
Thanks in advance!!

I hope you might solved this issue. ANyhow my reply is to help others for reference. I too faced the same problem and solved by the following changes made in workflow.yml. You need to mention the docker packages and docker file directory in workflow by cd
workflow at the time of error
run: docker build . --file Dockerfile --tag nodejs:$(date +%s)
Fix:
run: |
cd app
docker build . --file Dockerfile --tag nodejs:$(date +%s)

Related

GitHub Actions fails to build a docker image for web app

Have a few queries around it
I have a docker build failing due to path. It works when I execute on local PC. What should be the path here?
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout#v3
- name: Node
uses: actions/setup-node#v3
with:
node-version: 14.15
- name: Dependencies
run: npm install --legacy-peer-deps
- name: Build
run: npm run build-prod
- name: Docker Login
run: docker login -u $USERNAME -p $PWD
- name: Build
run: docker build . --tag $REPO:latest
- name: Docker Push
run: docker push $REPO:latest
Error
> [3/3] COPY /dist/app-name /usr/share/nginx/html:
145
------
146
error: failed to solve: failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount67345738657/dist: lstat /var/lib/docker/tmp/buildkit-mount67345738657/dist: no such file or directory
Dockerfile
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY /dist/app-name /usr/share/nginx/html
How do I get the tag version when a new release is created to start the build with two tags: latest and {tag} created for the build. This is to keep build backups of old tags in docker. What will be the changes above to do two builds?

Github Actions Docker build: "/pmpn-lock.yaml" and "./nginx/default.conf" not found

So I'm having an issue with my docker build action with github actions and I definitely feel like the issue is obvious but I am failing to get it.
So here is my Github Action
name: Build / Publish
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-push-docker-image:
name: Build Pinsel Docker image and push to repos
runs-on: ubuntu-latest
steps:
-
name: Checkout codebase
uses: actions/checkout#v2
-
name: Docker meta
id: meta
uses: docker/metadata-action#v3
with:
images: name/app
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Setup docker build
-
name: Set up Docker buildx
id: buildx
uses: docker/setup-buildx-action#v1
-
name: Login to Docker Hub
uses: docker/login-action#v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login into Github Packages
uses: docker/login-action#v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
-
name: Build image and push it to both registries
uses: docker/build-push-action#v2
with:
context: ../../
file: ./Dockerfile.prod
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
And here is my Dockerfile located in main directory
FROM node:16.4.2-alpine as build
RUN npm install -g pnpm#next-7
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY /pnpm-lock.yaml ./
RUN pnpm fetch --prod
ADD . ./
RUN pnpm install -r --offline --prod
FROM nginx:1.21-alpine
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
and lastly the error
#11 [build 5/8] COPY /package.json ./
#11 ERROR: failed to calculate checksum of ref ypf6stpm3t9h2xl6ezvwo7876::kvjk90tcw8wfykmdkvu1uvzgs: "/package.json": not found
#12 [stage-1 2/3] COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
#12 CANCELED
Dockerfile.prod:13
--------------------
11 |
12 | FROM nginx:1.21-alpine
13 | >>> COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
14 | COPY --from=build /app/build /usr/share/nginx/html
15 | EXPOSE 80
--------------------
error: failed to solve: failed to compute cache key: failed to calculate checksum of ref ypf6stpm3t9h2xl6ezvwo7876::kvjk90tcw8wfykmdkvu1uvzgs: "/nginx/default.conf": not found
Error: buildx failed with: error: failed to solve: failed to compute cache key: failed to calculate checksum of ref ypf6stpm3t9h2xl6ezvwo7876::kvjk90tcw8wfykmdkvu1uvzgs: "/nginx/default.conf": not found
Everything goes well on github actions until it needs to copy files. It says it can't find pnpm-lock.yaml, nor can it find ./nginx both of which are there.
I feel like the answer is super simple and I am just mentally fried and it's not standing out. If I can get a nudge in the right direction, it'd be appreciated!
I have realized that github/checkout puts you at the root directory of the github project, meaning I didn't need to add ../../ for context, I made the mistake of thinking I was navigating from the github action workflow directory.
So for anyone else who ends up this issue: actions/checkout will put you in the root directory of the repo, so you only need to use navigate via context if your dockerfiles are somewhere other than the root folder (like in their own docker folder)

Build Docker image using GitHub Actions: No such file or directory

We intend to use Git Actions to build our Docker on every commit.
This is our current Git Actions yml:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Navigate to app folder
run: cd app
- name: Open Directory
working-directory: app
run: |
ls -la
- name: Build docker image
run: docker build . -t app_name -f Dockerfile
The error I get is:
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/runner/work/git-root/app/Dockerfile: no such file or directory
But in my ls -la i see the Dockerfile is present:
total 48
drwxr-xr-x 4 runner docker 4096 Sep 15 13:03 .
drwxr-xr-x 6 runner docker 4096 Sep 15 13:03 ..
-rw-r--r-- 1 runner docker 93 Sep 15 13:03 .env-template
-rw-r--r-- 1 runner docker 655 Sep 15 13:03 Dockerfile
I have tried:
Using both actions/checkout#v1 and actions/checkout#v2
cd into the directory with the Dockerfile
setting Dockerfile directory to working-directory
Why does not the docker build find my Dockerfile?
See the docs here:
Each run keyword represents a new process and shell in the runner environment. When you provide multi-line commands, each line runs in the same shell.
This means that the working directory isn't persisted after the cd step. Your ls step works because you explicitly set the working directory for it.
You have to cd in the same run step as the build command:
- name: Build docker image
run: |
cd app
docker build . -t app_name -f Dockerfile
Or you can give docker the path to your dockerfile:
- name: Build docker image
run: docker build app -t app_name
The default for -f is PATH/Dockerfile, where PATH is app above.

Cannot push docker image into docker hub from Github Action

I have yaml file in GitHub action and i have successfully build docker image in it and i want to push into docker hub but getting below error
Run docker push ***/vampi_docker:latest
docker push ***/vampi_docker:latest
shell: /usr/bin/bash -e {0}
An image does not exist locally with the tag: ***/vampi_docker
The push refers to repository [docker.io/***/vampi_docker]
Error: Process completed with exit code 1.
Here is the yml file
name: vampi_docker
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: docker login
env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
repository: test/vampi_docker:latest
tags: latest, ${{ secrets.DOCKER_TOKEN }}
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Build the Vampi Docker image
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
docker build . --file Dockerfile --tag vampi_docker:latest
- name: List images
run: docker images
- name: Docker Push
run: docker push ${{secrets.DOCKER_USER}}/vampi_docker:latest
Please do let me know where im wrong and what i miss
Base on the error that is showed.
Change this:
docker build . --file Dockerfile --tag vampi_docker:latest
to:
docker build . --file Dockerfile --tag test/vampi_docker:latest
And run again.

Dockerfile go build command not getting cached in Github Actions

I am using the Github Action actions/cache#v2 to cache the docker layers. Following is the build.yml file:
name: Build
on:
push:
branches:
- '**'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout#v2
- name: Get Docker Tags
id: getDockerTag
run: |
echo ::set-output name=image_tag::${{github.sha}}
echo "Setting image tag as :: ${{github.sha}}"
# Set up buildx runner
- 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-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build docker image 1
uses: docker/build-push-action#v2
with:
push: false
tags: go-docker-caching:${{ steps.getDockerTag.outputs.image_tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
Dockerfile:
FROM golang:latest as builder
# create a working directory
WORKDIR /main
COPY go.mod go.sum ./
RUN ls -a
# Download dependencies
RUN go mod tidy
RUN go mod download
COPY . .
## Build binary
#RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o gin_test
RUN go build -o main
# use a minimal alpine image for deployment
FROM alpine:latest
# add ca-certificates in case you need them
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
# set working directory
WORKDIR /root
# copy the binary from builder
COPY --from=builder /main .
RUN touch .main.yml
# Specify the PORT
EXPOSE 8080:8080
# run the binary
CMD ["./main"]
On local, all docker commands are getting cached, but on Github Actions, the following commands are not getting cached which leads to the docker build taking around 3 minutes to download the modules, even if nothing is changed.
RUN go mod download
RUN go build -o main
How to make sure all the commands are cached?

Resources