From 690d504535eebcc9c07864980428c4f615710fec Mon Sep 17 00:00:00 2001 From: SirBlobby Date: Fri, 3 Jul 2026 22:36:51 -0400 Subject: [PATCH] Docker Image Builds --- .github/workflows/docker-publish.yml | 72 ++++++++++++++++++++++++++++ Dockerfile | 18 ++++++- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..02e5b6c --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,72 @@ +name: Build and Publish Docker Image + +on: + push: + branches: + - main + - dev + tags: + - "v*" + release: + types: [published] + workflow_dispatch: + inputs: + platforms: + description: "Target platforms to build (comma-separated)" + required: false + default: "linux/amd64,linux/arm64" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + DEFAULT_PLATFORMS: "linux/amd64,linux/arm64" + +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 the Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: ${{ github.event.inputs.platforms || env.DEFAULT_PLATFORMS }} + 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 114e009..7ea84bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ # Build Frontend -FROM oven/bun:alpine AS frontend-builder +# Frontend output is static, arch-independent assets, so build it natively on the +# build host (no emulation) regardless of the target platform. +FROM --platform=$BUILDPLATFORM oven/bun:alpine AS frontend-builder WORKDIR /app COPY package.json ./ RUN bun install @@ -7,6 +9,7 @@ COPY . . RUN bun run build # Build Backend +# Built for the target platform (under QEMU emulation for non-native arches). FROM rust:alpine AS backend-builder WORKDIR /app RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconfig git @@ -19,10 +22,21 @@ RUN cargo build --release # Final Runtime Image FROM alpine:3.19 +# Provided automatically by buildx (e.g. "amd64", "arm64"). +ARG TARGETARCH WORKDIR /app RUN apk add --no-cache libgcc openssl pandoc curl sqlite RUN mkdir -p /data -RUN curl -L https://github.com/Myriad-Dreamin/tinymist/releases/latest/download/tinymist-alpine-x64 -o /usr/local/bin/tinymist && chmod +x /usr/local/bin/tinymist +# Install tinymist for the target architecture. +RUN case "$TARGETARCH" in \ + amd64) TINYMIST_TRIPLE="x86_64-unknown-linux-musl" ;; \ + arm64) TINYMIST_TRIPLE="aarch64-unknown-linux-musl" ;; \ + *) echo "Unsupported TARGETARCH: $TARGETARCH" && exit 1 ;; \ + esac && \ + curl -fL "https://github.com/Myriad-Dreamin/tinymist/releases/latest/download/tinymist-${TINYMIST_TRIPLE}.tar.gz" -o /tmp/tinymist.tar.gz && \ + tar -xzf /tmp/tinymist.tar.gz -C /usr/local/bin --strip-components=1 "tinymist-${TINYMIST_TRIPLE}/tinymist" && \ + chmod +x /usr/local/bin/tinymist && \ + rm /tmp/tinymist.tar.gz COPY --from=frontend-builder /app/build /app/build COPY --from=backend-builder /app/server/target/release/server /app/server