Building a docker image using a dockerfile then pushing it to my registry (OD-467)
Stephen S opened 4 years ago

Hi, and thanks for this amazing project I have discovered today. My only criticism would be for the documentation I find lacking and messy.

For example, I could not find the answers to this very basic question: what are the steps involved to buid a docker image from a dockerfile then push it to a self hosted registry?

Here is what I did:

  1. create a shell Job Executor on the server
  2. create a new project with the Dockerfile included
  3. create a .onedev-buildspec.yml file
  4. first step: checkout the repository attached to the project
  5. second step: load yobasystems/alpine-docker , which is an image including docker
  6. BUT THEN WHAT? in what path do I find the dockerfile so that I am able to execute a docker build?
  7. And then, how do I push the resulting image from the Job Executor to my registry?

Please help because I am sure the solution is at hands, only difficult to find in the documentation, which is frustrating. Thanks. Stephen

  • Stephen S commented 4 years ago

    For a better understanding, here is the current state of the .onedev-buildspec.yml file:

    version: 13
    jobs:
    - name: build
      steps:
      - !CheckoutStep
        name: checkout
        cloneCredential: !DefaultCredential {}
        withLfs: false
        withSubmodules: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: build using dockerfile
        image: yobasystems/alpine-docker
        commands:
        - echo @project_name@
        useTTY: true
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      retryCondition: never
      maxRetries: 3
      retryDelay: 30
      cpuRequirement: 500
      memoryRequirement: 256
      timeout: 3600
    
  • Stephen S changed title 4 years ago
    Previous Value Current Value
    Using a dockerfile
    Building a docker image using a dockerfile then pushing it to my registry
  • Robin Shen commented 4 years ago

    I just wrote a tutorial on this:

    https://code.onedev.io/projects/162/blob/main/pages/build-image.md?initial-new-path=build-image.md

    Let me know if you encounter any problems.

  • Stephen S commented 4 years ago

    Thanks Robin for responding so fast. I had a look at the code and am puuzzled by this line in the build CI step:

    image.png

    My question was and still is: what is the path of the dockerfile? I do not see it here either...

  • Robin Shen commented 4 years ago

    When a command step is executed, the current directory is repository root. So if you add a ls command to list files of current directory, you will see Dockerfile there along side with other files in the repository root.

  • Stephen S commented 4 years ago

    Thanks for the prompt response. That should be written in bold on top of your documentation IMO ;o))

  • Robin Shen commented 4 years ago

    Thanks for the suggestion. Will make this information explicit.

  • Stephen S commented 4 years ago

    So I have changed my code to display subfolders of the ``root` folder:

    version: 13
    jobs:
    - name: build
      jobExecutor: srv-shell
      steps:
      - !CheckoutStep
        name: checkout
        cloneCredential: !DefaultCredential {}
        withLfs: false
        withSubmodules: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: build using dockerfile
        image: yobasystems/alpine-docker
        commands:
        - find /root -type d
        useTTY: true
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      retryCondition: never
      maxRetries: 3
      retryDelay: 30
      cpuRequirement: 500
      memoryRequirement: 256
      timeout: 3600
    

    Here is what I get: I cannot see the files from the Git repo...

    08:47:39Waiting for resources...
    08:47:39Executing job with executor 'srv-shell'...
    08:47:39Allocating job caches...
    08:47:39Copying job dependencies...
    08:47:39Running step "checkout"...
    08:47:39Checking out code...
    08:47:39Step "checkout" is successful
    08:47:39Running step "build using dockerfile"...
    08:47:39/root
    08:47:39/root/.config
    08:47:39/root/.config/jgit
    08:47:39/root/.ssh
    08:47:39/root/.java
    08:47:39/root/.java/fonts
    08:47:39/root/.java/fonts/1.8.0_292
    08:47:39/root/bin
    08:47:39Step "build using dockerfile" is successful
    08:47:40Job finished
    

    What am I doing wrong?

  • Robin Shen commented 4 years ago

    I mean repository root, not the literal directory /root. Change your command find /root -type d as a simple ls to list content of current directory, you will see all files in the repository root (or top level directory of git repo)

  • Stephen S commented 4 years ago

    Oh OK, get it now... And I can confirm it is the case. Thanks!

  • Robin Shen changed state to 'Closed' 4 years ago
    Previous Value Current Value
    Open
    Closed
issue 1/1
Type
Question
Priority
Normal
Assignee
Issue Votes (0)
Watchers (3)
Reference
OD-467
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover