Skip to content

Commit 464221e

Browse files
feat: add docker container
1 parent a6001cb commit 464221e

3 files changed

Lines changed: 177 additions & 0 deletions

File tree

.github/workflows/ci-docker.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
tags:
6+
- v?[0-9]+.[0-9]+.[0-9]+*
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
discover:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.discover.outputs.matrix }}
18+
manifests: ${{ steps.discover.outputs.manifests }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: DeterminateSystems/nix-installer-action@main
22+
- id: discover
23+
run: |
24+
flake_json=$(nix flake show --all-systems --json 2>/dev/null)
25+
26+
matrix=$(echo "$flake_json" | jq -c '[.inventory.packages.output.children
27+
| to_entries[]
28+
| .key as $sys
29+
| .value.children
30+
| keys[]
31+
| select(endswith("-docker"))
32+
| {system: $sys, package: .}]')
33+
34+
manifests=$(echo "$flake_json" | jq -c '[.inventory.packages.output.children
35+
| to_entries[]
36+
| .key as $sys
37+
| .value.children
38+
| keys[]
39+
| select(endswith("-docker"))
40+
| {system: $sys, package: .}]
41+
| group_by(.package)
42+
| map({package: .[0].package, systems: [.[].system]})')
43+
44+
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
45+
echo "manifests=$manifests" >> "$GITHUB_OUTPUT"
46+
47+
build-and-push:
48+
needs: discover
49+
runs-on: ${{ matrix.system == 'aarch64-linux' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
50+
permissions:
51+
contents: read
52+
packages: write
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
include: ${{ fromJson(needs.discover.outputs.matrix) }}
57+
steps:
58+
- uses: actions/checkout@v4
59+
- uses: DeterminateSystems/nix-installer-action@main
60+
61+
- name: Build Docker image
62+
run: nix build '.#packages.${{ matrix.system }}.${{ matrix.package }}' -o result
63+
64+
- name: Determine image metadata
65+
id: meta
66+
run: |
67+
name=$(nix eval --raw '.#packages.${{ matrix.system }}.${{ matrix.package }}.imageName')
68+
tag=$(nix eval --raw '.#packages.${{ matrix.system }}.${{ matrix.package }}.imageTag')
69+
echo "name=$name" >> "$GITHUB_OUTPUT"
70+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
71+
72+
- name: Login to GHCR
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ghcr.io
76+
username: ${{ github.actor }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Push per-arch image
80+
run: |
81+
repo="ghcr.io/${{ github.repository_owner }}/${{ steps.meta.outputs.name }}"
82+
repo="${repo,,}"
83+
84+
docker load < result
85+
loaded="${{ steps.meta.outputs.name }}:${{ steps.meta.outputs.tag }}"
86+
87+
docker tag "$loaded" "$repo:${{ matrix.system }}"
88+
docker push "$repo:${{ matrix.system }}"
89+
90+
manifest:
91+
needs: [discover, build-and-push]
92+
runs-on: ubuntu-latest
93+
permissions:
94+
contents: read
95+
packages: write
96+
strategy:
97+
matrix:
98+
include: ${{ fromJson(needs.discover.outputs.manifests) }}
99+
steps:
100+
- uses: actions/checkout@v4
101+
- uses: DeterminateSystems/nix-installer-action@main
102+
103+
- name: Determine image name
104+
id: meta
105+
run: |
106+
name=$(nix eval --raw '.#packages.${{ matrix.systems[0] }}.${{ matrix.package }}.imageName')
107+
repo="ghcr.io/${{ github.repository_owner }}/$name"
108+
echo "repo=${repo,,}" >> "$GITHUB_OUTPUT"
109+
110+
- name: Login to GHCR
111+
uses: docker/login-action@v3
112+
with:
113+
registry: ghcr.io
114+
username: ${{ github.actor }}
115+
password: ${{ secrets.GITHUB_TOKEN }}
116+
117+
- name: Create and push multi-arch manifest
118+
run: |
119+
repo="${{ steps.meta.outputs.repo }}"
120+
systems='${{ toJson(matrix.systems) }}'
121+
122+
args=()
123+
annotations=()
124+
for sys in $(echo "$systems" | jq -r '.[]'); do
125+
args+=("$repo:$sys")
126+
arch="${sys%%-*}"
127+
case "$arch" in
128+
x86_64) docker_arch="amd64" ;;
129+
aarch64) docker_arch="arm64" ;;
130+
*) docker_arch="$arch" ;;
131+
esac
132+
annotations+=("$repo:$sys --os linux --arch $docker_arch")
133+
done
134+
135+
docker manifest create "$repo:latest" "${args[@]}"
136+
for ann in "${annotations[@]}"; do
137+
docker manifest annotate "$repo:latest" $ann
138+
done
139+
docker manifest push "$repo:latest"
140+
141+
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
142+
tag="${GITHUB_REF#refs/tags/}"
143+
docker manifest create "$repo:$tag" "${args[@]}"
144+
for ann in "${annotations[@]}"; do
145+
docker manifest annotate "$repo:$tag" $ann
146+
done
147+
docker manifest push "$repo:$tag"
148+
fi

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
pdk = pkgs.gf180mcu-pdk;
9898
clockPeriodNs = 20;
9999
};
100+
terra-1-docker = self.packages.${system}.terra-1.docker;
100101
};
101102

102103
checks =

pkgs/aegis-ip/default.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
lib,
33
callPackage,
44
stdenvNoCC,
5+
dockerTools,
6+
bashInteractive,
7+
coreutils,
58
mkShell,
69
makeWrapper,
710
yosys,
@@ -171,6 +174,31 @@ lib.extendMkDerivation {
171174
surfer
172175
];
173176
};
177+
docker = dockerTools.buildLayeredImage {
178+
name = "aegis-${deviceName}";
179+
tag = "latest";
180+
contents = [
181+
bashInteractive
182+
coreutils
183+
yosys
184+
aegis-ip-tools
185+
aegis-pack
186+
aegis-sim
187+
nextpnr-aegis
188+
finalAttrs.finalPackage
189+
finalAttrs.finalPackage.tools
190+
];
191+
config = {
192+
Env = [
193+
"AEGIS_DEVICE_DIR=${finalAttrs.finalPackage}"
194+
];
195+
Cmd = [ "/bin/bash" ];
196+
WorkingDir = "/workspace";
197+
Volumes = {
198+
"/workspace" = { };
199+
};
200+
};
201+
};
174202
}
175203
// (args.passthru or { });
176204

0 commit comments

Comments
 (0)