Add GitHub Actions workflow for building and pushing Docker images (#6)

* Add GitHub Actions workflow for caching npm dependencies and building and pushing Docker images
This commit is contained in:
Icereed 2024-10-04 13:35:06 +02:00 committed by GitHub
parent c7b5c6a060
commit 199e1413ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 86 additions and 1 deletions

View file

@ -0,0 +1,84 @@
name: Build and Push Docker Images
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22
- name: Install dependencies
run: go mod download
- name: Run Go tests
run: go test ./...
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Cache npm dependencies
uses: actions/cache@v3
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: Run frontend tests
run: npm test
working-directory: web-app
build-and-push:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Build and push Docker images
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
icereed/paperless-gpt:unreleased
${{ github.ref == 'refs/heads/main' && 'icereed/paperless-gpt:unreleased' }}
${{ github.ref_type == 'tag' && 'icereed/paperless-gpt:latest' }}
${{ github.ref_type == 'tag' && 'icereed/paperless-gpt:${{ github.ref_name }}' }}

View file

@ -7,7 +7,8 @@
"dev": "vite", "dev": "vite",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview" "preview": "vite preview",
"test": "echo \"TODO\""
}, },
"dependencies": { "dependencies": {
"@headlessui/react": "^2.1.8", "@headlessui/react": "^2.1.8",