Home > Enterprise >  Github action workflow error for the Dockerfile
Github action workflow error for the Dockerfile

Time:10-12

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:-

enter image description here

CodePudding user response:

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