-
Notifications
You must be signed in to change notification settings - Fork 1
168 lines (146 loc) · 5.06 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: main
permissions:
contents: read
packages: write
attestations: write
id-token: write
on:
push:
branches: [ "master" ]
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
ATTIC_SERVER: "https://attic.tfk.nd/"
ATTIC_CACHE: "default"
jobs:
populate-cache:
strategy:
matrix:
package:
# these have to be fully qualified nix flake paths
- .#packages.x86_64-linux.bws-get
- .#packages.x86_64-linux.nixmad
- "github:zhaofengli/colmena#defaultPackage.x86_64-linux"
- "github:Mic92/nix-fast-build/8e7c9d7#packages.x86_64-linux.default"
host:
- ubuntu-latest
# - macos-latest
runs-on: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-build-env
name: Set up build env
with:
caCertificate: ${{ secrets.DCOTTA_ROOT_CA }}
tailscale_authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
- name: Build package ${{ matrix.package }}
continue-on-error: false
run: |
nix-fast-build --eval-workers 1 --skip-cached --no-nom --attic-cache=default \
-f ${{ matrix.package }}
resolve-nodes:
runs-on: ubuntu-latest
outputs:
nodes: ${{ steps.list.outputs.nodes }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v22
with:
github_access_token: '${{ github.token }}'
- name: List nodes
id: list
run: |
NODES=$(nix eval .#colmenaHive.nodes --json --apply builtins.attrNames | jq -c)
echo "nodes resolved:"
echo "$NODES"
echo "nodes=$NODES" >> "$GITHUB_OUTPUT"
build-nixos-configs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ${{ fromJSON(needs.resolve-nodes.outputs.nodes) }}
needs: resolve-nodes
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-build-env
name: Set up build env
with:
caCertificate: ${{ secrets.DCOTTA_ROOT_CA }}
tailscale_authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
aarch64LinuxSupport: true
- name: Build NixOS config for ${{ matrix.node }}
run: |
nix-fast-build --eval-workers 1 --skip-cached --no-nom --attic-cache=default \
-f .#colmenaHive.nodes.${{ matrix.node }}.config.system.build.toplevel
deploy-web:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-build-env
name: Set up build env
with:
caCertificate: ${{ secrets.DCOTTA_ROOT_CA }}
tailscale_authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
- name: Import Secrets
id: secrets
uses: hashicorp/vault-action@v2
with:
url: https://vault.dcotta.com:8200
role: actions-ro
path: jwt-github
method: jwt
jwtGithubAudience: sigstore
caCertificate: ${{ secrets.DCOTTA_ROOT_CA }}
secrets: |
secret/data/github-actions/cloudflare/workers_token value | CF_TOKEN ;
secret/data/github-actions/cloudflare/workers_token accountId | CF_ACCOUNT_ID ;
- name: Build web portfolio
run: |
nix build -L github:cottand/web-portfolio#static
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ steps.secrets.outputs.CF_TOKEN }}
accountId: ${{ steps.secrets.outputs.CF_ACCOUNT_ID }}
command: pages deploy ./result/srv --project-name=nico-dcotta-com
- name: Cache results
continue-on-error: true
run: |
attic push "$ATTIC_CACHE" ./result
build-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-build-env
name: Set up build env
with:
caCertificate: ${{ secrets.DCOTTA_ROOT_CA }}
tailscale_authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
- name: Build services image
run: |
nix build -L .#scripts.all-images
- name: Install skopeo
run: |
nix profile install nixpkgs#skopeo
- name: Login to GHCR
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | skopeo login -u ${{ github.actor }} --password-stdin https://ghcr.io
- name: Push all images
shell: python
run: |
import os
import json
images = os.popen("jq < $(nix build .#scripts.all-images --print-out-paths)").read()
git_sha = os.popen('git rev-parse --short "$GITHUB_SHA"').read().strip()
for repo, path in json.loads(images).items():
dest_repo = f'docker://ghcr.io/cottand/selfhosted/{repo}:{git_sha}'
print(os.popen(f'skopeo --insecure-policy copy "docker-archive:{path}" "{dest_repo}"').read())
- name: Cache results
continue-on-error: true
run: |
attic push "$ATTIC_CACHE" result*