-
Notifications
You must be signed in to change notification settings - Fork 10
160 lines (143 loc) · 4.87 KB
/
ci.yml
File metadata and controls
160 lines (143 loc) · 4.87 KB
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
name: CI/CD
on:
push:
branches: [ main ]
tags: [ '*' ]
pull_request:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
check:
name: Nix CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix flake check -L
- run: nix build -L
build:
name: Build Binary
needs: check
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix build -L
- run: mkdir -p target/release && cp result/bin/testaustime target/release/testaustime-rs
- uses: actions/upload-artifact@v4
with:
name: build
path: target/release/testaustime-rs
build-image:
name: Build Docker image
needs: check
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
strategy:
matrix:
runner:
- ubuntu-24.04
- ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Set up Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Build Docker image with Nix
run: |
nix build -L .#docker
IMAGE_PATH=$(readlink -f result)
echo "IMAGE_PATH=$IMAGE_PATH" >> $GITHUB_ENV
- name: Load Docker image
run: |
docker load < ${{ env.IMAGE_PATH }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine architecture
id: arch
run: |
if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then
echo "arch=amd64" >> $GITHUB_OUTPUT
echo "platform=linux/amd64" >> $GITHUB_OUTPUT
else
echo "arch=arm64" >> $GITHUB_OUTPUT
echo "platform=linux/arm64" >> $GITHUB_OUTPUT
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value={{branch}}-${{ steps.arch.outputs.arch }}
type=raw,value=latest-${{ steps.arch.outputs.arch }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=raw,value={{tag}}-${{ steps.arch.outputs.arch }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false
- name: Get image name from Nix build
id: image
run: |
IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1)
echo "name=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Tag and push Docker image
run: |
for tag in ${{ steps.meta.outputs.tags }};
do
docker tag ${{ steps.image.outputs.name }} $tag
docker push $tag
done
create-manifest:
name: Create multi-arch manifest
needs: build-image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for manifest
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value={{branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=match,pattern=\d+,group=0,enable=${{ startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false
- name: Create and push manifest
run: |
TAGS="${{ steps.meta.outputs.tags }}"
for tag in $TAGS;
do
docker manifest create $tag \
${tag}-amd64 \
${tag}-arm64
docker manifest push $tag
done