-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (142 loc) · 4.99 KB
/
build.yml
File metadata and controls
158 lines (142 loc) · 4.99 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
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
IMAGE_NAME: podmortem-ai-interface
DOCKERFILE: ./src/main/docker/Dockerfile.native
DEP_STAGE: dependencies
jobs:
warm-cache:
name: Warm Dependencies Cache
runs-on: [self-hosted, linux]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the GitHub Container Registry
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_PAT }}
- name: Build dependencies stage
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE }}
target: ${{ env.DEP_STAGE }}
platforms: linux/amd64
push: ${{ github.event_name == 'push' }}
cache-from: type=gha,scope=deps
cache-to: |
type=gha,mode=max,scope=deps
${{ github.event_name == 'push' && format('type=registry,ref=ghcr.io/{0}/{1}:deps-cache,mode=max', github.repository_owner, env.IMAGE_NAME) || '' }}
tags: |
${{ github.event_name == 'push' && format('ghcr.io/{0}/{1}:deps-cache', github.repository_owner, env.IMAGE_NAME) || '' }}
build-args: |
GITHUB_USER=${{ github.actor }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
test-build:
name: Test Build
if: github.event_name == 'pull_request'
needs: warm-cache
runs-on: [self-hosted, linux]
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image for testing
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE }}
platforms: linux/amd64
push: false
cache-from: |
type=gha,scope=deps
type=gha,scope=build-amd64
cache-to: type=gha,mode=max,scope=build-amd64
build-args: |
GITHUB_USER=${{ github.actor }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
build-arch:
name: Build ${{ matrix.arch }}
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: warm-cache
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- arch: amd64
platform: linux/amd64
runner: [self-hosted, linux]
- arch: arm64
platform: linux/arm64
runner: ubuntu-22.04-arm
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_PAT }}
- name: Build and push ${{ matrix.arch }} image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE }}
platforms: ${{ matrix.platform }}
push: true
cache-from: |
type=gha,scope=deps
type=gha,scope=build-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=build-amd64
tags: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-${{ matrix.arch }}
build-args: |
GITHUB_USER=${{ github.actor }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
create-manifest:
name: Create Multi-Arch Manifest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build-arch
runs-on: [self-hosted, linux]
permissions:
contents: read
packages: write
steps:
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_PAT }}
- name: Create and push multi-arch manifest
run: |
docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest-dev \
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64 \
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64
docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64 \
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64