Skip to content

Commit

Permalink
CI: Add cpp caching and rust cache fixes in CI build workflows (#2721)
Browse files Browse the repository at this point in the history
* Add ccache into ci build-dev workflow, add caching

* Fix build failure

* Disable save if rust cache condition

* Add build type

* Revert rust cache

* Remove rust caching from release and staging

* Add shared key to rust cache

* Fix ccache and rust cache key

* Switch debugging log

* Explicitly set ccache_dir

* Disable delete cpp cache on master

* Fix make.sh

* Fix ccache dir

* Fix ccache dir

* Disable save if on rust cache

* Add gh deps

* Fix base deps

* Use cpp caching to all workflows

* Install gh deps on ci setup deps

* Make.sh fixes

* Enable save only on master in build dev

* Better rename

* Fix if condition

* Enable cpp save

* Enable save cache condition check

* Switch to set-safe-directory setting

* Revert from set safe directory

* Unpack package and port into docker image instead

* Add debugging log

* Fix tar command

* Resave cache

* Save only on master

* Pass binary dir relative to docker root context

* Save rust cache separately for lint

* Better shared key naming

* Save cache

* Re-enable save only on master for rust lint

* Better rename

* Re-enable save only on master

* Rename

* Rename to docker build from binaries

* Better rename
  • Loading branch information
sieniven committed Dec 1, 2023
1 parent 79eaa98 commit 42d2183
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 40 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.code
.cache
.ccache
.idea

# Editors.
Expand Down
45 changes: 40 additions & 5 deletions .github/workflows/build-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,27 @@ jobs:

- name: Setup dependencies
run: ./make.sh ci-setup-deps

- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Restore cpp build cache
id: cpp-cache-restore
uses: actions/cache/restore@v3
with:
path: |
./build/depends
./build/src
~/.ccache
key: cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}

- name: Rust build cache
uses: Swatinem/rust-cache@v2
id: rust-cache-restore
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: ${{ env.TARGET }}

- name: Build and package
run: ./make.sh release
Expand All @@ -61,6 +74,25 @@ jobs:
name: defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}
path: ./build/defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}.${{ env.PKG_TYPE }}

- name: Delete previous cpp build cache
if: ${{ github.ref == 'refs/heads/master' && steps.cpp-cache-restore.outputs.cache-hit }}
continue-on-error: true
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete "cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}" --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save cpp build cache
if: ${{ github.ref == 'refs/heads/master' }}
uses: actions/cache/save@v3
with:
path: |
./build/depends
./build/src
~/.ccache
key: cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}

docker-build:
runs-on: ubuntu-latest
needs: [build]
Expand All @@ -69,18 +101,21 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory '*'

- name: Populate environment
run: ./make.sh ci-export-vars

- name: Download Binaries
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}
path: ./build/

- name: Unpack binaries
run: tar -xvzf ./build/defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}.${{ env.PKG_TYPE }} -C ./build/

- name: Build defi image
run: rm .dockerignore && ./make.sh docker-defi-build
run: rm .dockerignore && ./make.sh docker-build-from-binaries

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ jobs:
- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}

- name: Build and package
run: ./make.sh release

Expand Down Expand Up @@ -85,18 +80,21 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory '*'

- name: Populate environment
run: ./make.sh ci-export-vars

- name: Download Binaries
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}
path: ./build/

- name: Unpack binaries
run: tar -xvzf ./build/defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}.${{ env.PKG_TYPE }} -C ./build/

- name: Build defi image
run: rm .dockerignore && ./make.sh docker-defi-build
run: rm .dockerignore && ./make.sh docker-build-from-binaries

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/build-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ jobs:
- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}

- name: Build and package
run: ./make.sh release

Expand All @@ -57,15 +52,18 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory '*'

- name: Populate environment
run: ./make.sh ci-export-vars

- name: Download Binaries
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}
path: ./build/

- name: Unpack binaries
run: tar -xvzf ./build/defichain-${{ env.BUILD_VERSION }}-${{ env.TARGET }}.${{ env.PKG_TYPE }} -C ./build/

- name: Build defi image
run: rm .dockerignore && ./make.sh docker-defi-build
run: rm .dockerignore && ./make.sh docker-build-from-binaries
6 changes: 4 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: ./ci/extended_lint/main.sh

rust:
name: Rust Lints
name: Rust Lint
runs-on: ubuntu-latest
container: defi/ain-builder:latest
env:
Expand All @@ -57,10 +57,12 @@ jobs:
- name: Setup dependencies for user
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Rust lint cache
uses: Swatinem/rust-cache@v2
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: lint

- name: Build depends and configure
run: ./make.sh build-deps && ./make.sh build-conf
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/tests-ethlibs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,23 @@ jobs:
- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Restore cpp build cache
id: cpp-cache-restore
uses: actions/cache/restore@v3
with:
path: |
./build/depends
./build/src
~/.ccache
key: cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}

- name: Rust build cache
uses: Swatinem/rust-cache@v2
id: rust-cache-restore
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: ${{ env.TARGET }}

- name: Build binaries
run: ./make.sh build
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/tests-frontier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
TARGET: x86_64-pc-linux-gnu
MAKE_DEBUG: 0

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -30,10 +34,23 @@ jobs:
- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Restore cpp build cache
id: cpp-cache-restore
uses: actions/cache/restore@v3
with:
path: |
./build/depends
./build/src
~/.ccache
key: cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}

- name: Rust build cache
uses: Swatinem/rust-cache@v2
id: rust-cache-restore
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: ${{ env.TARGET }}

- name: Build binaries
run: ./make.sh build
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/tests-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ concurrency:

run-name: ${{ inputs.name || github.event.pull_request.title || github.ref_name }}

env:
TARGET: x86_64-pc-linux-gnu
MAKE_DEBUG: 0

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'ci/sync') || github.event_name == 'workflow_dispatch'
Expand All @@ -40,10 +44,23 @@ jobs:
- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Restore cpp build cache
id: cpp-cache-restore
uses: actions/cache/restore@v3
with:
path: |
./build/depends
./build/src
~/.ccache
key: cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}

- name: Rust build cache
uses: Swatinem/rust-cache@v2
id: rust-cache-restore
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: ${{ env.TARGET }}

- name: Build binaries
run: ./make.sh build
Expand Down Expand Up @@ -76,7 +93,6 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory '*'

- id: 'auth'
name: 'Authenticate to Google Cloud'
Expand Down Expand Up @@ -120,15 +136,14 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory '*'

- name: Download Snapshot
run: aria2c -x16 -s16 https://storage.googleapis.com/team-drop/master-datadir/datadir-${{matrix.blocks.start}}.tar.gz

- name: Create datadir
run: mkdir $DATADIR && tar -C $DATADIR -xvf datadir-${{matrix.blocks.start}}.tar.gz

- name: Download Binaries
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: defi-bins
Expand Down
24 changes: 22 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
TARGET: x86_64-pc-linux-gnu
MAKE_DEBUG: 0

jobs:
e2e-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,10 +49,23 @@ jobs:
- name: Setup user dependencies
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Restore cpp build cache
id: cpp-cache-restore
uses: actions/cache/restore@v3
with:
path: |
./build/depends
./build/src
~/.ccache
key: cpp-${{ env.TARGET }}-${{ env.BUILD_TYPE }}

- name: Rust build cache
uses: Swatinem/rust-cache@v2
id: rust-cache-restore
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: ${{ env.TARGET }}

- name: Build binaries
run: ./make.sh build
Expand Down Expand Up @@ -76,10 +93,13 @@ jobs:
- name: Setup dependencies for user
run: ./make.sh ci-setup-user-deps

- uses: Swatinem/rust-cache@v2
- name: Rust build cache
uses: Swatinem/rust-cache@v2
id: rust-cache-restore
with:
workspaces: lib -> ../build/lib/target
save-if: ${{ github.ref == 'refs/heads/master' }}
shared-key: ${{ env.TARGET }}

- name: Build deps and configure
run: ./make.sh build-deps && ./make.sh build-conf
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.code
.cache
.ccache
.idea

# Editors.
Expand Down
5 changes: 2 additions & 3 deletions contrib/dockerfiles/defi.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ ARG TARGET=x86_64-pc-linux-gnu

FROM --platform=linux/amd64 ubuntu:latest as defi
ARG TARGET
ARG PACKAGE
ARG BINARY_DIR
ENV PATH=/app/bin:$PATH
LABEL org.defichain.name="defichain"
LABEL org.defichain.arch=${TARGET}

WORKDIR /app
COPY ${PACKAGE} ./
RUN tar -xvzf ${PACKAGE} --strip-components 1
COPY ${BINARY_DIR} ./

RUN useradd --create-home defi && \
mkdir -p /data && \
Expand Down

0 comments on commit 42d2183

Please sign in to comment.