0

I follow the book Cloud Native Spring in Action and I encountered this error. I used the Paketo Buildpacks to build the image using ./gradlew bootBuildImage. Full source code: https://github.com/arkadisahakyan/catalog-service/

Full error message:

catalog-service  | unable to determine class count
catalog-service  | unable to walk /workspace
catalog-service  | open /workspace/BOOT-INF/classes/db: permission denied
catalog-service  | ERROR: failed to launch: exec.d: failed to execute exec.d file at path '/layers/paketo-buildpacks_bellsoft-liberica/helper/exec.d/memory-calculator': exit status 1

docker-compose.yml (runs the main Spring Boot application and the database image)

version: "3.8"
services:
  catalog-service:
    depends_on:
      - polar-postgres
    image: "ghcr.io/arkadisahakyan/catalog-service"
    container_name: "catalog-service"
    ports:
      - 9001:9001
    environment:
      - BPL_JVM_THREAD_COUNT=50
      - SPRING_DATASOURCE_URL=jdbc:postgresql://polar-postgres:5432/polardb_catalog
      - SPRING_PROFILES_ACTIVE=testdata
  polar-postgres:
    image: "postgres:14.4"
    container_name: "polar-postgres"
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=polardb_catalog

build.gradle (all the same as in the book)

plugins {
    id 'org.springframework.boot' version '2.7.18'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
    id 'java'
}

group = 'com.polarbookshop'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

description = 'Provides functionality for managing the books in the catalog.'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2021.0.9")
    set('testcontainersVersion', "1.19.8")
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.cloud:spring-cloud-starter-config'
    implementation 'org.springframework.retry:spring-retry'
    implementation 'org.flywaydb:flyway-core'

    runtimeOnly 'org.postgresql:postgresql'
    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.boot:spring-boot-starter-webflux'
    testImplementation 'org.testcontainers:postgresql'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}"
    }
}

bootRun {
    systemProperty 'spring.profiles.active', 'testdata'
}

bootBuildImage {
    builder = "docker.io/paketobuildpacks/builder-jammy-base"
    imageName = "${project.name}"
    environment = ["BP_JVM_VERSION": "17"]

    docker {
        publishRegistry {
            username = project.findProperty("registryUsername")
            password = project.findProperty("registryToken")
            url = project.findProperty("registryUrl")
        }
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

I tried to run both the local and remote images but the error is the same. Remote package:

docker pull ghcr.io/arkadisahakyan/catalog-service:latest

What is the source of the problem and how to fix it?

1
  • the only problem i can think of is that when you set WORKDIR workspace the directory will be created at /workspace which usually only has access by the user root but you are later running the app as the user spring. So depending on how you run your docker compose, if its run as root, or not. Or you run the chown command in the dockerfile changing the ownershop of the folder workspace to the user spring. Commented Nov 25 at 22:35

1 Answer 1

2

Quick answer: There are no problems with the source code.

I tested it using two different methods, and both appeared to be normal and without any problems.

The first method: manually create a Docker image.

The following are the steps to manually create a Docker image:

Build Spring Boot Application

gradle clean build

Build Docker image

docker build -f Dockerfile -t catalog-service:0.0.1-SNAPSHOT .

editing: docker-compose.yml

change image to "catalog-service:0.0.1-SNAPSHOT"

version: "3.8"
services:
  catalog-service:
    depends_on:
      - polar-postgres
    image: "catalog-service:0.0.1-SNAPSHOT"

Run

docker compose up

Test

Browser open http://localhost:9001/books

The second method: Use ./gradlew bootBuildImage

Build

./gradlew bootBuildImage

Find Docker Image

docker image ls | grep catalog-service

get

catalog-service                                      latest                        793ae7db06a2   45 years ago    348MB

editing: docker-compose.yml

change image to "catalog-service"

version: "3.8"
services:
  catalog-service:
    depends_on:
      - polar-postgres
    image: "catalog-service"

Run

docker compose up

Test

Browser open http://localhost:9001/books

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.