Docker镜像构建及发布 (#6)
www2 opened 4 years ago

兄弟,你这Docker镜像构建及发布到仓库文档,也太简单了,上手太难啊! 尤其是 onedev-buildspec.yml 文件不知道应该怎么配!!

  • www2 commented 4 years ago

    首先感谢您的回复!🍌 基础:Java - springboot 项目 下面是先选了建议的配置,然后加上了一行 Docker 构建命令

    version: 13
    jobs:
    - name: maven ci
      jobExecutor: Docker # 这里选了 Server Docker Executor。不清楚用途,参照示例填的
      steps:
      - !CheckoutStep
        name: checkout
        cloneCredential: !DefaultCredential {}
        withLfs: false
        withSubmodules: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: detect build version
        image: '@script:builtin:maven:determine-docker-image@'
        commands:
        - echo "Detecting project version (may require some time while downloading maven
          dependencies)..."
        - echo $(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version
          -q -DforceStdout) > buildVersion
        useTTY: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !SetBuildVersionStep
        name: set build version
        buildVersion: '@file:buildVersion@'
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: run maven
        image: '@script:builtin:maven:determine-docker-image@'
        commands:
        - mvn clean test
        useTTY: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: bulid
        image: docker:20.10.11  # 这个又是做啥用的?也不清楚
        commands:
        - docker build -tag helloworld:1.0 .  # docker 构建
        useTTY: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      triggers:
      - !BranchUpdateTrigger {}
      retryCondition: never
      maxRetries: 3
      retryDelay: 30
      cpuRequirement: 500
      memoryRequirement: 256
      caches:
      - key: maven-cache
        path: /root/.m2/repository
      timeout: 3600
    

    报错如下 "docker build" requires exactly 1 argument. See 'docker build --help'.

    Usage: docker build [OPTIONS] PATH | URL | -

    Build an image from a Dockerfile

    实在是不知道maven打包之后 jar包放在哪里,docker 构建命令如何识别到

    最后,再次感谢您的回复!🍌 🍌

  • Robin Shen commented 4 years ago
    1. Executor介绍请参考文档:https://code.onedev.io/projects/162/blob/main/pages/concepts.md#job-executor
    2. 这里用docker:20:10:11是因为这个image里有docker工具,你不是要调用docker命令行去build image吗
    3. 你的命令报错是因为docker build 应该传入--tags 而不是-tags
    4. 代码会被checkout到job workspace(文档里也说明了),然后所有的命令也会在job workspace下执行。这样你就能推算maven的jar包生成在哪里了,一般是job workspace下的target目录。可以用ls看下当前目录内容。
  • www2 commented 4 years ago
    • 第三点 不是这个原因。将建议的配置清空掉,只留 **checkout **和 **docker **命令就可以啦。
    • 第四点 Dockerfile 如下
    FROM java:8
    ADD target/HelloWorld-0.0.1-SNAPSHOT.jar /home/soft/HelloWorld-0.0.1-SNAPSHOT.jar
    EXPOSE 8080
    CMD ["java","-jar","/home/soft/HelloWorld-0.0.1-SNAPSHOT.jar"]
    MAINTAINER www2
    

    报错: ADD 指令找不到jar包

    job workspace 又得找找文档啦:sleepy:

  • Robin Shen commented 4 years ago

    明天我试下你这dockerfile

  • www2 commented 4 years ago

    终于解决啦! 默认建议 只有mvn clean test 命令,加上 mvn clean package 打包命令。 就可以正常打包构建Docker镜像啦。

  • www2 commented 4 years ago

    OneDev 功能挺强大的,就是文档差了一点点。 如果有详细的中文文档的话。相信国内用户会迅速增多的 🍌 🍌

  • Robin Shen commented 4 years ago
    谢谢!文档确实需要加强。
  • 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 (2)
Reference
onedev/manual#6
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover