1- name : CI-CD build and deploy docker images based on the last commit in the main branch
2- run-name : " Commit id ${{ github.sha }}: CI-CD build and deploy docker images based on the commit id in the main branch"
1+ name : CI-CD build and deploy docker images based on the last commit in the target branch
2+ run-name : " Commit id ${{ github.sha }}: CI-CD build and deploy docker images based on the commit id in the ${{ inputs.checkout_ref == '' && github.ref_name || inputs.checkout_ref }} branch"
33
44env :
55 APPLICATION : " erigon"
99 CHECKOUT_REF : " main"
1010 DOCKERHUB_REPOSITORY : " erigontech/erigon"
1111 LABEL_DESCRIPTION : " [docker image built on a last commit id from the main branch] Erigon is an implementation of Ethereum (execution layer with embeddable consensus layer), on the efficiency frontier. Archive Node by default."
12- KEEP_IMAGES : 100
1312
1413on :
1514 push :
1615 branches :
1716 - ' main'
17+ - ' docker_pectra'
1818 paths-ignore :
1919 - ' .github/**'
2020 workflow_dispatch :
21+ inputs :
22+ checkout_ref :
23+ required : false
24+ type : string
25+ default : ' '
26+ description : ' The branch to checkout and build artifacts from (in case of manual run). Default is "" .'
2127
2228jobs :
23- define_matrix :
24- runs-on : ubuntu-latest
25- outputs :
26- os : ${{ steps.os.outputs.os }}
27-
28- steps :
29- - name : Define os
30- id : os
31- run : echo 'os=ubuntu-latest' >> "$GITHUB_OUTPUT"
3229
3330 Build :
34- needs : define_matrix
35- runs-on : ${{ needs.define_matrix.outputs.os }}
31+ runs-on : ubuntu-latest
3632 timeout-minutes : 45
3733 outputs :
3834 docker_build_tag : ${{ steps.built_tag_export.outputs.docker_build_tag }}
3935
4036 steps :
41- - name : Fast checkout git repository
37+ - name : Fast checkout git repository, git ref ${{ inputs.checkout_ref == '' && github.ref_name || inputs.checkout_ref }}
4238 uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # # 4.1.7 release
4339 with :
4440 repository : ${{ env.APP_REPO }}
4541 fetch-depth : 1
46- ref : ${{ env.CHECKOUT_REF }}
42+ ref : ${{ inputs.checkout_ref == '' && github.ref || inputs.checkout_ref }}
4743 path : ' erigon'
4844
4945 - name : Setup go env and cache
5046 uses : actions/setup-go@v5
5147 with :
52- go-version : ' >=1.22 '
53- go-version-file : ' erigon/go.mod '
48+ go-version : ' >=1.23 '
49+ cache : ${{ contains(fromJSON('["refs/heads/main","refs/heads/docker_pectra"]'), github.ref) }}
5450 cache-dependency-path : |
5551 erigon/go.sum
5652
53+ - name : Define variables
54+ id : def_docker_vars
55+ # # Idea is:
56+ # # latest image: erigontech/erigon:${tag_name}${latest_suffix}
57+ # # commit id image: erigontech/erigon:${tag_name}-${short_commit_id}
58+ run : |
59+ branch_name="${{ inputs.checkout_ref == '' && github.ref_name || inputs.checkout_ref }}"
60+ case "$branch_name" in
61+ "main" )
62+ export tag_name='main';
63+ export keep_images=100;
64+ export latest_suffix='-latest'
65+ export binaries="erigon integration rpcdaemon"
66+ ;;
67+ "docker_pectra" )
68+ export tag_name='docker_pectra';
69+ export keep_images=5;
70+ export latest_suffix='';
71+ export binaries="erigon caplin diag devnet downloader evm hack integration rpcdaemon rpctest sentinel sentry state txpool"
72+ ;;
73+ * )
74+ # use last string after last slash '/' by default if branch contains slash:
75+ export tag_name=$(echo ${{ inputs.checkout_ref }} | sed -e 's/.*\///g' );
76+ export keep_images=0;
77+ export latest_suffix=''
78+ export binaries="erigon"
79+ ;;
80+ esac
81+ echo "tag_name=${tag_name}" >> $GITHUB_OUTPUT
82+ echo "keep_images=${keep_images}" >> $GITHUB_OUTPUT
83+ echo "latest_suffix=${latest_suffix}" >> $GITHUB_OUTPUT
84+ echo "binaries=${binaries}" >> $GITHUB_OUTPUT
85+ echo "Debug ${tag_name} ${keep_images} ${latest_suffix} ${binaries}"
86+
5787 - name : Get commit id
5888 id : getCommitId
5989 run : |
@@ -75,33 +105,41 @@ jobs:
75105 uses : docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # # v3.6.1
76106
77107 - name : Build arm64
108+ env :
109+ BINARIES : ${{ steps.def_docker_vars.outputs.binaries }}
78110 run : |
79111 docker run --platform linux/arm64 \
80112 --rm -v $(pwd)/erigon:/erigon:ro \
81113 -v $(pwd)/build-arm64:/erigon-build \
82- -v ${HOME}/.cache/go-build/arm64 :/root/.cache/go-build \
114+ -v ${HOME}/.cache/go-build:/root/.cache/go-build \
83115 -v ${HOME}/go/pkg/mod:/go/pkg/mod \
84116 -w /erigon --entrypoint /bin/sh \
85117 ${{ env.BUILDER_IMAGE }} \
86- -c "apk update; apk add make git gcc libstdc++ build-base linux-headers bash ca-certificates; git config --global --add safe.directory /erigon; make GOARCH=arm64 GOBIN=/erigon-build BUILD_TAGS=nosqlite,noboltdb,nosilkworm erigon integration rpcdaemon "
118+ -c "apk update; apk add make git gcc libstdc++ build-base linux-headers bash ca-certificates; git config --global --add safe.directory /erigon; make GOARCH=arm64 GOBIN=/erigon-build BUILD_TAGS=nosqlite,noboltdb,nosilkworm,netgo ${{ env.BINARIES }} "
87119
88120 - name : Build amd64
121+ env :
122+ BINARIES : ${{ steps.def_docker_vars.outputs.binaries }}
89123 run : |
90124 docker run --platform linux/amd64 \
91125 --rm -v $(pwd)/erigon:/erigon:ro \
92126 -v $(pwd)/build-amd64:/erigon-build \
93- -v ${HOME}/.cache/go-build/amd64 :/root/.cache/go-build \
127+ -v ${HOME}/.cache/go-build:/root/.cache/go-build \
94128 -v ${HOME}/go/pkg/mod:/go/pkg/mod \
95129 -w /erigon --entrypoint /bin/sh \
96130 ${{ env.BUILDER_IMAGE }} \
97- -c "apk update; apk add make git gcc libstdc++ build-base linux-headers bash ca-certificates; git config --global --add safe.directory /erigon; make GOARCH=amd64 GOAMD64=v2 GOBIN=/erigon-build BUILD_TAGS=nosqlite,noboltdb,nosilkworm erigon integration rpcdaemon "
131+ -c "apk update; apk add make git gcc libstdc++ build-base linux-headers bash ca-certificates; git config --global --add safe.directory /erigon; make GOARCH=amd64 GOAMD64=v2 GOBIN=/erigon-build BUILD_TAGS=nosqlite,noboltdb,nosilkworm,netgo ${{ env.BINARIES }} "
98132
99- - name : Build and push multi-platform docker image based on the commit id ${{ steps.getCommitId.outputs.short_commit_id }} in the main branch
133+ - name : Build and push multi-platform docker image based on the commit id ${{ steps.getCommitId.outputs.short_commit_id }} in the ${{ GITHUB.BASE_REF }} branch
134+ id : built_tag_export
100135 env :
101- BUILD_VERSION : " main-${{ steps.getCommitId.outputs.short_commit_id }}"
136+ BUILD_VERSION : " ${{ steps.def_docker_vars.outputs.tag_name }}-${{ steps.getCommitId.outputs.short_commit_id }}"
137+ BUILD_VERSION_LATEST : " ${{ steps.def_docker_vars.outputs.tag_name }}${{ steps.def_docker_vars.outputs.latest_suffix }}"
138+ DOCKER_PUBLISH_CONDITION : ${{ steps.def_docker_vars.outputs.keep_images > 0 && format('--tag {0}:{1} ', env.DOCKER_URL, env.BUILD_VERSION) || '' }}
102139 DOCKER_URL : ${{ env.DOCKERHUB_REPOSITORY }}
103140 DOCKERFILE_PATH : Dockerfile.release
104141 run : |
142+ echo "docker_build_tag=${{ env.BUILD_VERSION }}" >> $GITHUB_OUTPUT
105143 cp -vr build-amd64 erigon/
106144 cp -vr build-arm64 erigon/
107145 cd erigon
@@ -112,8 +150,8 @@ jobs:
112150 --sbom=true \
113151 --build-arg CI_CD_MAIN_TARGET_BASE_IMAGE=${{ env.TARGET_BASE_IMAGE }} \
114152 --build-arg CI_CD_MAIN_BUILDER_IMAGE=${{ env.BUILDER_IMAGE }} \
115- --tag ${{ env.DOCKER_URL }}:${{ env.BUILD_VERSION }} \
116- --tag ${{ env.DOCKER_URL }}:main-latest \
153+ ${{ steps.def_docker_vars.outputs.keep_images > 0 && format(' --tag {0}:{1} ', env.DOCKER_URL, env.BUILD_VERSION) || '' }} \
154+ --tag ${{ env.DOCKER_URL }}:${{ env.BUILD_VERSION_LATEST }} \
117155 --label org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
118156 --label org.opencontainers.image.authors="https://github.com/erigontech/erigon/graphs/contributors" \
119157 --label org.opencontainers.image.url="https://github.com/erigontech/erigon/blob/main/Dockerfile" \
@@ -129,32 +167,39 @@ jobs:
129167 --platform linux/amd64,linux/arm64 .
130168
131169 - name : export and print docker build tag, cleanup old docker images
132- id : built_tag_export
133170 env :
134- BUILD_VERSION : " main-${{ steps.getCommitId.outputs.short_commit_id }}"
171+ BUILD_VERSION : " ${{ steps.def_docker_vars.outputs.tag_name }}-${{ steps.getCommitId.outputs.short_commit_id }}"
172+ BUILD_VERSION_LATEST : " ${{ steps.def_docker_vars.outputs.tag_name }}${{ steps.def_docker_vars.outputs.latest_suffix }}"
173+ BUILD_VERSION_CONDITION : ${{ steps.def_docker_vars.outputs.keep_images > 0 && format('{0}:{1} ',env.DOCKER_URL,env.BUILD_VERSION) || '' }}
174+ DOCKER_URL : ${{ env.DOCKERHUB_REPOSITORY }}
175+ TAG_KEY : ${{ steps.def_docker_vars.outputs.tag_name }}
176+ KEEP_IMAGES : ${{ steps.def_docker_vars.outputs.keep_images }}
135177 run : |
136- echo "docker_build_tag=${{ env.BUILD_VERSION }}" >> $GITHUB_OUTPUT
137178 echo The following docker images have been published:
138- echo "${{ env.DOCKERHUB_REPOSITORY }}:main- ${{ env.BUILD_VERSION }}"
139- echo "${{ env.DOCKERHUB_REPOSITORY }}:main-latest "
179+ echo "${{ env.DOCKERHUB_REPOSITORY }}:${{ env.BUILD_VERSION_LATEST }}"
180+ echo "${{ steps.def_docker_vars.outputs.keep_images > 0 && format('{0}:{1} ', env.DOCKER_URL,env.BUILD_VERSION) || '' }} (empty, if keep_images is 0) "
140181 echo
141- echo "Cleanup old docker images matching pattern tag ~= main-XXXXXXX"
182+ echo "Cleanup old docker images matching pattern tag ~= ${{ env.TAG_KEY }}-XXXXXXX (where XXXXXXX is a short Commit IDs)"
183+ echo "Only last $KEEP_IMAGES images will be kept."
142184 curl_cmd="curl -s -H \"Authorization: JWT ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}\" "
143185 dockerhub_url='https://hub.docker.com/v2/namespaces/erigontech/repositories/erigon'
186+ ## getting all pages in a loop from dockerhub and grepping required tag from the list of tags:
144187 my_list () {
145188 # First page:
146189 next_page="$dockerhub_url/tags?page=1&page_size=100"
147190 while [ "$next_page" != "null" ]
148191 do
149- # Print tags and push dates for tags matching "main -":
150- $curl_cmd $next_page | jq -r '.results|.[]|.name + " " + .tag_last_pushed' | grep 'main-'
192+ # Print tags and push dates for tags matching "${{ env.TAG_KEY }} -":
193+ $curl_cmd $next_page | jq -r '.results|.[]|.name + " " + .tag_last_pushed' | grep '${{ env.TAG_KEY }}-' || true
151194 next_page=`$curl_cmd $next_page | jq '.next' | sed -e 's/^\"//' -e 's/\"$//'`
152195 done
153196 }
154-
197+ echo "DEBUG: full list of images:"
198+ my_list
199+ echo "DEBUG: end of the list."
155200 my_list | tail -n+${{ env.KEEP_IMAGES }} | while read line; do
156201 echo -n "Removing docker image/published - $line "
157- current_image=$(echo $line | sed -e 's/^\(main -.\{7\}\) .*/\1/')
202+ current_image=$(echo $line | sed -e 's/^\(${{ env.TAG_KEY }} -.\{7\}\) .*/\1/')
158203 output_code=$(curl --write-out %{http_code} --output curl-output.log \
159204 -s -X DELETE -H "Accept: application/json" \
160205 -H "Authorization: JWT ${{ secrets.ORG_DOCKERHUB_ERIGONTECH_TOKEN }}" \
@@ -167,11 +212,3 @@ jobs:
167212 fi
168213 echo "Done."
169214 done
170-
171- run-kurtosis-assertoor :
172- needs : [define_matrix, Build]
173- uses : erigontech/erigon/.github/workflows/test-kurtosis-assertoor.yml@main
174- with :
175- checkout_ref : ${{ github.sha }}
176- os : ${{ needs.define_matrix.outputs.os }}
177- docker_build_tag : ${{ needs.Build.outputs.docker_build_tag }}
0 commit comments