@@ -13,18 +13,30 @@ COPY frontend/ ./
1313
1414# Copy .env file (with fallback to .env.production.example)
1515RUN if [ ! -f .env ]; then \
16- if [ -f .env.production.example ]; then \
17- cp .env.production.example .env; \
18- fi; \
19- fi
16+ if [ -f .env.production.example ]; then \
17+ cp .env.production.example .env; \
18+ fi; \
19+ fi
2020
2121RUN npm run build
2222
2323# ========= BUILD BACKEND =========
24+ # Backend build stage
2425FROM --platform=$BUILDPLATFORM golang:1.23.3 AS backend-build
2526
26- # Install Go public tools needed in runtime
27- RUN curl -fsSL https://raw.githubusercontent.com/pressly/goose/master/install.sh | sh
27+ # Make TARGET args available early so tools built here match the final image arch
28+ ARG TARGETOS
29+ ARG TARGETARCH
30+
31+ # Install Go public tools needed in runtime. Use `go build` for goose so the
32+ # binary is compiled for the target architecture instead of downloading a
33+ # prebuilt binary which may have the wrong architecture (causes exec format
34+ # errors on ARM).
35+ RUN git clone --depth 1 --branch v3.24.3 https://github.com/pressly/goose.git /tmp/goose && \
36+ cd /tmp/goose/cmd/goose && \
37+ GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
38+ go build -o /usr/local/bin/goose . && \
39+ rm -rf /tmp/goose
2840RUN go install github.com/swaggo/swag/cmd/
[email protected] 2941
3042# Set working directory
@@ -49,35 +61,38 @@ ARG TARGETOS
4961ARG TARGETARCH
5062ARG TARGETVARIANT
5163RUN CGO_ENABLED=0 \
52- GOOS=$TARGETOS \
53- GOARCH=$TARGETARCH \
54- go build -o /app/main ./cmd/main.go
64+ GOOS=$TARGETOS \
65+ GOARCH=$TARGETARCH \
66+ go build -o /app/main ./cmd/main.go
5567
5668
5769# ========= RUNTIME =========
58- FROM --platform=$TARGETPLATFORM debian:bookworm-slim
70+ FROM debian:bookworm-slim
5971
6072# Add version metadata to runtime image
6173ARG APP_VERSION=dev
6274LABEL org.opencontainers.image.version=$APP_VERSION
6375ENV APP_VERSION=$APP_VERSION
6476
77+ # Set production mode for Docker containers
78+ ENV ENV_MODE=production
79+
6580# Install PostgreSQL server and client tools (versions 13-17)
6681RUN apt-get update && apt-get install -y --no-install-recommends \
67- wget ca-certificates gnupg lsb-release sudo gosu && \
68- wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
69- echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
70- > /etc/apt/sources.list.d/pgdg.list && \
71- apt-get update && \
72- apt-get install -y --no-install-recommends \
73- postgresql-17 postgresql-client-13 postgresql-client-14 postgresql-client-15 \
74- postgresql-client-16 postgresql-client-17 && \
75- rm -rf /var/lib/apt/lists/*
82+ wget ca-certificates gnupg lsb-release sudo gosu && \
83+ wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
84+ echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
85+ > /etc/apt/sources.list.d/pgdg.list && \
86+ apt-get update && \
87+ apt-get install -y --no-install-recommends \
88+ postgresql-17 postgresql-client-13 postgresql-client-14 postgresql-client-15 \
89+ postgresql-client-16 postgresql-client-17 && \
90+ rm -rf /var/lib/apt/lists/*
7691
7792# Create postgres user and set up directories
7893RUN useradd -m -s /bin/bash postgres || true && \
79- mkdir -p /postgresus-data/pgdata && \
80- chown -R postgres:postgres /postgresus-data/pgdata
94+ mkdir -p /postgresus-data/pgdata && \
95+ chown -R postgres:postgres /postgresus-data/pgdata
8196
8297WORKDIR /app
8398
@@ -96,10 +111,10 @@ COPY --from=backend-build /app/ui/build ./ui/build
96111# Copy .env file (with fallback to .env.production.example)
97112COPY backend/.env* /app/
98113RUN if [ ! -f /app/.env ]; then \
99- if [ -f /app/.env.production.example ]; then \
100- cp /app/.env.production.example /app/.env; \
101- fi; \
102- fi
114+ if [ -f /app/.env.production.example ]; then \
115+ cp /app/.env.production.example /app/.env; \
116+ fi; \
117+ fi
103118
104119# Create startup script
105120COPY <<EOF /app/start.sh
@@ -151,8 +166,10 @@ done
151166echo "Setting up database and user..."
152167gosu postgres \$ PG_BIN/psql -p 5437 -h localhost -d postgres << 'SQL'
153168ALTER USER postgres WITH PASSWORD 'Q1234567' ;
154- CREATE DATABASE "postgresus" OWNER postgres;
155- \q
169+ SELECT 'CREATE DATABASE postgresus OWNER postgres'
170+ WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'postgresus' )
171+ \\ gexec
172+ \\ q
156173SQL
157174
158175# Start the main application
@@ -168,4 +185,4 @@ EXPOSE 4005
168185VOLUME ["/postgresus-data" ]
169186
170187ENTRYPOINT ["/app/start.sh" ]
171- CMD []
188+ CMD []
0 commit comments