Skip to content

Commit

Permalink
WIP: docker build CI
Browse files Browse the repository at this point in the history
  • Loading branch information
afilini committed Mar 28, 2024
1 parent b14d3f2 commit 4184b78
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 12 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Print nixpkgs version
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target
./firmware/target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: nix build .#emulator
- run: nix build .#model
- run: nix build .#gui-simulator
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Docker Images"
# on:
# push:
# branches: ['master']
on:
pull_request:
push:

jobs:
build-and-push-image:
runs-on: ubuntu-latest

strategy:
matrix:
image: [emulatorImage] #, devEnvironment]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Print nixpkgs version
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'

- run: nix build .#docker.${{ matrix.image }}
- run: ./result | docker load

- name: Test
run: |
docker run --rm portal-emulator:latest
# - name: Push Docker image
# uses: docker/build-push-action@v5
# with:
# context: .
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
16 changes: 16 additions & 0 deletions docker/embedded-dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ pkgs, packages, getRust }:

let
qemuOnlyArm = packages.smallQemu;
shell = pkgs.mkShell {
buildInputs = with pkgs; [ cmake pkg-config (getRust { withEmbedded = true; }) ];

CC_thumbv7em_none_eabihf = "${pkgs.gcc-arm-embedded}/bin/arm-none-eabi-gcc";
};
in
pkgs.dockerTools.buildNixShellImage {
name = "portal-dev-environment";
tag = "latest";
homeDirectory = "/app";
drv = shell;
}
6 changes: 3 additions & 3 deletions docker/emulator.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs, packages }:

let
qemuOnlyArm = pkgs.qemu.override { hostCpuTargets = ["arm-softmmu"]; };
qemuOnlyArm = packages.smallQemu;
firmwareOnly = pkgs.runCommand "pruneFirmwareDeps" {} ''
mkdir -p $out/bin
cp ${packages.firmware-emu}/bin/firmware $out/bin/firmware
Expand All @@ -27,10 +27,10 @@ let
exec ${packages.emulator}/bin/gui --no-cargo-build --firmware /bin/firmware --join-logs "$@"
'';
in
pkgs.dockerTools.buildImage {
pkgs.dockerTools.streamLayeredImage {
name = "portal-emulator";
tag = "latest";
copyToRoot = pkgs.buildEnv {
contents = pkgs.buildEnv {
name = "image-root";
paths = [ pkgs.bash emulatorScript startupScript hostname qemuOnlyArm firmwareOnly pkgs.novnc pkgs.coreutils pkgs.xvfb-run pkgs.x11vnc pkgs.xterm pkgs.procps pkgs.gnugrep ];
pathsToLink = [ "/bin" "/etc" "/var" ];
Expand Down
12 changes: 11 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
config.android_sdk.accept_license = true; config.allowUnfree = true;

config.android_sdk.accept_license = true;
config.allowUnfree = true;
};
rustVersion = "1.76.0";
getRust =
Expand Down Expand Up @@ -129,6 +131,13 @@
};
};

packages.smallQemu = let
qemu' = pkgs.qemu.override { hostCpuTargets = ["arm-softmmu"]; };
in
pkgs.writeShellScriptBin "qemu-system-arm" ''
exec ${qemu'}/bin/qemu-system-arm "$@"
'';

packages.emulator = pkgs.callPackage ./emulator { inherit pkgs; craneLib = getCrane { withEmbedded = false; }; };
packages.gui-simulator = pkgs.callPackage ./gui { inherit pkgs; craneLib = getCrane { withEmbedded = false; }; };
packages.model = pkgs.callPackage ./model { inherit pkgs; craneLib = getCrane { withEmbedded = false; }; };
Expand All @@ -138,6 +147,7 @@
packages.firmware = pkgs.callPackage ./firmware { inherit pkgs; craneLib = getCrane { withEmbedded = true; }; };

packages.docker.emulatorImage = pkgs.callPackage ./docker/emulator.nix { inherit pkgs packages; };
packages.docker.devEnvironment = pkgs.callPackage ./docker/embedded-dev.nix { inherit pkgs packages getRust; };
}
);
}
5 changes: 5 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ pkgs.mkShell rec {
GRADLE_OPTS = lib.optionals withAndroid "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${android.buildToolsVersion}/aapt2";

shellHook = ''
RED='\033[1;31m'
NC='\033[0m'
printf "$RED Warning: the shell.nix file is deprecated, please migrate to the flake$NC\n"
${
lib.optionalString withAndroid androidShellHook
}
Expand Down

0 comments on commit 4184b78

Please sign in to comment.