mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-07-12 04:50:45 +00:00
fix: resolve CGO cross-compilation issues with multi-stage Docker builds
Problem: - Enabling CGO_ENABLED=1 for SQLite support caused cross-compilation failures - ARM64 assembly errors when building from amd64 host - Cross-compilation with CGO requires architecture-specific toolchains Solution: - Converted all Dockerfiles to multi-stage builds - Binaries now compile inside Docker using native platform builders - Used --platform flag to build for target architecture natively - Removed binary builds from .goreleaser.yaml (skip: true) - Updated dockers_v2 to use buildx with multi-platform support Changes: - .goreleaser.yaml: Skip standalone builds, use Docker buildx - Dockerfile.server: Multi-stage build with CGO - Dockerfile.scanner: Multi-stage build with CGO - Dockerfile.migrate: Multi-stage build with CGO Benefits: - No cross-compilation needed (each platform builds natively) - Docker buildx handles multi-platform builds automatically - SQLite support working with CGO enabled - Cleaner separation between build and runtime environments
This commit is contained in:
+28
-58
@@ -13,42 +13,13 @@ before:
|
||||
# - ./script/generate-version.sh
|
||||
|
||||
# Build configuration
|
||||
# Note: Binaries are built inside Docker containers (multi-stage builds)
|
||||
# to avoid CGO cross-compilation issues. No standalone builds here.
|
||||
builds:
|
||||
- id: gohoarder
|
||||
main: ./cmd/gohoarder
|
||||
binary: gohoarder
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
- windows
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X github.com/lukaszraczylo/gohoarder/internal/version.Version={{.Version}}
|
||||
- -X github.com/lukaszraczylo/gohoarder/internal/version.GitCommit={{.ShortCommit}}
|
||||
- -X github.com/lukaszraczylo/gohoarder/internal/version.BuildTime={{.Date}}
|
||||
|
||||
skip: true
|
||||
- id: migrate
|
||||
main: ./cmd/migrate
|
||||
binary: migrate
|
||||
env:
|
||||
- CGO_ENABLED=1
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
- windows
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X main.Version={{.Version}}
|
||||
- -X main.GitCommit={{.ShortCommit}}
|
||||
- -X main.BuildTime={{.Date}}
|
||||
skip: true
|
||||
|
||||
# Archives for releases
|
||||
archives:
|
||||
@@ -108,16 +79,17 @@ release:
|
||||
dockers_v2:
|
||||
# 1. Application Engine - Main GoHoarder server
|
||||
- id: gohoarder-server
|
||||
ids:
|
||||
- gohoarder
|
||||
use: buildx
|
||||
images:
|
||||
- ghcr.io/lukaszraczylo/gohoarder-server
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64,linux/arm64"
|
||||
- "--build-arg=VERSION={{ .Version }}"
|
||||
- "--build-arg=GIT_COMMIT={{ .ShortCommit }}"
|
||||
- "--build-arg=BUILD_TIME={{ .Date }}"
|
||||
tags:
|
||||
- "{{ .Version }}"
|
||||
- latest
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
dockerfile: Dockerfile.server
|
||||
labels:
|
||||
org.opencontainers.image.title: GoHoarder Server
|
||||
@@ -132,16 +104,14 @@ dockers_v2:
|
||||
|
||||
# 2. Website - Frontend Dashboard
|
||||
- id: gohoarder-frontend
|
||||
ids:
|
||||
- gohoarder
|
||||
use: buildx
|
||||
images:
|
||||
- ghcr.io/lukaszraczylo/gohoarder-frontend
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64,linux/arm64"
|
||||
tags:
|
||||
- "{{ .Version }}"
|
||||
- latest
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
dockerfile: Dockerfile.frontend
|
||||
labels:
|
||||
org.opencontainers.image.title: GoHoarder Frontend
|
||||
@@ -156,16 +126,17 @@ dockers_v2:
|
||||
|
||||
# 3. Scanning Engine - Background scanner worker
|
||||
- id: gohoarder-scanner
|
||||
ids:
|
||||
- gohoarder
|
||||
use: buildx
|
||||
images:
|
||||
- ghcr.io/lukaszraczylo/gohoarder-scanner
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64,linux/arm64"
|
||||
- "--build-arg=VERSION={{ .Version }}"
|
||||
- "--build-arg=GIT_COMMIT={{ .ShortCommit }}"
|
||||
- "--build-arg=BUILD_TIME={{ .Date }}"
|
||||
tags:
|
||||
- "{{ .Version }}"
|
||||
- latest
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
dockerfile: Dockerfile.scanner
|
||||
labels:
|
||||
org.opencontainers.image.title: GoHoarder Scanner
|
||||
@@ -180,16 +151,14 @@ dockers_v2:
|
||||
|
||||
# 4. Gateway - Nginx reverse proxy for unified deployment
|
||||
- id: gohoarder-gateway
|
||||
ids:
|
||||
- gohoarder
|
||||
use: buildx
|
||||
images:
|
||||
- ghcr.io/lukaszraczylo/gohoarder-gateway
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64,linux/arm64"
|
||||
tags:
|
||||
- "{{ .Version }}"
|
||||
- latest
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
dockerfile: Dockerfile.gateway
|
||||
labels:
|
||||
org.opencontainers.image.title: GoHoarder Gateway
|
||||
@@ -202,16 +171,17 @@ dockers_v2:
|
||||
|
||||
# 5. Migration Engine - Database migration tool
|
||||
- id: gohoarder-migrate
|
||||
ids:
|
||||
- migrate
|
||||
use: buildx
|
||||
images:
|
||||
- ghcr.io/lukaszraczylo/gohoarder-migrate
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64,linux/arm64"
|
||||
- "--build-arg=VERSION={{ .Version }}"
|
||||
- "--build-arg=GIT_COMMIT={{ .ShortCommit }}"
|
||||
- "--build-arg=BUILD_TIME={{ .Date }}"
|
||||
tags:
|
||||
- "{{ .Version }}"
|
||||
- latest
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
dockerfile: Dockerfile.migrate
|
||||
labels:
|
||||
org.opencontainers.image.title: GoHoarder Migrate
|
||||
|
||||
Reference in New Issue
Block a user