Closed22

Earthly触ってみる

Futa HirakobaFuta Hirakoba

You will notice that the recipes look very much like Dockerfiles. This is an intentional design decision. Existing Dockerfiles can be ported to earthfiles by copy-pasting them over and then tweaking them slightly. Compared to Dockerfile syntax, some commands are new (like SAVE ARTIFACT), others have additional semantics (like COPY +target/some-artifact) and other semantics have been removed (like FROM ... AS ... and COPY --from).
https://docs.earthly.dev/basics#a-simple-earthfile

  • earthfileはdockerfileに似ている
  • 既存のdockerfileをコピペして微調整すればearthfileに移植できる
  • SAVE ARTIFACTのような新規コマンドがある
  • COPY +target/some-artifactのような文脈が追加されたコマンドがある
  • FROM ... AS ...COPY --from ...のような文脈が削除されたコマンドがある
Futa HirakobaFuta Hirakoba

You might notice the command COPY +build/... ..., which has an unfamiliar form. This is a special type of COPY, which can be used to pass artifacts from one target to another. In this case, the target build (referenced as +build) produces an artifact, which has been declared with SAVE ARTIFACT, and the target docker copies that artifact in its build environment.
https://docs.earthly.dev/basics#a-simple-earthfile

COPY +target/some-artifactは特殊なCOPY
あるターゲットから別のターゲットにアーティファクトを渡すために使用できる。ターゲットはSAVE ARTIFACTでアーティファクトを保存している必要がある。

Futa HirakobaFuta Hirakoba

With Earthly you have the ability to pass such artifacts or images between targets within the same Earthfile, but also across different Earthfiles across directories or even across repositories. To read more about this, see the target, artifact and image referencing guide.
https://docs.earthly.dev/basics#a-simple-earthfile

アーティファクトやイメージはディレクトリやリポジトリを超えた異なるEarthfile間で共有できる[1]

脚注
  1. つまり、イメージやアーティファクトをGitHub Packagesといったレジストリにアップロードする必要がないってことか?参照しておけばローカルでそれらをビルドして使えるようにするってことだろうか? ↩︎

Futa HirakobaFuta Hirakoba

ターゲットの指定方法 https://docs.earthly.dev/basics#a-simple-earthfile

  • ローカルリポジトリ && 同ディレクトリ
    • +some-target
  • ローカルリポジトリ && 異ディレクトリ
    • ./some/local/path+some-target
    • 相対パス + ターゲット名
  • リモートリポジトリ
    • github.com/someone/someproject/a/deep/dir:v1.2.3+some-target
    • GitHub URL プロジェクトルートからの相対パス : タグ名 + ターゲット名
Futa HirakobaFuta Hirakoba

https://github.com/korosuke613/playground/tree/main/earthly/a-simple-earthfile

earthly +buildしてみる
まずはearthly/buildkitdというイメージをプルしてきた。

❯ earthly +build
           buildkitd | Starting buildkit daemon as a docker container (earthly-buildkitd)...
v0.5.7: Pulling from earthly/buildkitd
f84cab65f19f: Pull complete 
c37d30c392a1: Pull complete 
0d9c3c684c2b: Pull complete 
72ef90c81cde: Pull complete 
3c9ab012bd01: Pull complete 
49580714a781: Pull complete 
c62ec5d03aee: Pull complete 
e5304ed25f66: Pull complete 
21bc80906502: Pull complete 
9ee0b4595e31: Pull complete 
cef205674e15: Pull complete 
5c19a43e44a7: Pull complete 
45a1cb8f24c8: Pull complete 
843c550853fa: Pull complete 
b7f2b31151d2: Pull complete 
69501f5db8af: Pull complete 
9632a361427f: Pull complete 
Digest: sha256:cddd4cd70b507cd2cf0deb4a3441d04b54837d6cfab7ac2d7824319fbe7726c3
Status: Downloaded newer image for earthly/buildkitd:v0.5.7
docker.io/earthly/buildkitd:v0.5.7
           buildkitd | ...Done
No ssh auth socket detected or zero keys loaded; falling back to https for auto auth values
Error: resolve build context for target +build: No Earthfile nor build.earth file found for target +build

Error: resolve build context for target +build: No Earthfile nor build.earth file found for target +build
ディレクトリを間違えてた。こんなふうなエラーになった。

Futa HirakobaFuta Hirakoba

ディレクトリ移動してやり直し。
途中golang:1.15-alpine3.13をプルしてたところは省略。

cd earthly/go
❯ earthly +build            
           buildkitd | Found buildkit daemon as docker container (earthly-buildkitd)
No ssh auth socket detected or zero keys loaded; falling back to https for auto auth values
golang:1.15-alpine3.13 | --> Load metadata linux/amd64
               +base | --> FROM golang:1.15-alpine3.13
             context | --> local context .
               +base | [          ] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a[██████████] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a99a71578b574a63172ea7d2415c60ae5e2bc0a ... 100%
             context | [██████████] transferring .: ... 100%
               +base | [          ] sha256:d9e3b7eac99f4b699447dd3da27a57e5ec5ea823f8e3fe6ccaa016410de8caf0 ... 
               +base | --> WORKDIR /go-example
              +build | --> COPY main.go .
              +build | --> RUN go build -o build/go-example main.go
              +build | --> SAVE ARTIFACT build/go-example +build/go-example AS LOCAL build/go-example
              output | --> exporting outputs
              output | [██████████] copying files ... 100%
              output | [██████████] sending tarballs ... 100%
================================ SUCCESS [main] ================================
              +build | Artifact github.com/korosuke613/playground:main+build/go-example as local build/go-example

baseとなるイメージを用意して作業ディレクトリに移動してbuildの中のコマンドを実行していってるっぽい。
SAVE ARTIFACTbuild以下にgo-exampleという実行ファイルが生まれた。
これはgitに登録する必要があるのか???

Futa HirakobaFuta Hirakoba

今度はdockerをビルドしてみる

❯ earthly +docker
           buildkitd | Found buildkit daemon as docker container (earthly-buildkitd)
No ssh auth socket detected or zero keys loaded; falling back to https for auto auth values
golang:1.15-alpine3.13 | --> Load metadata linux/amd64
               +base | --> FROM golang:1.15-alpine3.13
             context | --> local context .
               +base | [          ] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a[██████████] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a99a71578b574a63172ea7d2415c60ae5e2bc0a ... 100%
               +base | *cached* --> WORKDIR /go-example
             context | [██████████] transferring .: ... 100%
              +build | *cached* --> COPY main.go .
              +build | *cached* --> RUN go build -o build/go-example main.go
              +build | *cached* --> SAVE ARTIFACT build/go-example +build/go-example
             +docker | --> COPY +build/go-example ./
              output | --> exporting outputs
              output | [██████████] exporting layers ... 100%
              output | [          ] exporting manifest sha256:0fe3d2c372ba15fe2c015e972192f986dff8d50aca44ac9ace9e3654[██████████] exporting manifest sha256:0fe3d2c372ba15fe2c015e972192f986dff8d50aca44ac9ace9e36543d23a866 ... 100%
              output | [          ] exporting config sha256:d9af900b50620f6c1bbb6d6df83527651350c76919abcf58df0ff5fea2[██████████] exporting config sha256:d9af900b50620f6c1bbb6d6df83527651350c76919abcf58df0ff5fea295c3e9 ... 100%
              output | [██████████] copying files ... 100%
              output | [██████████] sending tarballs ... 100%
================================ SUCCESS [main] ================================
cb381a32b229: Loading layer  2.812MB/2.812MB
9f6187760448: Loading layer  281.3kB/281.3kB
5f99296f8773: Loading layer     153B/153B
9617f2c10db0: Loading layer  106.8MB/106.8MB
44402b5de9fd: Loading layer     156B/156B
e91baf99e366: Loading layer     106B/106B
f38f187e5af3: Loading layer  1.113MB/1.113MB
Loaded image: go-example:latest
             +docker | Image github.com/korosuke613/playground:main+docker as go-example:latest
              +build | Artifact github.com/korosuke613/playground:main+build/go-example as local build/go-example

basebuildはキャッシュ済みだった。成果物がなかったりdockerイメージがなかったら必要に応じてビルドするのだろう。

docker images 
REPOSITORY            TAG     IMAGE ID    CREATED    SIZE
go-example           latest    d9af900b5062    2 minutes ago    302MB
earthly/buildkitd    v0.5.7    8437be9cd4be    5 days ago    212MB

でもdocker imagesしたらdockerで生成したgo-exampleしかイメージは生まれてなかった。つまり、buildの内容のイメージは残さないのか。エコだけど繰り返し行おうとしたらあった方が嬉しいかも??

Futa HirakobaFuta Hirakoba

本当にできてるか確認。

❯ docker run --rm go-example:latest
hello world

ちゃんとできてる

Futa HirakobaFuta Hirakoba

Adding dependencies in the mixもやってみる

https://github.com/korosuke613/playground/tree/main/earthly/adding-dependencies-in-the-mix

❯ docker run --rm go-adding-dependencies-in-the-mix:latest
time="2021-03-21T06:40:50Z" level=info msg="hello world"

ちゃんと動いた。

However, as we build this new setup and make changes to the main source code, we notice that the dependencies are downloaded every single time we change the source code. While the build is not necessarily incorrect, it is inefficient for proper development speed.
https://docs.earthly.dev/basics#adding-dependencies-in-the-mix

  • ソースコードを変更するたびに依存パッケージをダウンロードしてしまう
  • このビルドでもいいけど、開発速度は非効率的になってしまう[1]
❯ earthly +build
           buildkitd | Found buildkit daemon as docker container (earthly-buildkitd)
No ssh auth socket detected or zero keys loaded; falling back to https for auto auth values
golang:1.15-alpine3.13 | --> Load metadata linux/amd64
               +base | --> FROM golang:1.15-alpine3.13
             context | --> local context .
               +base | [          ] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a[██████████] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a99a71578b574a63172ea7d2415c60ae5e2bc0a ... 100%
             context | [██████████] transferring .: ... 100%
               +base | *cached* --> WORKDIR /go-example
              +build | *cached* --> COPY go.mod go.sum .
              +build | --> COPY main.go .
              +build | --> RUN go build -o build/go-example main.go
              +build | go: downloading github.com/sirupsen/logrus v1.5.0
              +build | go: downloading golang.org/x/sys v0.0.0-20190422165155-953cdadca894
              +build | --> SAVE ARTIFACT build/go-example +build/go-example AS LOCAL build/go-example
              output | --> exporting outputs
              output | [██████████] copying files ... 100%
              output | [██████████] sending tarballs ... 100%
================================ SUCCESS [main] ================================
              +build | Artifact github.com/korosuke613/playground:main+build/go-example as local build/go-example

なるほと。確かにmain.goが変更されて依存関係が再ダウンロードされている

               +base | *cached* --> WORKDIR /go-example
              +build | *cached* --> COPY go.mod go.sum .
              +build | --> COPY main.go .
              +build | --> RUN go build -o build/go-example main.go
              +build | go: downloading github.com/sirupsen/logrus v1.5.0
              +build | go: downloading golang.org/x/sys v0.0.0-20190422165155-953cdadca894
脚注
  1. 他にいい方法があるってこと? ↩︎

Futa HirakobaFuta Hirakoba

Efficient caching of dependenciesやってみる。
上で出た問題を解決するっぽい。依存関係をキャッシュする良い方法っぽい

The reason the build is inefficient is because we have not made proper use of caching. When a file changes, the corresponding COPY command is re-executed without cache, causing all commands after it to also re-execute without cache.
https://docs.earthly.dev/basics#efficient-caching-of-dependencies

  • ビルド効率が悪いのはキャッシュを適切に利用していないから。
  • ファイルが変更されると対応するCOPYコマンドがキャッシュなしで実行される。それ以降のコマンドももちろんキャッシュなし

If, however, we could first download the dependencies and only afterwards copy and build the code, then the cache would be reused every time we changed the code.
For a primer into Dockerfile layer caching see this article. The same principles apply to Earthfiles.
https://docs.earthly.dev/basics#efficient-caching-of-dependencies

  • 最初に依存ファイルをダウンロードし、その後コードをコピーしてビルドできればコードを変更するたびにキャッシュが再利用される
  • Dockerfileのレイヤーキャッシングの原理と同じ
❯ earthly +build
           buildkitd | Found buildkit daemon as docker container (earthly-buildkitd)
No ssh auth socket detected or zero keys loaded; falling back to https for auto auth values
golang:1.15-alpine3.13 | --> Load metadata linux/amd64
               +base | --> FROM golang:1.15-alpine3.13
             context | --> local context .
               +base | [          ] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a[██████████] resolve docker.io/library/golang:1.15-alpine3.13@sha256:a025015951720f3227acd51b0a99a71578b574a63172ea7d2415c60ae5e2bc0a ... 100%
             context | [██████████] transferring .: ... 100%
               +base | *cached* --> WORKDIR /go-example
              +build | *cached* --> COPY go.mod go.sum .
              +build | *cached* --> RUN go mod download
              +build | *cached* --> SAVE ARTIFACT go.sum +build/go.sum AS LOCAL go.sum
              +build | --> COPY main.go .
              +build | *cached* --> SAVE ARTIFACT go.mod +build/go.mod AS LOCAL go.mod
              +build | --> RUN go build -o build/go-example main.go
              +build | --> SAVE ARTIFACT build/go-example +build/go-example AS LOCAL build/go-example
              output | --> exporting outputs
              output | [██████████] copying files ... 100%
              output | [██████████] sending tarballs ... 100%
================================ SUCCESS [main] ================================
              +build | Artifact github.com/korosuke613/playground:main+build/go.mod as local go.mod
              +build | Artifact github.com/korosuke613/playground:main+build/go.sum as local go.sum
              +build | Artifact github.com/korosuke613/playground:main+build/go-example as local build/go-example

なるほど確かにgo mod downloadを先にやることでキャッシュが効いている。

              +build | *cached* --> RUN go mod download
              +build | *cached* --> SAVE ARTIFACT go.sum +build/go.sum AS LOCAL go.sum
              +build | --> COPY main.go .
              +build | *cached* --> SAVE ARTIFACT go.mod +build/go.mod AS LOCAL go.mod
              +build | --> RUN go build -o build/go-example main.go
              +build | --> SAVE ARTIFACT build/go-example +build/go-example AS LOCAL build/go-example
    # Also save these back to host, in case go.sum changes.
    SAVE ARTIFACT go.mod AS LOCAL go.mod
    SAVE ARTIFACT go.sum AS LOCAL go.sum

この二つの文はローカルのgo.modgo.sumを更新しているのね。

Futa HirakobaFuta Hirakoba

Reduce code duplicationをやっていき。

In some cases, the dependencies might be used in more than one build target. For this use case, we might want to separate dependency downloading and reuse it. For this reason, let's consider breaking this out into a separate build target, called deps. We can then inherit from deps by using the command FROM +deps.
https://docs.earthly.dev/basics#reduce-code-duplication

  • 複数のビルドで依存関係を使用する場合、依存関係のダウンロードを分離して再利用したい。
  • そのため依存関係のダウンロードをするビルドを作ってそれを継承すればDRY

Note that in our case, only the JavaScript version has an example where FROM +deps is used in more than one place: both in build and in docker. Nevertheless, all versions show how dependencies may be separated.
https://docs.earthly.dev/basics#reduce-code-duplication

  • この例だとjsくらいしか複数のビルドで利用してないけどね。
  • とはいえビルドを分離するのは大事

Notice how at the end of the deps recipe, we issued a SAVE IMAGE command. In this case, it is not for the purpose of saving as an image that would be used outside of the build: the command has no docker tag associated with it. Instead, it is for the purpose of reusing the image within the build, from another target (via FROM +deps).
https://docs.earthly.dev/basics#reduce-code-duplication

  • depsの最後にSAVE IMAGEコマンドがある。
  • ビルド外で使用するイメージとして保存するわけではない。
  • このコマンドにはdockerタグがついていない。
  • 代わりに別のターゲット(FROM +deps)からビルド内でイメージを再利用する目的

いや、サンプルコードにdepsの最後にSAVE IMAGEコマンドないんだが???

昔は必要だったけど今入らなくなったということか?
実行してみよう

実行してみたが、今までのキャッシュが働いてしまっているので、キャッシュを消す

❯ earthly prune
           buildkitd | Found buildkit daemon as docker container (earthly-buildkitd)

pruneしたらbaseイメージまで消しおった...
そこは消さなくてよかった。

実行

❯ earthly +build
           buildkitd | Found buildkit daemon as docker container (earthly-buildkitd)
No ssh auth socket detected or zero keys loaded; falling back to https for auto auth values
golang:1.15-alpine3.13 | --> Load metadata linux/amd64
               +base | --> FROM golang:1.15-alpine3.13
             context | --> local context .
               +base | --> WORKDIR /go-example
               +deps | --> COPY go.mod go.sum ./
               +deps | --> RUN go mod download
              +build | --> COPY main.go .
               +deps | --> SAVE ARTIFACT go.mod +deps/go.mod AS LOCAL go.mod
               +deps | --> SAVE ARTIFACT go.sum +deps/go.sum AS LOCAL go.sum
              +build | --> RUN go build -o build/go-example main.go
              +build | --> SAVE ARTIFACT build/go-example +build/go-example AS LOCAL build/go-example
              output | --> exporting outputs
              output | [██████████] copying files ... 100%
              output | [██████████] sending tarballs ... 100%
================================ SUCCESS [main] ================================
              +build | Artifact github.com/korosuke613/playground:main+build/go-example as local build/go-example
               +deps | Artifact github.com/korosuke613/playground:main+deps/go.mod as local go.mod
               +deps | Artifact github.com/korosuke613/playground:main+deps/go.sum as local go.sum

やっぱりSAVE IMAGEしなくてもいけるな。昔はダメだったのかも。

Futa HirakobaFuta Hirakoba

GitHub Actions化してみるか
https://docs.earthly.dev/ci-examples/gh-actions-integration

サンプルコードはdocker loginしてる。今回は必要最低限にしたいのでやらない

# .github/workflows/ci.yml

name: Earthly Go

on:
  pull_request:
    branches: 
      - main

jobs:
  reduce-code-duplication:
    runs-on: ubuntu-latest
    env:
      FORCE_COLOR: 1
    defaults:
      run:
        working-directory: earthly-reduce-code-duplication
    steps:
    - uses: actions/checkout@v2
    - name: Put back the git branch into git (Earthly uses it for tagging)
      run: |
        branch=""
        if [ -n "$GITHUB_HEAD_REF" ]; then
          branch="$GITHUB_HEAD_REF"
        else
          branch="${GITHUB_REF##*/}"
        fi
        git checkout -b "$branch" || true
    - name: Download latest earthly
      run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
    - name: Earthly version
      run: earthly --version
    - name: Run build
      run: earthly --push +build

とりあえず実行

Run branch=""
  branch=""
  if [ -n "$GITHUB_HEAD_REF" ]; then
    branch="$GITHUB_HEAD_REF"
  else
    branch="${GITHUB_REF##*/}"
  fi
  git checkout -b "$branch" || true
  shell: /usr/bin/bash -e {0}
  env:
    FORCE_COLOR: 1
Error: No such file or directory

早速失敗したんだけど。
Put back the git branch into git (Earthly uses it for tagging)
これってどういう意味だ??

Futa HirakobaFuta Hirakoba
Run sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'
Error: No such file or directory

うーん。https://github.com/korosuke613/playground/runs/2158745022?check_suite_focus=true

リンクがおかしい?
いや、ちゃんとダウンロードできる。

調査する

❯ docker run --rm -it ubuntu bash
root@899ab282dd3f:/# apt update
root@899ab282dd3f:/# apt install wget
root@899ab282dd3f:/# /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'
--2021-03-21 07:41:24--  https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64
Resolving github.com (github.com)... 52.69.186.44
Connecting to github.com (github.com)|52.69.186.44|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/246903803/9d3d8300-8589-11eb-9824-6fa70c6a5bc3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210321%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210321T074124Z&X-Amz-Expires=300&X-Amz-Signature=a18f266c4fcdeb609555c2357c8a04d177d7c4dc541a6e38c12b4667f2312d8c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=246903803&response-content-disposition=attachment%3B%20filename%3Dearthly-linux-amd64&response-content-type=application%2Foctet-stream [following]
--2021-03-21 07:41:24--  https://github-releases.githubusercontent.com/246903803/9d3d8300-8589-11eb-9824-6fa70c6a5bc3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210321%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210321T074124Z&X-Amz-Expires=300&X-Amz-Signature=a18f266c4fcdeb609555c2357c8a04d177d7c4dc541a6e38c12b4667f2312d8c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=246903803&response-content-disposition=attachment%3B%20filename%3Dearthly-linux-amd64&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.108.154, 185.199.109.154, 185.199.110.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.108.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 30320056 (29M) [application/octet-stream]
Saving to: '/usr/local/bin/earthly'

/usr/local/bin/ea 100%[============>]  28.92M  1.76MB/s    in 11s 

ubuntuコンテナ内だと普通に実行できたな。
/usr/shがactionsには無いとか?

Futa HirakobaFuta Hirakoba
Run sudo bash -c 'wget https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'
Error: No such file or directory

やっぱダメだなー
コマンド分けるか

Run wget https://github.com/earthly/earthly/releases/download/v0.5.7/earthly-linux-amd64 -O /usr/local/bin/earthly
Error: No such file or directory

あー/usr/local/binが無いんじゃね?
mkdir -p /usr/local/binすればいいのでは?

Run mkdir -p /usr/local/bin
Error: No such file or directory

なんで???pオプションつけてるのに
sudoしてもダメだった。

しゃーないからホームディレクトリ直下に置いてみるか

Futa HirakobaFuta Hirakoba
    defaults:
      run:
        working-directory: earthly-reduce-code-duplication

これ外したらいけた。
working-directoryがおかしい???

no such file or directory は cd するときに起こってた説

あああ...
pathミスってた.....
earthly-reduce-code-duplicationじゃなくて./earthly/reduce-code-duplication

Futa HirakobaFuta Hirakoba

きたーーーーーー https://github.com/korosuke613/playground/runs/2158848661?check_suite_focus=true

              output | --> exporting outputs
================================ SUCCESS [main] ================================
=============================== SUCCESS [--push] ===============================
              +build | Artifact github.com/korosuke613/playground:HEAD+build/go-example as local build/go-example
               +deps | Artifact github.com/korosuke613/playground:HEAD+deps/go.mod as local go.mod
               +deps | Artifact github.com/korosuke613/playground:HEAD+deps/go.sum as local go.sum

どこにpushしてるんだ???
そして、HEADというタグがついてる。

    - name: Put back the git branch into git (Earthly uses it for tagging)
      run: |
        branch=""
        if [ -n "$GITHUB_HEAD_REF" ]; then
          branch="$GITHUB_HEAD_REF"
        else
          branch="${GITHUB_REF##*/}"
        fi
        git checkout -b "$branch" || true

ここでこれが必要になるのか

              +build | Artifact github.com/korosuke613/playground:earthly/ci+build/go-example as local build/go-example
               +deps | Artifact github.com/korosuke613/playground:earthly/ci+deps/go.mod as local go.mod
               +deps | Artifact github.com/korosuke613/playground:earthly/ci+deps/go.sum as local go.sum

うん。ちゃんとタグがブランチ名でついた https://github.com/korosuke613/playground/runs/2158859304?check_suite_focus=true

Futa HirakobaFuta Hirakoba

--push

Marks the command as a "push command". Push commands are only executed if all other non-push instructions succeed. In addition, push commands are never cached, thus they are executed on every applicable invocation of the build.

  • 全ての非pushコマンドが成功した場合のみに実行される
  • pushコマンドはキャッシュされない。常に実行される

よくわからん。実際にどこかにpushするわけではないらしい。最終成果物としてマークするという意味だろうか?

Push commands were introduced to allow the user to define commands that have an effect external to the build. This kind of effects are only allowed to take place if the entire build succeeds. Good candidates for push commands are uploads of artifacts to artifactories, commands that make a change to an external environment, like a production or staging environment.
Note that non-push commands are not allowed to follow a push command within a recipe.

  • pushコマンド導入の理由はユーザがビルドの外部に影響を与えるコマンドを定義できるようにするため。
  • ビルド全体が成功した場合にのみ実行されることが許される
  • 適している例
    • アーティファクトリーへのアーティファクトのアップロード
    • 本番環境やステージング環境などの外部環境に変更を加える
  • レシピ内ではプッシュコマンド以外のコマンドを後に続けることができない

最終成果物なのはわかったけど、CLIのオプションになってる理由がわからない

このスクラップは2021/03/21にクローズされました