Skip to content

Commit 7ffe4a2

Browse files
Merge pull request #2331 from keep-network/rfc-18/use-docker-build-publish-action
Switch to Docker's build-publish-action in GitHub Actions In this PR we are switching the Go building workflow to Docker's official [Build and Publish Action](https://github.com/marketplace/actions/build-and-push-docker-images). We were experiencing some issues with running out of disk space while using `satackey/action-docker-layer-caching`. It was happening because the cache size was incremented with each execution. During testing, it [grew up pretty quickly to 7 GB](https://github.com/keep-network/keep-core/runs/1880553919?check_suite_focus=true). There is an issue describing such a situation satackey/action-docker-layer-caching#55. I tried the proposed workarounds but was not satisfied with them. According to [documentation](https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy) caches will be cleaned up when their total size reaches 5 GB, but in this case, we had just one cache of 7 GB. I noticed that Docker released [an action set](https://github.com/marketplace/actions/build-and-push-docker-images) that may suit our needs. It also supports layers caching. Additionally, we can use it later for image publication to registries. During testing the cache size was around 1 GB. What is worth mentioning is a clever way how GH's cache action handles access to caches between branches. Long story short: 1. restore matches first caches on the current branch and later on parents - [read more](https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) 2. sibling branches cannot access each other's caches - [read more](https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache)
2 parents 8350928 + 27d1d87 commit 7ffe4a2

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ workflows:
339339
branches:
340340
ignore:
341341
- master
342-
- /rfc-18\/.*/
343342
context: keep-dev
344343
- build_token_dashboard_dapp:
345344
filters:

.github/workflows/client.yml

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,51 @@ jobs:
1717
build-and-test:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v1
21-
- uses: satackey/action-docker-layer-caching@v0.0.11
22-
continue-on-error: true # ignore the failure of a step and avoid terminating the job
23-
- name: Run Docker build
24-
run: |
25-
docker build \
26-
--target gobuild \
27-
--tag go-build-env .
28-
docker build \
29-
--tag keep-client .
20+
- uses: actions/checkout@v2
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v1
24+
25+
- name: Cache Docker layers
26+
uses: actions/cache@v2
27+
with:
28+
path: /tmp/.buildx-cache
29+
key: ${{ runner.os }}-buildx-${{ github.sha }}
30+
restore-keys: |
31+
${{ runner.os }}-buildx-
32+
33+
# TODO: This step was left here intentionally so we can track disk space
34+
# usage for a while. We were trying to fight problems with out of disk space
35+
# that happened due to the size of data restored from cache. The cache size
36+
# was growing linearly with subsequent workflow runs. We want to observe
37+
# available disk space for `/`. Fresh execution starts with 20 GB, we expect
38+
# to have no less than 15 GB after the cache is restored.
39+
- run: sudo df -h
40+
41+
- name: Build Docker Build Image
42+
uses: docker/build-push-action@v2
43+
with:
44+
target: gobuild
45+
tags: go-build-env
46+
build-args: |
47+
REVISION=${{ github.sha }}
48+
# VERSION= ? TODO: Configure version, sample: 1.7.6
49+
load: true # load image to local registry to use it in next steps
50+
cache-from: type=local,src=/tmp/.buildx-cache
51+
cache-to: type=local,dest=/tmp/.buildx-cache
52+
3053
- name: Create test results directory
3154
run: |
3255
mkdir test-results
56+
3357
- name: Run Go tests
3458
run: |
3559
docker run \
3660
--volume $GITHUB_WORKSPACE/test-results:/mnt/test-results \
3761
--workdir /go/src/github.com/keep-network/keep-core \
3862
go-build-env \
3963
gotestsum --junitfile /mnt/test-results/unit-tests.xml
64+
4065
- name: Publish unit test results
4166
uses: EnricoMi/publish-unit-test-result-action@v1.7
4267
if: always() # guarantees that this action always runs, even if earlier steps fail
@@ -45,3 +70,15 @@ jobs:
4570
files: ./test-results/unit-tests.xml
4671
check_name: Go Test Results # name under which test results will be presented in GitHub (optional)
4772
comment_on_pr: false # turns off commenting on Pull Requests
73+
74+
# This step is executed after the tests as we want to configure it eventually
75+
# as image publication step.
76+
- name: Build Docker Runtime Image
77+
uses: docker/build-push-action@v2
78+
with:
79+
tags: keep-client
80+
labels: |
81+
revision=${{ github.sha }}
82+
# TODO: Check branch name and publish to a registry accordingly to the
83+
# environment.
84+
# push: true # publish to registry

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
FROM golang:1.13.6-alpine3.10 AS gobuild
22

3-
ARG VERSION
4-
ARG REVISION
5-
63
ENV GOPATH=/go \
74
GOBIN=/go/bin \
85
APP_NAME=keep-client \
@@ -63,6 +60,10 @@ RUN go generate ./.../gen
6360
COPY ./ $APP_DIR/
6461
RUN go generate ./pkg/gen
6562

63+
# Client Versioning.
64+
ARG VERSION
65+
ARG REVISION
66+
6667
RUN GOOS=linux go build -ldflags "-X main.version=$VERSION -X main.revision=$REVISION" -a -o $APP_NAME ./ && \
6768
mv $APP_NAME $BIN_PATH
6869

0 commit comments

Comments
 (0)