graphql-engine/v3/flake.nix
Samir Talwar a793fd479d Use Nix to build and publish Docker images. (#664)
## Description

We can use Nix to build Docker images, which gives us a few advantages:

1. the images will be cached a little better
2. aarch64 builds become easy
3. Samir is happy because the Nixification continues

## Changelog

- Add a changelog entry (in the "Changelog entry" section below) if the
changes
  in this PR have any user-facing impact. See
[changelog
guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide).
- If no changelog is required ignore/remove this section and add a
  `no-changelog-required` label to the PR.

### Product

_(Select all products this will be available in)_

- [x] community-edition
- [ ] cloud
<!-- product : end : DO NOT REMOVE -->

### Type

<!-- See changelog structure:
https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog
-->

_(Select only one. In case of multiple, choose the most appropriate)_

- [ ] highlight
- [x] enhancement
- [ ] bugfix
- [ ] behaviour-change
- [ ] performance-enhancement
- [ ] security-fix
<!-- type : end : DO NOT REMOVE -->

### Changelog entry

<!--
  - Add a user understandable changelog entry
- Include all details needed to understand the change. Try including
links to docs or issues if relevant
  - For Highlights start with a H4 heading (#### <entry title>)
  - Get the changelog entry reviewed by your team
-->

The v3 engine and dev-auth-webhook Docker images are now published for
both x86_64 (`amd64`) and aarch64 (`arm64`) architectures.

<!-- changelog-entry : end : DO NOT REMOVE -->

<!-- changelog : end : DO NOT REMOVE -->

Co-Authored-By: Philip Carlsen <philip@hasura.io>
Co-Authored-By: Gil Mizrahi <gil@hasura.io>
V3_GIT_ORIGIN_REV_ID: ae6fec45dee62a21f03b5258b57d841a16542c72
2024-06-04 14:15:41 +00:00

234 lines
8.6 KiB
Nix

{
description = "DDN Engine";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay }:
flake-utils.lib.eachDefaultSystem
(localSystem:
let
pkgs = import nixpkgs {
system = localSystem;
overlays = [ rust-overlay.overlays.default ];
};
rust = import ./nix/rust.nix {
inherit nixpkgs rust-overlay crane localSystem;
};
rust-x86_64-linux = (import ./nix/rust.nix {
inherit nixpkgs rust-overlay crane localSystem;
crossSystem = "x86_64-linux";
});
rust-aarch64-linux = (import ./nix/rust.nix {
inherit nixpkgs rust-overlay crane localSystem;
crossSystem = "aarch64-linux";
});
in
{
formatter = pkgs.nixpkgs-fmt;
packages = {
###### ENGINE
# engine binary for whichever is the local machine
engine = rust.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "engine";
};
# engine binary for x86_64-linux
engine-x86_64-linux = rust-x86_64-linux.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "engine";
};
# engine binary for aarch64-linux
engine-aarch64-linux = rust-aarch64-linux.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "engine";
};
# engine docker files for whichever is the local machine
engine-docker = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.engine;
image-name = "ghcr.io/hasura/v3-engine";
tag = "dev";
port = "3000";
};
# engine docker for x86_64-linux
engine-docker-x86_64-linux = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.engine-x86_64-linux;
architecture = "amd64";
image-name = "ghcr.io/hasura/v3-engine";
port = "3000";
};
# engine docker for aarch64-linux
engine-docker-aarch64-linux = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.engine-aarch64-linux;
architecture = "arm64";
image-name = "ghcr.io/hasura/v3-engine";
port = "3000";
};
default = self.packages.${localSystem}.engine;
###### CUSTOM_CONNECTOR
# custom-connector binary for whichever is the local machine
custom-connector = rust.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "custom-connector";
};
# custom-connector binary for x86_64-linux
custom-connector-x86_64-linux = rust-x86_64-linux.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "custom-connector";
};
# custom-connector binary for aarch64-linux
custom-connector-aarch64-linux = rust-aarch64-linux.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "custom-connector";
};
# custom-connector docker files for whichever is the local machine
custom-connector-docker = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.custom-connector;
image-name = "ghcr.io/hasura/v3-custom-connector";
tag = "dev";
port = "8181";
};
# custom-connector docker for x86_64-linux
custom-connector-docker-x86_64-linux = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.custom-connector-x86_64-linux;
architecture = "amd64";
image-name = "ghcr.io/hasura/v3-custom-connector";
port = "8181";
};
# custom-connector docker for aarch64-linux
custom-connector-docker-aarch64-linux = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.custom-connector-aarch64-linux;
architecture = "arm64";
image-name = "ghcr.io/hasura/v3-custom-connector";
port = "8181";
};
###### DEV-AUTH-WEBHOOK
# dev-auth-webhook binary for whichever is the local machine
dev-auth-webhook = rust.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "dev-auth-webhook";
};
# dev-auth-webhook binary for x86_64-linux
dev-auth-webhook-x86_64-linux = rust-x86_64-linux.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "dev-auth-webhook";
};
# dev-auth-webhook binary for aarch64-linux
dev-auth-webhook-aarch64-linux = rust-aarch64-linux.callPackage ./nix/app.nix {
version = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
pname = "dev-auth-webhook";
};
# dev-auth-webhook docker files for whichever is the local machine
dev-auth-webhook-docker = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.dev-auth-webhook;
image-name = "ghcr.io/hasura/v3-dev-auth-webhook";
tag = "dev";
port = "3050";
};
# dev-auth-webhook docker for x86_64-linux
dev-auth-webhook-docker-x86_64-linux = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.dev-auth-webhook-x86_64-linux;
architecture = "amd64";
image-name = "ghcr.io/hasura/v3-dev-auth-webhook";
port = "3050";
};
# dev-auth-webhook docker for aarch64-linux
dev-auth-webhook-docker-aarch64-linux = pkgs.callPackage ./nix/docker.nix {
package = self.packages.${localSystem}.dev-auth-webhook-aarch64-linux;
architecture = "arm64";
image-name = "ghcr.io/hasura/v3-dev-auth-webhook";
port = "3050";
};
### SCRIPTS
publish-docker-image = pkgs.writeShellApplication {
name = "publish-docker-image";
runtimeInputs = with pkgs; [ coreutils skopeo ];
text = builtins.readFile ./.github/scripts/deploy.sh;
};
};
apps = {
default = self.apps.${localSystem}.engine;
engine = flake-utils.lib.mkApp {
drv = self.packages.${localSystem}.engine;
name = "engine";
};
dev-auth-webhook = flake-utils.lib.mkApp {
drv = self.packages.${localSystem}.dev-auth-webhook;
name = "dev-auth-webhook";
};
custom-connector = flake-utils.lib.mkApp {
drv = self.packages.${localSystem}.custom-connector;
name = "custom-connector";
};
};
devShells = {
default = pkgs.mkShell {
# include dependencies of the default package
inputsFrom = [ self.packages.${localSystem}.default ];
# build-time inputs
nativeBuildInputs = [
# Development
pkgs.just
pkgs.nixpkgs-fmt
pkgs.nodePackages.prettier
# Rust
pkgs.cargo-edit
pkgs.cargo-expand
pkgs.cargo-flamegraph
pkgs.cargo-insta
pkgs.cargo-machete
pkgs.cargo-nextest
pkgs.cargo-watch
rust.rustToolchain
];
};
};
});
}