@@ -13,18 +13,27 @@ 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 install` 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 env GOBIN=/usr/local/bin GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
36+ go install github.com/pressly/goose/v3/cmd/goose@latest
2837RUN go install github.com/swaggo/swag/cmd/
[email protected] 2938
3039# Set working directory
@@ -49,9 +58,9 @@ ARG TARGETOS
4958ARG TARGETARCH
5059ARG TARGETVARIANT
5160RUN CGO_ENABLED=0 \
52- GOOS=$TARGETOS \
53- GOARCH=$TARGETARCH \
54- go build -o /app/main ./cmd/main.go
61+ GOOS=$TARGETOS \
62+ GOARCH=$TARGETARCH \
63+ go build -o /app/main ./cmd/main.go
5564
5665
5766# ========= RUNTIME =========
@@ -62,22 +71,25 @@ ARG APP_VERSION=dev
6271LABEL org.opencontainers.image.version=$APP_VERSION
6372ENV APP_VERSION=$APP_VERSION
6473
74+ # Set production mode for Docker containers
75+ ENV ENV_MODE=production
76+
6577# Install PostgreSQL server and client tools (versions 13-17)
6678RUN 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/*
79+ wget ca-certificates gnupg lsb-release sudo gosu && \
80+ wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
81+ echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
82+ > /etc/apt/sources.list.d/pgdg.list && \
83+ apt-get update && \
84+ apt-get install -y --no-install-recommends \
85+ postgresql-17 postgresql-client-13 postgresql-client-14 postgresql-client-15 \
86+ postgresql-client-16 postgresql-client-17 && \
87+ rm -rf /var/lib/apt/lists/*
7688
7789# Create postgres user and set up directories
7890RUN useradd -m -s /bin/bash postgres || true && \
79- mkdir -p /postgresus-data/pgdata && \
80- chown -R postgres:postgres /postgresus-data/pgdata
91+ mkdir -p /postgresus-data/pgdata && \
92+ chown -R postgres:postgres /postgresus-data/pgdata
8193
8294WORKDIR /app
8395
@@ -96,10 +108,10 @@ COPY --from=backend-build /app/ui/build ./ui/build
96108# Copy .env file (with fallback to .env.production.example)
97109COPY backend/.env* /app/
98110RUN 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
111+ if [ -f /app/.env.production.example ]; then \
112+ cp /app/.env.production.example /app/.env; \
113+ fi; \
114+ fi
103115
104116# Create startup script
105117COPY <<EOF /app/start.sh
151163echo "Setting up database and user..."
152164gosu postgres \$ PG_BIN/psql -p 5437 -h localhost -d postgres << 'SQL'
153165ALTER USER postgres WITH PASSWORD 'Q1234567' ;
154- CREATE DATABASE "postgresus" OWNER postgres;
166+ SELECT 'CREATE DATABASE postgresus OWNER postgres'
167+ WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'postgresus' )\g exec
155168\q
156169SQL
157170
@@ -168,4 +181,4 @@ EXPOSE 4005
168181VOLUME ["/postgresus-data" ]
169182
170183ENTRYPOINT ["/app/start.sh" ]
171- CMD []
184+ CMD []
0 commit comments