earthly 简单试用

前边有简单介绍多earthly,以下是一个简单的试用

安装

我使用的mac 系统,实际自己选择对应的系统

 
curl -s https://api.github.com/repos/vladaionescu/earthly/releases/latest | grep browser_download_url | grep darwin-amd64 | cut -d : -f 2- | tr -d " | wget -P /usr/local/bin/ -i - && mv /usr/local/bin/earth-darwin-amd64 /usr/local/bin/earth && chmod +x /usr/local/bin/earth

vscode 扩展

方便语法高亮处理

ext install earthly.earthfile-syntax-highlighting

基本使用

  • 一个golang 项目
main.go
package main
import "fmt"
func main() {
    fmt.Println("hello world")
}
  • build.earth
FROM golang:1.13-alpine3.11
WORKDIR /go-example
build:
    COPY main.go .
    RUN go build -o build/go-example main.go
    SAVE ARTIFACT build/go-example /go-example AS LOCAL build/go-example
docker:
    COPY +build/go-example .
    ENTRYPOINT ["/go-example/go-example"]
    SAVE IMAGE go-example:latest
  • 构建
earth +build  
or:
earth +docker
  • 效果


构建结果

  • 再次构建

发现很好的利用了cache,还是很快的

参考资料

https://docs.earthly.dev/guides/basics
https://github.com/moby/buildkit
https://github.com/vladaionescu/earthly

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