-
-
Notifications
You must be signed in to change notification settings - Fork 27
260 lines (254 loc) · 8.83 KB
/
docker-build-and-push.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: Build and Push Docker Images
permissions:
pull-requests: write
contents: read
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install frontend dependencies
run: npm install
working-directory: web-app
- name: Build frontend
run: npm run build && cp -r dist/ ../dist/
working-directory: web-app
- name: Run frontend tests
run: npm test
working-directory: web-app
- name: Install mupdf
run: sudo apt-get install -y mupdf
- name: Set library path
run: echo "/usr/lib" | sudo tee -a /etc/ld.so.conf.d/mupdf.conf && sudo ldconfig
- name: Install dependencies
run: go mod download
- name: Run Go tests
run: go test ./...
build-amd64:
runs-on: ubuntu-latest
needs: test
outputs:
digest: ${{ steps.build_amd64.outputs.digest }}
image_tag: ${{ steps.set_image_tag.outputs.image_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set Docker tags
id: set_tags
run: |
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
echo "TAGS=icereed/paperless-gpt:pr-${GITHUB_SHA}-amd64" >> $GITHUB_ENV
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "TAGS=icereed/paperless-gpt:${VERSION}-amd64" >> $GITHUB_ENV
else
echo "TAGS=icereed/paperless-gpt:unreleased-amd64" >> $GITHUB_ENV
fi
- name: Build and push AMD64 image
id: build_amd64
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.TAGS }}
build-args: |
VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.repository.pushed_at }}
- name: Set image tag output
id: set_image_tag
run: echo "image_tag=${TAGS}" >> $GITHUB_OUTPUT
- name: Export digest for amd64
run: |
mkdir -p ${{ runner.temp }}/digests
echo "${{ steps.build_amd64.outputs.digest }}" | sed 's/^sha256://g' > ${{ runner.temp }}/digests/digest-amd64.txt
- name: Upload amd64 digest
uses: actions/upload-artifact@v4
with:
name: digest-amd64
path: ${{ runner.temp }}/digests/digest-amd64.txt
build-arm64:
runs-on: ubuntu-24.04-arm
needs: test
outputs:
digest: ${{ steps.build_arm64.outputs.digest }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set Docker tags
id: set_tags
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "TAGS=icereed/paperless-gpt:${VERSION}-arm64" >> $GITHUB_ENV
else
echo "TAGS=icereed/paperless-gpt:unreleased-arm64" >> $GITHUB_ENV
fi
- name: Build and push ARM64 image
id: build_arm64
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.TAGS }}
build-args: |
VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.repository.pushed_at }}
- name: Export digest for arm64
run: |
mkdir -p ${{ runner.temp }}/digests
echo "${{ steps.build_arm64.outputs.digest }}" | sed 's/^sha256://g' > ${{ runner.temp }}/digests/digest-arm64.txt
- name: Upload arm64 digest
uses: actions/upload-artifact@v4
with:
name: digest-arm64
path: ${{ runner.temp }}/digests/digest-arm64.txt
merge-manifests:
needs: [build-amd64, build-arm64]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
env:
DOCKERHUB_REPO: icereed/paperless-gpt
steps:
- name: Download amd64 digest
uses: actions/download-artifact@v4
with:
name: digest-amd64
path: ${{ runner.temp }}/digests
- name: Download arm64 digest
uses: actions/download-artifact@v4
with:
name: digest-arm64
path: ${{ runner.temp }}/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Determine version/tag
id: get_version
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
else
echo "VERSION=unreleased" >> $GITHUB_ENV
fi
- name: Create and push manifest list
run: |
AMD64_DIGEST=$(cat ${{ runner.temp }}/digests/digest-amd64.txt)
ARM64_DIGEST=$(cat ${{ runner.temp }}/digests/digest-arm64.txt)
# Create manifest with the single-arch image digests
docker buildx imagetools create -t ${DOCKERHUB_REPO}:${VERSION} \
${DOCKERHUB_REPO}@sha256:${AMD64_DIGEST} ${DOCKERHUB_REPO}@sha256:${ARM64_DIGEST}
# Also push "latest" tag when on a tag
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
docker buildx imagetools create -t ${DOCKERHUB_REPO}:latest \
${DOCKERHUB_REPO}@sha256:${AMD64_DIGEST} ${DOCKERHUB_REPO}@sha256:${ARM64_DIGEST}
fi
- name: Inspect manifest
run: |
docker buildx imagetools inspect ${DOCKERHUB_REPO}:${VERSION}
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
docker buildx imagetools inspect ${DOCKERHUB_REPO}:latest
fi
e2e-tests:
name: E2E Tests
needs: build-amd64
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./web-app
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set PAPERLESS_GPT_IMAGE
run: |
if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then
IMAGE="icereed/paperless-gpt:pr-${GITHUB_SHA}-amd64"
elif [ "${GITHUB_REF_TYPE}" = "tag" ]; then
IMAGE="icereed/paperless-gpt:${GITHUB_REF_NAME}-amd64"
else
IMAGE="icereed/paperless-gpt:unreleased-amd64"
fi
echo "PAPERLESS_GPT_IMAGE=${IMAGE}" >> $GITHUB_ENV
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: './web-app/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install chromium --with-deps
- name: Run Playwright tests
run: npm run test:e2e
env:
CI: true
DEBUG: testcontainers:containers
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
PAPERLESS_GPT_IMAGE: ${{ env.PAPERLESS_GPT_IMAGE }}
- name: Upload Playwright Report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: web-app/playwright-report/
retention-days: 30
- name: Upload test screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: web-app/test-results/
retention-days: 30