Docker Image Builds
This commit is contained in:
@@ -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
|
||||||
+16
-2
@@ -1,5 +1,7 @@
|
|||||||
# Build Frontend
|
# 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
|
WORKDIR /app
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
RUN bun install
|
RUN bun install
|
||||||
@@ -7,6 +9,7 @@ COPY . .
|
|||||||
RUN bun run build
|
RUN bun run build
|
||||||
|
|
||||||
# Build Backend
|
# Build Backend
|
||||||
|
# Built for the target platform (under QEMU emulation for non-native arches).
|
||||||
FROM rust:alpine AS backend-builder
|
FROM rust:alpine AS backend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconfig git
|
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
|
# Final Runtime Image
|
||||||
FROM alpine:3.19
|
FROM alpine:3.19
|
||||||
|
# Provided automatically by buildx (e.g. "amd64", "arm64").
|
||||||
|
ARG TARGETARCH
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apk add --no-cache libgcc openssl pandoc curl sqlite
|
RUN apk add --no-cache libgcc openssl pandoc curl sqlite
|
||||||
RUN mkdir -p /data
|
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=frontend-builder /app/build /app/build
|
||||||
COPY --from=backend-builder /app/server/target/release/server /app/server
|
COPY --from=backend-builder /app/server/target/release/server /app/server
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user