-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.build
More file actions
152 lines (136 loc) · 5.42 KB
/
Dockerfile.build
File metadata and controls
152 lines (136 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Build Dockerfile for creating distribution packages
#
# This Dockerfile provides a complete build environment for creating:
# - Cross-platform binaries (Linux, macOS, Windows)
# - Distribution packages (DEB, RPM, Arch Linux)
# - Signed releases with checksums
#
# Purpose:
# - Build production-ready binaries for multiple platforms
# - Create native packages for various Linux distributions
# - Generate release artifacts with proper versioning
#
# Usage:
# docker build -f Dockerfile.build \
# --build-arg VERSION=1.0.0 \
# --build-arg GIT_COMMIT=$(git rev-parse --short HEAD) \
# --build-arg BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S') \
# -t generator-builder .
#
# docker run -it --rm \
# -v $(pwd):/app \
# -v go-build-cache:/home/builder/.cache/go-build \
# -v go-mod-cache:/home/builder/go/pkg/mod \
# generator-builder
#
# Output artifacts:
# - /app/dist/ - Cross-platform binaries
# - /app/packages/ - Distribution packages (DEB, RPM, Arch)
#
# Note: This builds Linux packages only. For macOS/Windows binaries,
# cross-compilation is used but native packages are not created.
# Build arguments (must be before FROM)
ARG UBUNTU_VERSION=25.10
ARG GO_VERSION=1.25.0
FROM ubuntu:${UBUNTU_VERSION}
# Build arguments for versioning and metadata
ARG VERSION=dev
ARG GIT_COMMIT=unknown
ARG BUILD_TIME=unknown
ARG GO_VERSION
ARG TARGETARCH
# Labels for image metadata
LABEL org.opencontainers.image.title="Generator Build Environment"
LABEL org.opencontainers.image.description="Build environment for Open Source Project Generator"
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.vendor="Cuesoft Inc."
# Install build dependencies and package creation tools
RUN apt-get update && apt-get install -y \
# Core build tools
git \
ca-certificates \
curl \
wget \
tar \
gzip \
bzip2 \
xz-utils \
zip \
unzip \
build-essential \
# Package building tools
rpm \
dpkg-dev \
fakeroot \
debhelper \
dh-make \
# Arch Linux package tools
binutils \
fakeroot \
# Security and signing tools
gnupg \
gpg \
# Checksum tools
coreutils \
# Additional utilities
file \
jq \
&& rm -rf /var/lib/apt/lists/*
# Install Go with architecture detection and verification
RUN ARCH=$(dpkg --print-architecture) && \
if [ "$ARCH" = "amd64" ]; then GOARCH="amd64"; \
elif [ "$ARCH" = "arm64" ]; then GOARCH="arm64"; \
else echo "Unsupported architecture: $ARCH" && exit 1; fi && \
echo "Installing Go ${GO_VERSION} for ${GOARCH}..." && \
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-${GOARCH}.tar.gz" -o /tmp/go.tar.gz && \
tar -xzC /usr/local -f /tmp/go.tar.gz && \
rm /tmp/go.tar.gz && \
/usr/local/go/bin/go version && \
echo "Go installation verified successfully"
# Set up Go environment
ENV PATH="/usr/local/go/bin:${PATH}"
ENV GOROOT="/usr/local/go"
ENV GOPATH="/home/builder/go"
ENV PATH="${GOPATH}/bin:${PATH}"
ENV GOCACHE="/home/builder/.cache/go-build"
ENV GOMODCACHE="/home/builder/go/pkg/mod"
# Set build metadata environment variables
ENV VERSION="${VERSION}"
ENV GIT_COMMIT="${GIT_COMMIT}"
ENV BUILD_TIME="${BUILD_TIME}"
# Create non-root user and set up directories with proper permissions
RUN useradd -m -s /bin/bash -u 1001 builder && \
mkdir -p \
/app/dist \
/app/packages/deb \
/app/packages/rpm \
/app/packages/arch \
/app/bin \
/home/builder/go/pkg/mod \
/home/builder/.cache/go-build \
/home/builder/.gnupg && \
chown -R builder:builder /app /home/builder && \
chmod 700 /home/builder/.gnupg
# Set working directory
WORKDIR /app
# Switch to non-root user
USER builder
# Set environment variables for cross-compilation
ENV CGO_ENABLED=0
# Configure Git for the builder user
RUN git config --global user.name "Builder" && \
git config --global user.email "builder@generator.dev" && \
git config --global --add safe.directory /app
# Add helpful build aliases
RUN echo 'alias build="make build"' >> /home/builder/.bashrc && \
echo 'alias dist="make dist"' >> /home/builder/.bashrc && \
echo 'alias package="make package"' >> /home/builder/.bashrc && \
echo 'echo "🏗️ Generator Build Environment Ready!"' >> /home/builder/.bashrc && \
echo 'echo "Version: ${VERSION} | Commit: ${GIT_COMMIT} | Build Time: ${BUILD_TIME}"' >> /home/builder/.bashrc && \
echo 'echo "Available commands: make build, make dist, make package, make release"' >> /home/builder/.bashrc && \
echo 'echo "Output: dist/ (binaries), packages/ (DEB/RPM/Arch packages)"' >> /home/builder/.bashrc
# Health check to verify build environment
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD go version && make --version || exit 1
# Default command runs the build script if it exists, otherwise opens shell
CMD ["/bin/bash", "-c", "if [ -x './scripts/build.sh' ]; then echo 'Running build script...' && ./scripts/build.sh; else echo 'No build script found. Available commands:' && echo ' make build - Build for current platform' && echo ' make dist - Build cross-platform binaries' && echo ' make package - Create distribution packages' && echo ' make release - Full release (test, lint, security, dist, package)' && echo ' ./scripts/build.sh - Run build script directly' && echo '' && echo 'Starting interactive shell...' && /bin/bash; fi"]