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

Reduce use of self-hosted runner and use cache #409

Merged
merged 40 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b4065bb
try to replace self-host with github runner
Kailai-Wang Mar 15, 2022
07196f4
rectify the usage of cache
Kailai-Wang Mar 15, 2022
a561d75
remove time limit
Kailai-Wang Mar 15, 2022
e5806ee
use upload/download
Kailai-Wang Mar 15, 2022
226582b
fix download path
Kailai-Wang Mar 15, 2022
7e7af38
missing checkout
Kailai-Wang Mar 15, 2022
80de5d9
use ul/dl version 3
Kailai-Wang Mar 15, 2022
1885886
try to use yaml anchor
Kailai-Wang Mar 15, 2022
d8ebed0
add feature branch trigger
Kailai-Wang Mar 15, 2022
1453857
revert anchor as its not supported
Kailai-Wang Mar 15, 2022
d1e313f
try to use buildx cache
Kailai-Wang Mar 15, 2022
11b8afc
add sccache and file-filters
Kailai-Wang Mar 16, 2022
772861f
missing checkout
Kailai-Wang Mar 16, 2022
af60a9f
fix permission
Kailai-Wang Mar 16, 2022
99b636a
move concurrency to workflow level
Kailai-Wang Mar 16, 2022
022cd77
update ts-tests dep to check the file filter
Kailai-Wang Mar 16, 2022
a107971
unuse docker/build-push-action
Kailai-Wang Mar 16, 2022
5e13561
cargo update
Kailai-Wang Mar 16, 2022
2349253
refine the file filter
Kailai-Wang Mar 16, 2022
3164e01
Merge branch 'dev' into 393-avoid-self-runner-in-CI
Kailai-Wang Mar 16, 2022
af86072
try cargo chef
Kailai-Wang Mar 16, 2022
2bb509c
reuse buildx action
Kailai-Wang Mar 16, 2022
3f50165
fix recipe path
Kailai-Wang Mar 16, 2022
2009d42
prepend cargo build with apt
Kailai-Wang Mar 16, 2022
13c8324
fix order of copy
Kailai-Wang Mar 16, 2022
a8b72b0
use self-hosted docker
Kailai-Wang Mar 16, 2022
497adc8
remove buildx
Kailai-Wang Mar 16, 2022
a04e2c8
update comment
Kailai-Wang Mar 16, 2022
d5cd48f
retry buildx
Kailai-Wang Mar 16, 2022
18d0c82
try local cache
Kailai-Wang Mar 16, 2022
ed700c4
update comment to test cached builds
Kailai-Wang Mar 16, 2022
95868a6
fix docker save
Kailai-Wang Mar 17, 2022
31e3276
modify comment to trigger GHA
Kailai-Wang Mar 17, 2022
38c4455
separate dev and prod Dockefile
Kailai-Wang Mar 17, 2022
4d2e801
more comment and TYPE
Kailai-Wang Mar 17, 2022
77f8de9
update .gitignore
Kailai-Wang Mar 17, 2022
91ea5ba
more comment
Kailai-Wang Mar 17, 2022
c6edb4b
update README
Kailai-Wang Mar 17, 2022
8f920a8
Merge branch 'dev' into 393-avoid-self-runner-in-CI
Kailai-Wang Mar 21, 2022
8a8fe2f
fix typo
Kailai-Wang Mar 22, 2022
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
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
**/polkadot
**/token-server
**/target
**/ts-tests
2 changes: 1 addition & 1 deletion .github/workflows/benchmark_runtime_weights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Build docker image
run: |
./scripts/build-docker.sh runtime-benchmarks --features=runtime-benchmarks
./scripts/build-docker.sh prod runtime-benchmarks --features=runtime-benchmarks

- name: Push docker image
run: |
Expand Down
167 changes: 152 additions & 15 deletions .github/workflows/build_and_run_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,36 @@ on:
env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-file-change:
runs-on: ubuntu-latest
outputs:
src: ${{ steps.filter.outputs.src }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

# Checks to see if any files in the PR/commit match one of the listed file types.
# We can use this filter to decide whether or not to build docker images
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
src:
- 'node/**'
- 'pallets/**'
- 'primitives/**'
- 'runtime/**'
- 'docker/Dockerfile.dev'
- '**/Cargo.lock'
- '**/Cargo.toml'
- '**/rust-toolchain.toml'

check-cargo-fmt:
runs-on: ubuntu-latest
steps:
Expand All @@ -37,7 +66,8 @@ jobs:

check-cargo-clippy:
runs-on: ubuntu-latest
needs: check-cargo-fmt
needs: [check-cargo-fmt, check-file-change]
if: needs.check-file-change.outputs.src == 'true'
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -56,41 +86,89 @@ jobs:
run: make clippy

build-docker:
if: "!contains(github.event.commits[0].message, '[SKIP CI]')"
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
# run the docker build on our self-hosted runner, which takes
# - 25min without cache, or
# - 15 min with cache
# on a standard github runner it takes 1 hour+
# see also https://github.com/litentry/litentry-parachain/issues/259
runs-on: self-hosted
needs: check-cargo-fmt
needs: [check-cargo-fmt, check-file-change]
steps:
- name: Checkout codes
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup docker buildx
uses: docker/setup-buildx-action@v1

# Syncing GHA cache seems to be very slow, we use local cache for a self-hosted runner
- name: Build docker image
timeout-minutes: 40
if: needs.check-file-change.outputs.src == 'true'
uses: docker/build-push-action@v2
with:
context: .
tags: litentry/litentry-parachain:latest
outputs: type=docker,dest=litentry-parachain.tar
push: false
file: docker/Dockerfile.dev
cache-from: type=local,src=/tmp/parachain-buildx-cache
cache-to: type=local,dest=/tmp/parachain-buildx-cache-new,mode=max

- name: Move cache
if: needs.check-file-change.outputs.src == 'true'
# Temp fix for constantly growing cache, see
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
run: |
rm -rf /tmp/parachain-buildx-cache
mv /tmp/parachain-buildx-cache-new /tmp/parachain-buildx-cache

- name: Pull docker image optinally
if: needs.check-file-change.outputs.src == 'false'
run: |
./scripts/build-docker.sh
echo "============================="
docker images
docker pull litentry/litentry-parachain:latest
docker save litentry/litentry-parachain:latest -o litentry-parachain.tar

- name: Upload docker image
uses: actions/upload-artifact@v3
with:
name: docker-artifact
path: litentry-parachain.tar

- name: Remove dangling docker images if any
run: |
[ -z "$(docker images --filter=dangling=true -q)" ] || docker rmi -f $(docker images --filter=dangling=true -q)

run-ts-tests:
runs-on: self-hosted
runs-on: ubuntu-latest
needs: build-docker
strategy:
matrix:
chain:
- litmus
- litentry
steps:
- name: Checkout codes
uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/download-artifact@v3
with:
name: docker-artifact

- name: Load docker image
run: |
docker load -i litentry-parachain.tar

- name: Run ts tests for ${{ matrix.chain }}
timeout-minutes: 20
run: |
make test-ts-docker-${{ matrix.chain }}

- name: Archive logs if test fails
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: ${{ matrix.chain }}-ts-tests-artifacts
Expand All @@ -104,7 +182,8 @@ jobs:

run-cargo-unit-tests:
runs-on: ubuntu-latest
needs: check-cargo-fmt
needs: [check-cargo-fmt, check-file-change]
if: needs.check-file-change.outputs.src == 'true'
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -123,7 +202,14 @@ jobs:

run-cargo-runtime-tests:
runs-on: ubuntu-latest
needs: check-cargo-fmt
needs: [check-cargo-fmt, check-file-change]
if: needs.check-file-change.outputs.src == 'true'
env:
RUST_BACKTRACE: full
RUSTC_WRAPPER: sccache
SCCACHE_CACHE_SIZE: 10G
SCCACHE_DIR: /home/runner/.cache/sccache
CARGO_INCREMENTAL: 0
strategy:
matrix:
chain:
Expand All @@ -142,13 +228,64 @@ jobs:
target: wasm32-unknown-unknown
default: true

# use sccache to accelerate binary compilation
# see https://www.infinyon.com/blog/2021/04/github-actions-best-practices/
- name: Install sccache
env:
LINK: https://github.com/mozilla/sccache/releases/download
SCCACHE_VERSION: v0.2.15
run: |
SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl
mkdir -p $HOME/.local/bin
curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz
mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache
chmod +x $HOME/.local/bin/sccache
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Cache cargo registry
uses: actions/cache@v2
continue-on-error: false
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-

- name: Cache sccache
uses: actions/cache@v2
continue-on-error: false
with:
path: /home/runner/.cache/sccache
key: sccache-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
sccache-

- name: Run runtime integration tests
run: cargo test --release -p ${{ matrix.chain }}-parachain-runtime --lib

- name: Print sccache stats
run: sccache --show-stats

push-docker-image:
runs-on: self-hosted
runs-on: ubuntu-latest
needs: ["check-cargo-clippy", "run-cargo-unit-tests", "run-cargo-runtime-tests", "run-ts-tests"]
steps:
- uses: actions/download-artifact@v3
with:
name: docker-artifact

- name: Load docker image
run: |
docker load -i litentry-parachain.tar

- name: Dockerhub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Push docker image on dev branch if test passes
if: ${{ success() && (github.event_name == 'push') && (github.ref == 'refs/heads/dev') }}
run:
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/build_docker_with_args.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ name: Build docker with args
on:
workflow_dispatch:
inputs:
dockerfile_type:
type: choice
description: The type of Dockerfile to use
options:
- dev
- prod
docker_tag:
description: The tag for the built docker image
required: true
Expand All @@ -24,7 +30,7 @@ jobs:

- name: Build docker image
run: |
./scripts/build-docker.sh ${{ github.event.inputs.docker_tag }} "${{ github.event.inputs.args }}"
./scripts/build-docker.sh ${{ github.event.inputs.dockerfile_type }} ${{ github.event.inputs.docker_tag }} "${{ github.event.inputs.args }}"
echo "============================="
docker images

Expand All @@ -41,7 +47,7 @@ jobs:
docker cp $(docker create --rm litentry/litentry-parachain:${{ github.event.inputs.docker_tag }}):/usr/local/bin/litentry-collator .

- name: Upload the client binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: litentry-collator
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
cp ${{ steps.srtool_build.outputs.wasm_compressed }} ${{ github.event.inputs.chain }}-parachain-runtime.compact.compressed.wasm

- name: Upload wasm artefacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.inputs.chain }}-parachain-runtime
path: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/create_release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
cp ${{ steps.srtool_build.outputs.wasm_compressed }} ${{ matrix.chain }}-parachain-runtime.compact.compressed.wasm

- name: Upload wasm artefacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.chain }}-parachain-runtime
path: |
Expand All @@ -85,7 +85,7 @@ jobs:

- name: Build docker image
run: |
./scripts/build-docker.sh ${{ env.RELEASE_TAG }}
./scripts/build-docker.sh prod ${{ env.RELEASE_TAG }}
echo "============================="
docker images

Expand All @@ -108,7 +108,7 @@ jobs:
docker cp $(docker create --rm litentry/litentry-parachain:${{ env.RELEASE_TAG }}):/usr/local/bin/litentry-collator .

- name: Upload the client binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: litentry-collator
if-no-files-found: ignore
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
fetch-depth: 0

- name: Download all artefacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3

- name: Generate release notes
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.cargo/config

**/node_modules/
**/para-*

docker/yarn.lock
docker/package.json
Expand All @@ -14,3 +13,5 @@ docker/generated-*/
ts-tests/package-lock.json

tags.lock

recipe.json
Loading