earthly特性说明

前边有简单说明以及试用过earthly 以下是功能的一个整体说明(工具真的很不错)

整体说明

  • 基容器的构建
  • 编程语言无关
  • 可重复构建
  • 并行执行
  • 单体仓库友好
  • 多代码仓库友好

核心特性

  • 类Dockerfile语法格式
    参考
 
# Initialize the build environment - this applies to all targets.
FROM golang:1.13-alpine3.11
WORKDIR /go-example
build:
  # Copy source from local dir into the build environment,
  # run go build and save the resulting binary.
  COPY main.go .
  RUN go build -o build/go-example main.go
  SAVE ARTIFACT build/go-example AS LOCAL build/go-example
docker:
  # Copy an artifact from target +build,
  # set an entrypoint for the image and save it.
  COPY +build/go-example .
  ENTRYPOINT ["/go-example/go-example"]
  SAVE IMAGE go-example:latest
  • 构建引用
build:
  # Build the target lint (defined in the same build.earth file).
  BUILD +lint
  # Inherit image from target +some-image available in ./some/deep/dir.
  FROM ./some/deep/dir+some-image
  # Execute the build of project github.com/some-user/some-project, with
  # the target +some-binary, copying the artifact out.
  COPY github.com/some-user/some-project+some-binary/out ./
  # Execute the build within the local directory ./some/deep/dir, with
  # the target +my-binary, copying the artifact bin.
  COPY ./some/deep/dir+my-binary/bin ./
lint:
  # ...
 
 
  • 除过images&& artifacts不共享任何东西
a-target:
  # Something complex and time-consuming.
another-target:
  # Something else complex and time-consuming.
final-target:
  # This will build the two targets in parallel.
  BUILD +a-target
  BUILD +another-target
  # So would this.
  COPY +a-target/an-artifact ./
  COPY +another-target/another-artifact ./
  # And so would this (or some other combination).
  FROM +a-target
  COPY +another-target/another-artifact ./
  • 基于buildkit强大的cache能力
  • 基于参数的可复用构建
lint:
  FROM golang:1.13-alpine3.11
  RUN go get golang.org/x/lint/golint
  ARG COPY_SRC
  COPY "$COPY_SRC" ./
  RUN golint -set_exit_status .
lint-project-a:
  BUILD --build-arg COPY_SRC=./project-a +lint
lint-project-b:
  BUILD --build-arg COPY_SRC=./project-b +lint
 
 
  • 安全token管理
    基于命令行的安全token处理,token 不会存储在镜像中
 
some-target:
  RUN --push --secret GITHUB_TOKEN=+secrets/GITHUB_TOKEN github-release upload file.bin
earth --secret GITHUB_TOKEN --push +some-target
  • 支持基于本地以及远程repo 的模式
earth ./path/to/a/deep/dir+target-name
earth github.com/vladaionescu/earthly+earth-docker
同时支持自目录:
earth github.com/vladaionescu/earthly/buildkitd+buildkitd

超越dockerfile 的语法

包含了FROM,COPY,RUN, BUILD ,SAVE,GIT CLONE ....
当然以上的命令包含了好多子命令,都是超越原生dockerfile 的,详细的参考官方文档

说明

earthly 依赖docker但是强大于dockerfile,集成了dockerfile+makefile的强大能力,是一个很不错的基于容器的构建工具

参考资料

https://github.com/vladaionescu/earthly
https://docs.earthly.dev/earth-command
https://github.com/moby/buildkit

原文地址:https://www.cnblogs.com/rongfengliang/p/12742732.html