【问题标题】:Run tests using docker compose in scala在 scala 中使用 docker compose 运行测试
【发布时间】:2020-09-25 10:45:01
【问题描述】:

尝试使用 docker 执行集成测试。

下面是Dockerfile

FROM openjdk:8u232

ARG SBT_VERSION=1.2.8

# Install sbt
RUN \
  curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
  dpkg -i sbt-$SBT_VERSION.deb && \
  rm sbt-$SBT_VERSION.deb && \
  apt-get update && \
  apt-get install sbt && \
  sbt sbtVersion

ENV WORK_DIR="/test"

USER root

COPY . ${WORK_DIR}/

RUN cd ${WORK_DIR}

RUN sbt clean it:test

下面是docker-compose.yml

version: '3.7'
services:
  test:
    build:
      context: ../..
      dockerfile: Dockerfile.test
    restart: always

当我运行docker-compose -f test.yaml up 时:

它给了我错误:

Step 10/10 : RUN sbt clean it:test
 ---> Running in d9513c01439b
[warn] No sbt.version set in project/build.properties, base directory: /
[info] Set current project to root (in build file:/)
[success] Total time: 0 s, completed Jun 6, 2020 7:20:37 AM
[error] Expected ';'
[error] No such setting/task
[error] it:test

为了检查它,我从 docker 文件中删除了这一行,并将图像和 exec 构建到容器中,我的测试运行良好。

我的项目结构是:

src
  main
  it
  test

我也尝试过执行单元测试 但它给了我:

Step 10/10 : RUN sbt clean test
 ---> Running in c300fcf2bf53
[warn] No sbt.version set in project/build.properties, base directory: /
[info] Set current project to root (in build file:/)
[success] Total time: 0 s, completed Jun 6, 2020 7:19:13 AM

[success] Total time: 10 s, completed Jun 6, 2020 7:19:24 AM
Removing intermediate container c300fcf2bf53
 ---> c0215c62663d
Successfully built c0215c62663d
Successfully tagged it_it:latest
Creating it_it_1 ... done
Attaching to it_it_1

当我把它改成:

Step 10/10 : CMD sbt clean it:test
 ---> Running in 719b239fb7e4
Removing intermediate container 719b239fb7e4
 ---> f7adb19f2cb6

Successfully built f7adb19f2cb6
Successfully tagged it_it:latest
Creating it_it_1 ... done
Attaching to it_it_1
it_1     | [warn] No sbt.version set in project/build.properties, base directory: /
it_1     | [info] Set current project to root (in build file:/)
           [success] Total time: 0 s, completed Jun 6, 2020 7:32:24 AM
           [error] Expected ';'
it_1     | [error] No such setting/task
it_1     | [error] it:test
it_1     | [error]  

如何使用 compose 从 dockerfile 执行 sbt it:test?

【问题讨论】:

    标签: scala docker docker-compose sbt


    【解决方案1】:

    切换到下一个:

    RUN cd ${WORK_DIR} && sbt clean it:test
    

    dockerfile中不同的RUN不会互相影响。

    【讨论】:

      【解决方案2】:

      如果它在容器内工作,那么这必须工作:

      ENTRYPOINT cd ${WORK_DIR} && \
                  sbt clean it:test
      

      【讨论】:

        猜你喜欢
        • 2020-09-06
        • 1970-01-01
        • 1970-01-01
        • 2020-07-09
        • 1970-01-01
        • 2020-04-22
        • 2018-06-07
        • 1970-01-01
        • 2021-08-04
        相关资源
        最近更新 更多