Maven build and containerize

I am trying to use concourse to build a spring boot project using maven and dockerize it and store the image in dockerhub.

I have

resources:
  - name: democicdcode
    type: git
    

  - name: democicd
    type: docker-image
    
jobs:
  - name: build-base-images
    plan:
      - get: democicdcode
        trigger: true
      - task: build
        file: democicdcode/ci/tasks/build.yml  
      - put: democicd
        params:
          build: democicdcode/
          file: built-project/DemocicdProject.jar

My build.yml

platform: linux

image_resource:
  type: docker-image
  source:
    repository: maven
    tag: 3.6-jdk-8-alpine

inputs:
  - name: democicdcode

outputs:
  - name: built-project

run:
   path: sh
   args:
   - -exc
   - | 
      cd democicdcode
      mvn clean install
      cp ./target/DemocicdProject-*jar ../built-project/DemocicdProject.jar

How can i use the build artifacts ( a jar file ) created during maven build in the next put operation to build the docker image?

Thanks

Hi vvs0001
I was able to build and push the image using you example. Here is my sample:`resources:

  • check_every: 24h
    name: code-repo
    source:
    branch: master
    private_key:
    uri:
    type: git

  • name: docker-image-master
    type: docker-image
    source:
    username:
    password:
    repository: /
    tag: latest

jobs:

  • name: build-base-images
    plan:
    • get: code-repo
      trigger: true

    • task: build
      config:
      platform: linux
      image_resource:
      type: docker-image
      source:
      repository:
      tag: “latest”
      inputs:
      - name: code-repo
      outputs:
      - name: code-repo
      run:
      path: sh
      args:
      - -exc
      - |
      cd code-repo
      mvn clean install

    • put: docker-image-master
      params:
      build: code-repo

You can pass the build folder to put step and make sure to Dockerfile as below. No need to copy the jar to some other location. It will be under target folder by default and you can add jar from target folder in Dockerfile.
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ADD ./target/*.jar app.jar
ENTRYPOINT [“java”,"-jar","/app.jar"]