2024-10-04 06:35:06 -05:00
|
|
|
name: Build and Push Docker Images
|
|
|
|
|
2025-02-03 02:04:12 -06:00
|
|
|
permissions:
|
|
|
|
pull-requests: write
|
|
|
|
contents: read
|
|
|
|
|
2024-10-04 06:35:06 -05:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
tags:
|
|
|
|
- 'v*.*.*'
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
2025-01-06 14:54:22 -06:00
|
|
|
uses: actions/checkout@v4
|
2024-10-04 06:35:06 -05:00
|
|
|
- name: Set up Go
|
2025-01-06 14:54:49 -06:00
|
|
|
uses: actions/setup-go@v5
|
2024-10-04 06:35:06 -05:00
|
|
|
with:
|
|
|
|
go-version: 1.22
|
|
|
|
- name: Set up Node.js
|
2025-01-22 04:22:03 -06:00
|
|
|
uses: actions/setup-node@v4
|
2024-10-04 06:35:06 -05:00
|
|
|
with:
|
|
|
|
node-version: 20
|
|
|
|
- name: Cache npm dependencies
|
2025-01-22 16:12:25 -06:00
|
|
|
uses: actions/cache@v4
|
2024-10-04 06:35:06 -05:00
|
|
|
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
|
2025-02-03 03:51:42 -06:00
|
|
|
- name: Build frontend
|
|
|
|
run: npm run build && cp -r dist/ ../dist/
|
|
|
|
working-directory: web-app
|
2024-10-04 06:35:06 -05:00
|
|
|
- name: Run frontend tests
|
|
|
|
run: npm test
|
|
|
|
working-directory: web-app
|
2025-02-03 03:51:42 -06:00
|
|
|
- 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 ./...
|
2025-02-02 14:18:09 -06:00
|
|
|
build-amd64:
|
2024-10-04 06:35:06 -05:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: test
|
2025-02-02 14:36:08 -06:00
|
|
|
outputs:
|
|
|
|
digest: ${{ steps.build_amd64.outputs.digest }}
|
2025-02-03 02:04:12 -06:00
|
|
|
image_tag: ${{ steps.set_image_tag.outputs.image_tag }}
|
2024-10-04 06:35:06 -05:00
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
2025-01-06 14:54:22 -06:00
|
|
|
uses: actions/checkout@v4
|
2024-10-04 06:35:06 -05:00
|
|
|
- name: Set up Docker Buildx
|
2025-01-23 13:05:10 -06:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2024-10-04 06:35:06 -05:00
|
|
|
- name: Log in to Docker Hub
|
2025-01-23 13:05:33 -06:00
|
|
|
uses: docker/login-action@v3
|
2024-10-04 06:35:06 -05:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
2025-02-02 14:18:09 -06:00
|
|
|
- name: Set Docker tags
|
|
|
|
id: set_tags
|
|
|
|
run: |
|
2025-02-03 02:04:12 -06:00
|
|
|
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
|
|
|
|
echo "TAGS=icereed/paperless-gpt:pr-${GITHUB_SHA}-amd64" >> $GITHUB_ENV
|
|
|
|
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
2025-02-02 14:18:09 -06:00
|
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
|
|
echo "TAGS=icereed/paperless-gpt:${VERSION}-amd64" >> $GITHUB_ENV
|
2025-02-02 14:36:08 -06:00
|
|
|
else
|
|
|
|
echo "TAGS=icereed/paperless-gpt:unreleased-amd64" >> $GITHUB_ENV
|
2025-02-02 14:18:09 -06:00
|
|
|
fi
|
|
|
|
- name: Build and push AMD64 image
|
2025-02-02 14:36:08 -06:00
|
|
|
id: build_amd64
|
2025-02-02 14:18:09 -06:00
|
|
|
uses: docker/build-push-action@v6
|
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
platforms: linux/amd64
|
2025-02-03 02:04:12 -06:00
|
|
|
push: true
|
2025-02-02 14:18:09 -06:00
|
|
|
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 }}
|
2025-02-03 02:04:12 -06:00
|
|
|
- name: Set image tag output
|
|
|
|
id: set_image_tag
|
|
|
|
run: echo "image_tag=${TAGS}" >> $GITHUB_OUTPUT
|
2025-02-02 14:36:08 -06:00
|
|
|
- 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
|
2025-02-02 14:18:09 -06:00
|
|
|
|
|
|
|
build-arm64:
|
|
|
|
runs-on: ubuntu-24.04-arm
|
|
|
|
needs: test
|
2025-02-02 14:36:08 -06:00
|
|
|
outputs:
|
|
|
|
digest: ${{ steps.build_arm64.outputs.digest }}
|
2025-02-02 14:18:09 -06:00
|
|
|
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 }}
|
2024-10-04 07:03:24 -05:00
|
|
|
- name: Set Docker tags
|
|
|
|
id: set_tags
|
|
|
|
run: |
|
2025-02-02 14:36:08 -06:00
|
|
|
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
2024-10-04 07:03:24 -05:00
|
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
2025-02-02 14:18:09 -06:00
|
|
|
echo "TAGS=icereed/paperless-gpt:${VERSION}-arm64" >> $GITHUB_ENV
|
2025-02-02 14:36:08 -06:00
|
|
|
else
|
|
|
|
echo "TAGS=icereed/paperless-gpt:unreleased-arm64" >> $GITHUB_ENV
|
2024-10-04 07:03:24 -05:00
|
|
|
fi
|
2025-02-02 14:18:09 -06:00
|
|
|
- name: Build and push ARM64 image
|
2025-02-02 14:36:08 -06:00
|
|
|
id: build_arm64
|
2025-01-22 16:12:37 -06:00
|
|
|
uses: docker/build-push-action@v6
|
2024-10-04 06:35:06 -05:00
|
|
|
with:
|
|
|
|
context: .
|
2025-02-02 14:18:09 -06:00
|
|
|
platforms: linux/arm64
|
2024-10-04 06:35:06 -05:00
|
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
|
|
cache-from: type=gha
|
|
|
|
cache-to: type=gha,mode=max
|
2024-10-21 02:50:03 -05:00
|
|
|
tags: ${{ env.TAGS }}
|
2025-01-13 01:02:55 -06:00
|
|
|
build-args: |
|
|
|
|
VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
|
|
|
|
COMMIT=${{ github.sha }}
|
|
|
|
BUILD_DATE=${{ github.event.repository.pushed_at }}
|
2025-02-02 14:36:08 -06:00
|
|
|
- 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
|
2025-02-02 14:18:09 -06:00
|
|
|
|
|
|
|
merge-manifests:
|
|
|
|
needs: [build-amd64, build-arm64]
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.event_name != 'pull_request'
|
2025-02-02 14:36:08 -06:00
|
|
|
env:
|
|
|
|
DOCKERHUB_REPO: icereed/paperless-gpt
|
2025-02-02 14:18:09 -06:00
|
|
|
steps:
|
2025-02-02 14:36:08 -06:00
|
|
|
- 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
|
2025-02-02 14:18:09 -06:00
|
|
|
uses: docker/login-action@v3
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
2025-02-02 14:36:08 -06:00
|
|
|
- name: Determine version/tag
|
|
|
|
id: get_version
|
2025-02-02 14:18:09 -06:00
|
|
|
run: |
|
|
|
|
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
|
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
2025-02-02 14:36:08 -06:00
|
|
|
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
2025-02-02 14:18:09 -06:00
|
|
|
else
|
2025-02-02 14:36:08 -06:00
|
|
|
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
|
2025-02-03 02:04:12 -06:00
|
|
|
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
|
2025-02-03 02:39:57 -06:00
|
|
|
- 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
|
2025-02-03 02:04:12 -06:00
|
|
|
- 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
|
2025-02-10 08:34:12 -06:00
|
|
|
DEBUG: testcontainers:containers
|
2025-02-03 02:04:12 -06:00
|
|
|
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
2025-02-03 02:39:57 -06:00
|
|
|
PAPERLESS_GPT_IMAGE: ${{ env.PAPERLESS_GPT_IMAGE }}
|
2025-02-03 02:04:12 -06:00
|
|
|
- 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
|