From 7d53f20673bc88b7b65b8b65374f2f40a875086d Mon Sep 17 00:00:00 2001 From: lowcarbdev <193176840+lowcarbdev@users.noreply.github.com> Date: Tue, 11 Nov 2025 21:56:53 -0700 Subject: [PATCH] Publish docker image with github actions (#1) Co-authored-by: lowcarbdev --- .github/workflows/docker-build.yml | 67 ++++++++++++++++++++++++++++++ Dockerfile | 29 +++++++------ README.md | 29 +++++++++++-- compose.yaml | 5 ++- go.mod | 2 +- 5 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..6b9e7e6 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,67 @@ +name: Docker Build and Push + +on: + push: + branches: + - main + - '*' + tags: + - 'v*.*.*' + pull_request: + branches: + - main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + type=raw,value=stable,enable={{is_default_branch}} + flavor: | + latest=false + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index dee4f76..64721ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,21 +12,22 @@ RUN npm ci # Copy frontend source COPY frontend/ ./ -# Build frontend +# Build frontend with production API URL (relative path) +# This ensures the frontend uses relative paths instead of localhost:8081 +ENV VITE_API_URL=/api RUN npm run build # Stage 2: Build backend -FROM golang:bookworm AS backend-builder +FROM golang:1.25-alpine AS backend-builder WORKDIR /app # Install build dependencies for libheif and SQLite FTS5 -# Using bookworm-backports to get a newer version of libheif -RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/sources.list && \ - apt-get update && apt-get install -y \ - build-essential \ - && apt-get install -y -t bookworm-backports libheif-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache \ + gcc \ + g++ \ + musl-dev \ + libheif-dev # Copy go mod files COPY go.mod go.sum ./ @@ -39,22 +40,20 @@ COPY *.go ./ COPY internal/*.go internal/ # Build with FTS5 support -RUN go build -tags "fts5 heic" -o sbv . +# Use CGO for SQLite and libheif +RUN CGO_ENABLED=1 go build -tags "fts5 heic" -o sbv . # Stage 3: Final runtime image -FROM debian:bookworm-slim +FROM alpine:3 WORKDIR /app # Install runtime dependencies -# Using bookworm-backports to get matching runtime library -RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/sources.list && \ - apt-get update && apt-get install -y \ +RUN apk add --no-cache \ ca-certificates \ wget \ ffmpeg \ - && apt-get install -y -t bookworm-backports libheif1 \ - && rm -rf /var/lib/apt/lists/* + libheif # Copy backend binary COPY --from=backend-builder /app/sbv . diff --git a/README.md b/README.md index a7bd97d..21c6bad 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,33 @@ A modern web application for viewing SMS and MMS message backups. Import your me ![conversation view](docs/conversation-view.png "SBV Conversation View") ## Quick Start -docker: + +### Docker + +Run the latest stable version: ```bash docker run -d \ -p 8081:8081 \ -v $(pwd)/data:/data \ -e DB_PATH_PREFIX=/data \ - lowcarbdev/sbv + ghcr.io/lowcarbdev/sbv:stable ``` -docker-compose: +Or run the latest development version: +```bash +docker run -d \ + -p 8081:8081 \ + -v $(pwd)/data:/data \ + -e DB_PATH_PREFIX=/data \ + ghcr.io/lowcarbdev/sbv:latest ``` + +### Docker Compose + +```yaml services: sbv: - image: lowcarbdev/sbv + image: ghcr.io/lowcarbdev/sbv:stable ports: - "8081:8081" volumes: @@ -30,6 +43,14 @@ services: restart: unless-stopped ``` +### Available Image Tags + +- `stable` - Latest stable release (recommended for production) +- `latest` - Latest build from main branch (development) +- `v0.1.0` - Specific version (e.g., v0.1.0) +- `v0.1` - Latest patch version of v0.1.x +- `v0` - Latest minor version of v0.x.x + ## Features - **Multi-user** - Create a username/password to log in diff --git a/compose.yaml b/compose.yaml index 4571c5a..662b450 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,9 @@ services: sbv: - build: . + # Use pre-built image from GitHub Container Registry + # For local development, comment out 'image' and uncomment 'build: .' below + image: ghcr.io/lowcarbdev/sbv:stable + # build: . container_name: sbv ports: - "8081:8081" diff --git a/go.mod b/go.mod index 344596a..c7dd656 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/lowcarbdev/sbv -go 1.24.7 +go 1.25.4 require github.com/mattn/go-sqlite3 v1.14.32