Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Docker's build-publish-action in GitHub Actions #2331

Merged
merged 7 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ workflows:
branches:
ignore:
- master
- /rfc-18\/.*/
context: keep-dev
- build_token_dashboard_dapp:
filters:
Expand Down
57 changes: 47 additions & 10 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,51 @@ jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: satackey/[email protected]
continue-on-error: true # ignore the failure of a step and avoid terminating the job
- name: Run Docker build
run: |
docker build \
--target gobuild \
--tag go-build-env .
docker build \
--tag keep-client .
- uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

# TODO: This step was left here intentionally so we can track disk space
# usage for a while. We were trying to fight problems with out of disk space
# that happened due to the size of data restored from cache. The cache size
# was growing linearly with subsequent workflow runs. We want to observe
# available disk space for `/`. Fresh execution starts with 20 GB, we expect
# to have no less than 15 GB after the cache is restored.
- run: sudo df -h

- name: Build Docker Build Image
uses: docker/build-push-action@v2
with:
target: gobuild
tags: go-build-env
build-args: |
REVISION=${{ github.sha }}
# VERSION= ? TODO: Configure version, sample: 1.7.6
load: true # load image to local registry to use it in next steps
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Create test results directory
run: |
mkdir test-results

- name: Run Go tests
run: |
docker run \
--volume $GITHUB_WORKSPACE/test-results:/mnt/test-results \
--workdir /go/src/github.com/keep-network/keep-core \
go-build-env \
gotestsum --junitfile /mnt/test-results/unit-tests.xml

- name: Publish unit test results
uses: EnricoMi/[email protected]
if: always() # guarantees that this action always runs, even if earlier steps fail
Expand All @@ -45,3 +70,15 @@ jobs:
files: ./test-results/unit-tests.xml
check_name: Go Test Results # name under which test results will be presented in GitHub (optional)
comment_on_pr: false # turns off commenting on Pull Requests

# This step is executed after the tests as we want to configure it eventually
# as image publication step.
- name: Build Docker Runtime Image
uses: docker/build-push-action@v2
with:
tags: keep-client
labels: |
revision=${{ github.sha }}
# TODO: Check branch name and publish to a registry accordingly to the
# environment.
# push: true # publish to registry
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
FROM golang:1.13.6-alpine3.10 AS gobuild

ARG VERSION
ARG REVISION

ENV GOPATH=/go \
GOBIN=/go/bin \
APP_NAME=keep-client \
Expand Down Expand Up @@ -63,6 +60,10 @@ RUN go generate ./.../gen
COPY ./ $APP_DIR/
RUN go generate ./pkg/gen

# Client Versioning.
ARG VERSION
ARG REVISION

RUN GOOS=linux go build -ldflags "-X main.version=$VERSION -X main.revision=$REVISION" -a -o $APP_NAME ./ && \
mv $APP_NAME $BIN_PATH

Expand Down