-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap up Nix Build for Node Wrapper (#893)
* wip: nix build * nix build * nix docker build * add install nix * use default system * tweaks tests * parallel docker build * parallel docker build * fix docker push * rm test branch * rm toolchain file * read params from file
- Loading branch information
1 parent
ea784b0
commit 0f6c13b
Showing
5 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: nix-build | ||
on: | ||
pull_request: | ||
push: | ||
branches: [parachain] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
# Nix Flakes doesn't work on shallow clones | ||
fetch-depth: 0 | ||
- uses: cachix/install-nix-action@v16 | ||
with: | ||
install_url: https://releases.nixos.org/nix/nix-2.10.3/install | ||
- uses: cachix/cachix-action@v10 | ||
with: | ||
name: centrifuge-chain | ||
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" | ||
- name: Build centrifuge-chain | ||
run: nix build --no-allow-dirty -L |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: docker | ||
on: | ||
push: | ||
branches: [parachain] | ||
jobs: | ||
docker: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
target: [".#dockerImage", ".#dockerImageFastRuntime"] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: cachix/install-nix-action@v16 | ||
with: | ||
install_url: https://releases.nixos.org/nix/nix-2.10.3/install | ||
- name: Build Docker image | ||
run: | | ||
nix build --no-allow-dirty -L ${{ matrix.target }} | ||
docker load < result | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
- name: List images | ||
run: docker images | ||
- name: Push image to Docker Hub | ||
run: docker push --all-tags --quiet centrifugeio/centrifuge-chain |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{ | ||
description = "Nix package for centrifuge-chain"; | ||
|
||
inputs = { | ||
nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11; | ||
flake-utils = { | ||
url = github:numtide/flake-utils; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
gitignore = { | ||
url = github:hercules-ci/gitignore.nix; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
fenix = { | ||
url = github:nix-community/fenix; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
|
||
outputs = inputs : | ||
inputs.flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = inputs.nixpkgs.legacyPackages.${system}; | ||
|
||
cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml); | ||
rustToolChainTOML = builtins.fromTOML (builtins.readFile ./rust-toolchain.toml); | ||
|
||
name = cargoTOML.package.name; | ||
# This is the program version. | ||
version = cargoTOML.package.version; | ||
# This selects a nightly Rust version, based on the date. | ||
nightly-date = pkgs.lib.strings.removePrefix "nightly-" rustToolChainTOML.toolchain.channel; | ||
# This is the hash of the Rust toolchain at nightly-date, required for reproducibility. | ||
nightly-sha256 = "sha256-CNMj0ouNwwJ4zwgc/gAeTYyDYe0botMoaj/BkeDTy4M="; | ||
|
||
|
||
# This instantiates a new Rust version based on nightly-date. | ||
nightlyRustPlatform = pkgs.makeRustPlatform { | ||
inherit | ||
(inputs.fenix.packages.${system}.toolchainOf { | ||
channel = "nightly"; | ||
date = nightly-date; | ||
sha256 = nightly-sha256; | ||
}) | ||
cargo rustc; | ||
}; | ||
|
||
# This is a mock git program, which just returns the commit-substr value. | ||
# It is called when the build process calls git. Instead of the real git, | ||
# it will find this one. | ||
git-mock = | ||
let | ||
# This evaluates to the first 7 digits of the git hash of this repo's HEAD | ||
# commit, or to "dirty" if there are uncommitted changes. | ||
commit-substr = builtins.substring 0 7 (inputs.self.rev or "dirty"); | ||
in | ||
pkgs.writeShellScriptBin "git" '' | ||
echo ${commit-substr} | ||
''; | ||
|
||
# srcFilter is used to keep out of the build non-source files, | ||
# so that we only trigger a rebuild when necessary. | ||
srcFilter = src: | ||
let | ||
isGitIgnored = inputs.gitignore.lib.gitignoreFilter src; | ||
|
||
ignoreList = [ | ||
".dockerignore" | ||
".envrc" | ||
".github" | ||
".travis.yml" | ||
"CODE_OF_CONDUCT.md" | ||
"README.md" | ||
"ci" | ||
"cloudbuild.yaml" | ||
"codecov.yml" | ||
"docker-compose.yml" | ||
"rustfmt.toml" | ||
]; | ||
in | ||
path: type: | ||
isGitIgnored path type | ||
&& builtins.all (name: builtins.baseNameOf path != name) ignoreList; | ||
in | ||
rec { | ||
defaultPackage = nightlyRustPlatform.buildRustPackage { | ||
pname = name; | ||
inherit version; | ||
|
||
# This applies the srcFilter function to the current directory, so | ||
# we don't include unnecessary files in the package. | ||
src = pkgs.lib.cleanSourceWith { | ||
src = ./.; | ||
filter = srcFilter ./.; | ||
name = "${name}-source"; | ||
}; | ||
|
||
# This is a hash of all the Cargo dependencies, for reproducibility. | ||
cargoSha256 = "sha256-hmXhJBjc4HuyKQbxtpiIIvaL/Kl/e70sMFgdNlw4E0o="; | ||
|
||
nativeBuildInputs = with pkgs; [ clang git-mock pkg-config ]; | ||
buildInputs = with pkgs; [ openssl ] ++ ( | ||
lib.optionals stdenv.isDarwin [ | ||
darwin.apple_sdk.frameworks.Security | ||
darwin.apple_sdk.frameworks.SystemConfiguration | ||
] | ||
); | ||
|
||
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; | ||
PROTOC = "${pkgs.protobuf}/bin/protoc"; | ||
SKIP_WASM_BUILD = 1; | ||
|
||
|
||
doCheck = false; | ||
}; | ||
|
||
packages.fastRuntime = defaultPackage.overrideAttrs (base: { | ||
buildFeatures = [ "fast-runtime" ]; | ||
}); | ||
|
||
# Docker image package doesn't work on Darwin Archs | ||
packages.dockerImage = pkgs.dockerTools.buildLayeredImage { | ||
name = "centrifugeio/${name}"; | ||
tag = "${version}-nix-do-not-use"; # todo remove suffix once verified | ||
# This uses the date of the last commit as the image creation date. | ||
created = builtins.substring 0 8 inputs.self.lastModifiedDate; | ||
|
||
contents = [ | ||
pkgs.busybox | ||
inputs.self.defaultPackage.${system} | ||
]; | ||
|
||
config = { | ||
ExposedPorts = { | ||
"30333/tcp" = { }; | ||
"9933/tcp" = { }; | ||
"9944/tcp" = { }; | ||
}; | ||
Volumes = { | ||
"/data" = { }; | ||
}; | ||
Entrypoint = [ "centrifuge-chain" ]; | ||
}; | ||
}; | ||
|
||
packages.dockerImageFastRuntime = packages.dockerImage.overrideAttrs (base: { | ||
tag = "test-${version}-nix-do-not-use"; # todo remove suffix once verified | ||
contents = [ | ||
pkgs.busybox | ||
packages.fastRuntime | ||
]; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[toolchain] | ||
channel = "nightly-2022-05-09" | ||
components = [ "rustfmt", "clippy" ] | ||
targets = [ "wasm32-unknown-unknown" ] | ||
profile = "minimal" |