Skip to content

Commit 7a93839

Browse files
committed
dockerImage: init
1 parent 8ff15d1 commit 7a93839

4 files changed

Lines changed: 151 additions & 11 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Docker deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'pr/docker'
8+
9+
permissions:
10+
packages: write
11+
12+
jobs:
13+
build-container:
14+
name: Build Docker container
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2.4.0
18+
19+
- name: Login to GitHub Container Registry
20+
uses: docker/login-action@v2
21+
with:
22+
registry: ghcr.io
23+
username: '${{ github.actor }}'
24+
password: '${{ secrets.GITHUB_TOKEN }}'
25+
26+
- uses: cachix/install-nix-action@v22
27+
with:
28+
nix_path: nixpkgs=channel:nixpkgs-22.05-darwin
29+
extra_nix_config: |
30+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
31+
32+
- uses: cachix/cachix-action@v12
33+
with:
34+
name: epic-eic
35+
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
36+
skipPush: true
37+
38+
- name: Build Docker image
39+
run: |
40+
nix build .#dockerImage --keep-going --print-build-logs --no-write-lock-file -o docker-image
41+
42+
- name: Load Docker image
43+
run: |
44+
docker load -i docker-image | tee docker_load
45+
grep "Loaded image: " docker_load
46+
47+
- name: Push to the Container Registry
48+
run: |
49+
DOCKER_IMAGE=$(cut -d " " -f 3 docker_load)
50+
docker image tag $DOCKER_IMAGE ghcr.io/${{ github.repository }}:latest
51+
docker image push ghcr.io/${{ github.repository }}:latest

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ git clone https://github.com/veprbl/epic-nix.git
5151
cd epic-nix
5252
nix develop
5353
```
54+
55+
Singularity
56+
-----------
57+
58+
A pre-built container can be entered like so:
59+
60+
```shell
61+
singularity shell docker://ghcr.io/veprbl/epic-nix
62+
```

docker.nix

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,83 @@
1-
{ pkgs, providedPackageList, self, system }:
2-
3-
{
4-
dockerImage = pkgs.dockerTools.buildLayeredImage {
5-
name = "eic-nix";
6-
contents = map (name: self.packages.${system}.${name}) providedPackageList;
7-
};
8-
}
1+
{ self
2+
, epic_pkgs
3+
, pkgs
4+
}:
5+
6+
let
7+
8+
packages =
9+
(builtins.attrValues
10+
(pkgs.lib.filterAttrs
11+
(name: value: (name != "fun4all") && (pkgs.lib.isDerivation value))
12+
epic_pkgs));
13+
14+
extra_packages = with pkgs; [
15+
# Development
16+
cmake
17+
gitFull
18+
nix
19+
stdenv.cc
20+
21+
# Utilities
22+
bash
23+
cacert
24+
cachix
25+
coreutils
26+
curl
27+
emacs
28+
entr
29+
gawk
30+
gnugrep
31+
gnused
32+
jq
33+
less
34+
perl
35+
procps
36+
rsync
37+
silver-searcher
38+
vim
39+
which
40+
wget
41+
zsh
42+
43+
# Libraries
44+
python3
45+
python3Packages.awkward
46+
python3Packages.dask
47+
python3Packages.distributed
48+
python3Packages.hepmc3
49+
python3Packages.matplotlib
50+
python3Packages.pyarrow
51+
python3Packages.scikit-learn
52+
python3Packages.pytorch
53+
python3Packages.uproot
54+
root
55+
56+
# Continuous Integration
57+
github-runner
58+
];
59+
60+
container_env = pkgs.runCommandNoCC "container-env" {
61+
buildInputs = packages ++ extra_packages;
62+
} ''
63+
mkdir -p "$out/.singularity.d/env"
64+
declare -p | grep -vE "^declare -[ai-]" | grep -vE "^declare -. (PWD|OLDPWD|HOME|TMP|TEMP)" > "$out/.singularity.d/env/99-epic-nix.sh"
65+
cat > "$out/.singularity.d/env/99-epic-nix-config.sh" <<EOF
66+
unset NIX_STORE_DIR
67+
unset NIX_CONF_DIR
68+
unset NIX_STATE_DIR
69+
EOF
70+
mkdir -p "$out/etc/nix"
71+
cat > "$out/etc/nix/nix.conf" <<EOF
72+
experimental-features = flakes nix-command
73+
substituters = https://cache.nixos.org https://epic-eic.cachix.org
74+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= epic-eic.cachix.org-1:9Mu7fnayGYtapkzXm+7ZhPP5w7bJxtSv9C+BJTWon/o=
75+
EOF
76+
'';
77+
78+
in
79+
80+
pkgs.dockerTools.buildLayeredImage {
81+
name = "epic-nix";
82+
contents = packages ++ extra_packages ++ [ container_env ];
83+
}

flake.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@
3737

3838
is_broken = pkg: (pkg.meta or {}).broken or false;
3939
select_unbroken = lib.filterAttrs (name: pkg: !(is_broken pkg));
40+
41+
epic_pkgs =
42+
lib.filterAttrs (name: lib.isDerivation)
43+
(select_unbroken (lib.getAttrs providedPackageList pkgs));
44+
45+
dockerImage = pkgs.callPackage ./docker.nix { inherit epic_pkgs self; };
4046
in
41-
lib.filterAttrs (name: lib.isDerivation)
42-
(select_unbroken (lib.getAttrs providedPackageList pkgs)));
47+
epic_pkgs // (lib.optionalAttrs pkgs.stdenv.isLinux { inherit dockerImage; }));
4348

4449
checks = self.packages;
4550

@@ -51,7 +56,7 @@
5156
{
5257
default = pkgs.mkShell rec {
5358
buildInputs =
54-
builtins.attrValues self.packages.${system} ++
59+
builtins.filter lib.isDerivation (builtins.attrValues self.packages.${system}) ++
5560
(with self.packages.${system}; [
5661
geant4.data.G4EMLOW
5762
geant4.data.G4ENSDFSTATE

0 commit comments

Comments
 (0)