Skip to content

Commit 7bb057e

Browse files
Merge pull request #34 from RostislavDugin/fix/build_for_arm
Fix/build for arm
2 parents 5f36f26 + d814c13 commit 7bb057e

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

Dockerfile

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,27 @@ COPY frontend/ ./
1313

1414
# Copy .env file (with fallback to .env.production.example)
1515
RUN 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

2121
RUN npm run build
2222

2323
# ========= BUILD BACKEND =========
24+
# Backend build stage
2425
FROM --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
2837
RUN go install github.com/swaggo/swag/cmd/[email protected]
2938

3039
# Set working directory
@@ -49,9 +58,9 @@ ARG TARGETOS
4958
ARG TARGETARCH
5059
ARG TARGETVARIANT
5160
RUN 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
6271
LABEL org.opencontainers.image.version=$APP_VERSION
6372
ENV 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)
6678
RUN 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
7890
RUN 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

8294
WORKDIR /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)
97109
COPY backend/.env* /app/
98110
RUN 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
105117
COPY <<EOF /app/start.sh
@@ -151,7 +163,8 @@ done
151163
echo "Setting up database and user..."
152164
gosu postgres \$PG_BIN/psql -p 5437 -h localhost -d postgres << 'SQL'
153165
ALTER 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')\gexec
155168
\q
156169
SQL
157170

@@ -168,4 +181,4 @@ EXPOSE 4005
168181
VOLUME ["/postgresus-data"]
169182

170183
ENTRYPOINT ["/app/start.sh"]
171-
CMD []
184+
CMD []

0 commit comments

Comments
 (0)