forked from rehmatworks/fastcp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
148 lines (117 loc) · 4.74 KB
/
Copy pathDockerfile
File metadata and controls
148 lines (117 loc) · 4.74 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
# FastCP Development Dockerfile
# Multi-stage build for both development and production
# =============================================================================
# Stage 1: Builder
# =============================================================================
FROM golang:1.22-bookworm AS builder
WORKDIR /build
# Install build dependencies
RUN apt-get update && apt-get install -y \
libpam0g-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy go mod files first for caching
COPY go.mod go.sum* ./
RUN go mod download
# Copy source code
COPY . .
# Build binaries
RUN CGO_ENABLED=1 go build -o /build/bin/fastcp ./cmd/fastcp
RUN CGO_ENABLED=1 go build -o /build/bin/fastcp-agent ./cmd/fastcp-agent
# =============================================================================
# Stage 2: Development Image
# =============================================================================
FROM ubuntu:24.04 AS development
ARG TARGETARCH
# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
acl \
mysql-server \
supervisor \
libpam0g \
build-essential \
libpam0g-dev \
software-properties-common \
gnupg2 \
apt-transport-https \
lsb-release \
ca-certificates \
restic \
&& rm -rf /var/lib/apt/lists/*
# Install Go 1.22 based on architecture
RUN ARCH=${TARGETARCH:-amd64} && \
if [ "$ARCH" = "arm64" ]; then GO_ARCH="arm64"; else GO_ARCH="amd64"; fi && \
curl -fsSL "https://go.dev/dl/go1.22.5.linux-${GO_ARCH}.tar.gz" | tar -C /usr/local -xzf -
ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}"
ENV GOPATH="/root/go"
# Install Caddy (plain reverse proxy)
RUN ARCH=${TARGETARCH:-amd64} && \
if [ "$ARCH" = "arm64" ]; then CADDY_ARCH="arm64"; else CADDY_ARCH="amd64"; fi && \
curl -fsSL "https://caddyserver.com/api/download?os=linux&arch=${CADDY_ARCH}" \
-o /usr/local/bin/caddy && chmod +x /usr/local/bin/caddy
# Install Ondrej PHP versions + common modules
RUN add-apt-repository -y ppa:ondrej/php && \
apt-get update && \
COMMON_PHP_MODULES="bcmath bz2 cli common curl fpm gd gmp igbinary imagick imap intl mbstring mysql opcache readline redis soap sqlite3 xml xmlrpc zip" && \
for v in 8.2 8.3 8.4 8.5; do \
for m in $COMMON_PHP_MODULES; do \
apt-get install -y "php${v}-${m}" || true; \
done; \
apt-get install -y "php${v}" "php${v}-fpm" || true; \
done && \
rm -rf /var/lib/apt/lists/*
# Create directories
RUN mkdir -p /opt/fastcp/bin /opt/fastcp/data /opt/fastcp/config /opt/fastcp/run \
/var/log/fastcp /var/log/supervisor /opt/fastcp/phpmyadmin && chmod 1777 /opt/fastcp/run
# Create test user for development
RUN useradd -m -s /bin/bash testuser && echo "testuser:testpass" | chpasswd
# Download and configure phpMyAdmin
RUN curl -fsSL https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.tar.gz \
| tar -xz -C /opt/fastcp/phpmyadmin --strip-components=1
# Generate encryption secret for dev
RUN openssl rand -base64 32 > /opt/fastcp/data/.secret && chmod 600 /opt/fastcp/data/.secret
# Initialize MySQL data directory
RUN mkdir -p /var/run/mysqld && chown mysql:mysql /var/run/mysqld
# Copy supervisor config and initial Caddyfile
COPY docker/supervisord.conf /etc/supervisor/conf.d/fastcp.conf
COPY docker/Caddyfile /opt/fastcp/config/Caddyfile
# Working directory for development
WORKDIR /app
# Expose ports
EXPOSE 80 443 2050 3306
# Default command
CMD ["/bin/bash"]
# =============================================================================
# Stage 3: Production Image
# =============================================================================
FROM ubuntu:24.04 AS production
ARG TARGETARCH
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
curl \
acl \
mysql-server \
supervisor \
libpam0g \
ca-certificates \
restic \
&& rm -rf /var/lib/apt/lists/*
# Install Caddy based on architecture
RUN ARCH=${TARGETARCH:-amd64} && \
if [ "$ARCH" = "arm64" ]; then CADDY_ARCH="arm64"; else CADDY_ARCH="amd64"; fi && \
curl -fsSL "https://caddyserver.com/api/download?os=linux&arch=${CADDY_ARCH}" \
-o /usr/local/bin/caddy && chmod +x /usr/local/bin/caddy
# Create directories
RUN mkdir -p /opt/fastcp/bin /opt/fastcp/data /opt/fastcp/config /opt/fastcp/run \
/var/log/fastcp /var/log/supervisor && chmod 1777 /opt/fastcp/run
# Copy binaries from builder
COPY --from=builder /build/bin/fastcp /opt/fastcp/bin/
COPY --from=builder /build/bin/fastcp-agent /opt/fastcp/bin/
COPY docker/supervisord.conf /etc/supervisor/conf.d/fastcp.conf
COPY docker/Caddyfile /opt/fastcp/config/
EXPOSE 80 443 2050
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]