Github action workflow error for the Dockerfile - docker

I have following Dockerfile:
FROM openjdk:17
RUN mkdir -p /ctk
RUN mkdir -p /ctk/config/tnt/v2/
WORKDIR /ctk
COPY suitexmls/ /ctk/suitexmls/
COPY config/tnt/v2/EventSubscription.json /ctk/config/tnt/v2/
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN chmod +x ./mvnw
RUN ./mvnw dependency:go-offline
COPY src ./src
RUN ./mvnw clean package spring-boot:repackage
CMD ["./mvnw", "spring-boot:run"]
This docker build and excution works fine locally.
But it fails in github action workflow. It gives following error:-
#5 [ 2/11] RUN mkdir -p /ctk
#5 DONE 0.3s
#6 [ 3/11] RUN mkdir -p /ctk/config/tnt/v2/
#6 DONE 0.3s
#4 [ 1/11] FROM docker.io/library/openjdk:17#sha256:528707081fdb9562eb819128a9f85ae7fe000e2fbaeaf9f87662e7b3f38cb7d8
#4 ...
#7 [ 4/11] WORKDIR /ctk
#7 DONE 0.0s
#8 [ 5/11] COPY suitexmls/ /ctk/suitexmls/
#8 DONE 0.0s
#9 [ 6/11] COPY config/tnt/v2/EventSubscription.json /ctk/config/tnt/v2/
#9 DONE 0.0s
#10 [ 7/11] COPY .mvn/ .mvn
#10 DONE 0.0s
#11 [ 8/11] COPY mvnw pom.xml ./
#11 DONE 0.0s
#12 [ 9/11] RUN ./mvnw dependency:go-offline
#12 0.189 /bin/sh: ./mvnw: Permission denied
#12 ERROR: executor failed running [/bin/sh -c ./mvnw dependency:go-offline]: exit code: 126
#4 [ 1/11] FROM docker.io/library/openjdk:17#sha256:528707081fdb9562eb819128a9f85ae7fe000e2fbaeaf9f87662e7b3f38cb7d8
------
> [ 9/11] RUN ./mvnw dependency:go-offline:
#12 0.189 /bin/sh: ./mvnw: Permission denied
------
ERROR: failed to solve: executor failed running [/bin/sh -c ./mvnw dependency:go-offline]: exit code: 126
Error: buildx failed with: ERROR: failed to solve: executor failed running [/bin/sh -c ./mvnw dependency:go-offline]: exit code: 126
How to fix this error? I have to add more text to post this quesion.
Updated quesion:
docker-publish.yml code:-
name: Docker
on:
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout#v3
- name: Set up JDK 17
uses: actions/setup-java#v3
with:
java-version: 17
distribution: 'temurin'
- name: Cache local Maven repository
uses: actions/cache#v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: build Toolkit
run: echo ${{ secrets.DCSA_USER }} && mvn -B package -DskipTests -X
- name: Extract Build tag
id: buildtag
run: echo "TAG=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout)">> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action#v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# Build and push Docker image
- name: Build and push
uses: docker/build-push-action#v3
with:
push: true
tags: user/app:latest
Now Docker build is fine with suggested fix. But push is fails. Error:-
#17 pushing user/app:latest with docker
#17 pushing layer 5a9003ca1b2d
#17 pushing layer 5a9003ca1b2d 0.2s done
#17 pushing layer a22a34274397 0.2s done
#17 pushing layer c8dd97366670 0.3s done
#17 ERROR: denied: requested access to the resource is denied
------
> pushing user/app:latest with docker:
------
ERROR: denied: requested access to the resource is denied
Error: buildx failed with: ERROR: denied: requested access to the resource is denied
I setup dockerhub secret correclty. Still I can't access why? I have to add more text to post my updated question. It doesn't allow me to post it. I setup dockerhub secret correclty. Still I can't access why?
I have to add more text to post my updated question. It doesn't allow me to post it. I setup dockerhub secret correclty. Still I can't access why?
I have to add more text to post my updated question. It doesn't allow me to post it. Here it the place where I added secret:-

For your dockerfile add RUN chmod +x ./mvnw after copy mvnw to image as follows. This command give you the execution permission.
FROM openjdk:17
RUN mkdir -p /ctk
RUN mkdir -p /ctk/config/tnt/v2/
WORKDIR /ctk
COPY suitexmls/ /ctk/suitexmls/
COPY config/tnt/v2/EventSubscription.json /ctk/config/tnt/v2/
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN chmod +x ./mvnw
RUN ./mvnw dependency:go-offline
COPY src ./src
RUN ./mvnw clean package spring-boot:repackage
CMD ["./mvnw", "spring-boot:run"]
The docker image tag you are using cause the error. Because to push to the docker hub the tag must contain your name as follows.
tags: <your_user_name>/app:latest

Related

Github actions docker cache invalidation

in my actions I am using the gha export type like:
- uses: docker/setup-buildx-action#v1
- name: Build & Push
uses: docker/build-push-action#v2
with:
cache-from: type=gha,scope=${{ matrix.ecr_repo }}
cache-to: type=gha,mode=max,scope=${{ matrix.ecr_repo }}
push: true
tags: "${{ env.tags }}"
However when the action is building I sometimes have lines that should be cached suddenly invalidated.
e.g:
#20 [base 22/26] COPY src/go.sum ./
#20 CACHED
#30 [base 23/26] RUN go mod download
#30 sha256:fccecca06c0e928afeb80a372e92178cfe09778a2d41c53d690328cd9350920f 43.01kB / 43.01kB 0.1s done
#30 sha256:46e25f3fb1d9354adea3ee0ec11523a2d4bdb24c795548575f2a8a180f8ef285 2.53kB / 2.53kB 0.1s done
...
Dockerfile:
...
COPY src/go.mod ./
COPY src/go.sum ./
RUN go mod download
COPY src ./
RUN --mount=type=cache,target=/root/.cache/go-build \
go build -tags=static -o /cli && ls -al /cli
...
I don't understand why RUN go mod download is not cached when the COPY before is - is there any debugging I can do?

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)

COPY failed: no source files were specified with github actions

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)

Docker Build fails but Gitlab-CI reports succeeds(False positive)

I have a Gitlab pipeline that builds my Docker image from a Dockerfile, but when the "docker build" command fails, the pipeline still reports a success.
build:
stage: build
script:
- docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL .
I've added an error to my Dockerfile so I can provoke an error:
FROM ubuntu:20.04
RUN not_a_real_command_that_should_fail
The pipeline runs:
Running with gitlab-runner 14.0.1 (c1edb478)
on ******* Cy33WtLD
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on **********...
Getting source from Git repository
00:04
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/gitlab-runner/builds/Cy33WtLD/0/dockerfile/.git/
Checking out 999a815d as fix_pipeline_status...
git-lfs/2.13.2 (GitHub; windows amd64; go 1.14.13; git fc664697)
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:03
$ docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL .
#1 [internal] load build definition from Dockerfile
#1 sha256:c544637cbaca3e93c2a8a8c00efd4f81ee45b1abd410d971af12de8dae21e8ea
#1 transferring dockerfile: 3.04kB done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:ab745a167b371ba5e9380063cb278a7792a5838550b89f02f35d7f6a583fb548
#2 transferring context: 2B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/ubuntu:20.04
#3 sha256:8e67b796a66f85f06793e026943184e32d365c77929e94d2ac98b34a1e1cb30e
#3 DONE 0.6s
#4 [ 1/17] FROM docker.io/library/ubuntu:20.04#sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f
#4 sha256:c8b7f784dc481f981cf0bc39c4d4e60a54a355d96ca108a13ffffa3bfa047067
#4 CACHED
#20 [internal] load build context
#20 sha256:d12ef8e847404a2cc9437d8099f4b73f215c48eb92002e759a5f264989ae3ace
#20 transferring context: 92B 0.0s done
#20 DONE 0.0s
#5 [ 2/17] RUN not_a_real_command_that_should_fail
#5 sha256:724c85340f260555ab116f9064ba3c7a2c16fe0af059ef5226df31545b30ddb6
#5 0.485 /bin/sh: 1: not_a_real_command_that_should_fail: not found
#5 ERROR: executor failed running [/bin/sh -c not_a_real_command_that_should_fail]: exit code: 127
------
> [ 2/17] RUN not_a_real_command_that_should_fail:
------
executor failed running [/bin/sh -c not_a_real_command_that_should_fail]: exit code: 127
Cleaning up file based variables
00:01
Job succeeded
The exit code is 127, I've added a -after_stage step to print out the return code "echo $?" and get "true" result back. Seems like this should be sufficient for the command to trigger a failure in the pipeline.
The gitlab-runner is a shell executor on a Windows-machine, if that matters.
Any suggestions?
1 - Gitlab issue
There is a bug for gitlab runner versions prior to 13.1.1 :
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/26347
Where job is always successful when FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY is set to False
Solution seems to be updating.
2 - Script issue
Try to force exit 1 on error with
build:
stage: build
script:
- docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL . || exit 1
Edit 1
By default, Powershell continues its execution.
You can set those variables :
job:
stage: build
variables:
ErrorActionPreference: stop
script:
- docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL .
Please see this issue on github for more information :
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4683
After moving the pipeline to a gitlab-runner on a Ubuntu machine the pipeline fails as expected. Assuming the Windows-Powershell exit-codes does not trigger correctly

problems running Docker container in Cypress

The docker container 'will build' but for some reason 'will not run'. I've trying to resolve this but I think I need a fresh pair of eyes on it.
Here is the code:
Docker file:
FROM cypress/included:6.8.0
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/ cypress verify
RUN $(npm bin)/cypress
The docker ignore file
node_modules
The docker-compose.yml file
version: '3'
services:
e2e:
image: cypress
build: .
container_name: cypress
command:
npx cypress run
I got the following error message in my terminal
docker-compose -f docker-compose.yml up
Building e2e
[+] Building 293.8s (9/10)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 36B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/cypress/included:6.8.0 0.0s
=> [1/6] FROM docker.io/cypress/included:6.8.0 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 1.14kB 0.0s
=> CACHED [2/6] WORKDIR /app 0.0s
=> [3/6] COPY . /app 0.1s
=> [4/6] RUN npm install 292.0s
=> ERROR [5/6] RUN $(npm bin)/ cypress verify 1.4s
------
> [5/6] RUN $(npm bin)/ cypress verify:
#9 1.387 /bin/sh: 1: /app/node_modules/.bin/: Permission denied
------
executor failed running [/bin/sh -c $(npm bin)/ cypress verify]: exit code: 126
ERROR: Service 'e2e' failed to build
xxx-MacBook-Air CypressDocker %
#mosaad. I just tried your answer. However I got the following error message
=> ERROR [5/6] RUN $(npm bin)/ cypress verify 1.8s
------
> [5/6] RUN $(npm bin)/ cypress verify:
#9 1.705 /bin/sh: 1: /app/node_modules/.bin/: not found
------
executor failed running [/bin/sh -c $(npm bin)/ cypress verify]: exit code: 127
ERROR: Service 'e2e' failed to build
You should copy after npm install so that node_modules are copied too.
This should work:
FROM cypress/included:6.8.0
WORKDIR /app
RUN npm install
COPY . /app
RUN $(npm bin)/ cypress verify
RUN $(npm bin)/cypress
Many thanks to everyone who took a moment to take a look at my problem. I rewrote the docker-compose.yml file code again and it now works perfectly. If this can help anyone in the future here is the corrected code.
FROM cypress/included:6.8.0
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/cypress verify
RUN $(npm bin)/cypress

Resources