-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.standalone
More file actions
116 lines (101 loc) · 4.03 KB
/
Dockerfile.standalone
File metadata and controls
116 lines (101 loc) · 4.03 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
FROM rust:1.86
WORKDIR /app
# Install PostgreSQL and build dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl-dev \
libglpk-dev \
pkg-config \
build-essential \
wget \
postgresql-15 \
postgresql-client-15 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Detect architecture and set up GLPK paths
RUN ARCH=$(dpkg --print-architecture) && \
if [ "$ARCH" = "amd64" ]; then \
LIBDIR="/usr/lib/x86_64-linux-gnu"; \
elif [ "$ARCH" = "arm64" ]; then \
LIBDIR="/usr/lib/aarch64-linux-gnu"; \
else \
LIBDIR="/usr/lib"; \
fi && \
echo "Architecture: $ARCH, Library directory: $LIBDIR" && \
export PKG_CONFIG_PATH="/usr/lib/pkgconfig:$LIBDIR/pkgconfig:/usr/share/pkgconfig" && \
mkdir -p "$LIBDIR/pkgconfig" && \
echo "prefix=/usr" > "$LIBDIR/pkgconfig/glpk.pc" && \
echo "exec_prefix=\${prefix}" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "libdir=$LIBDIR" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "includedir=\${prefix}/include" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "Name: GLPK" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "Description: GNU Linear Programming Kit" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "Version: 5.0" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "Libs: -L$LIBDIR -lglpk" >> "$LIBDIR/pkgconfig/glpk.pc" && \
echo "Cflags: -I\${includedir}" >> "$LIBDIR/pkgconfig/glpk.pc"
# Set up PostgreSQL
USER postgres
RUN /etc/init.d/postgresql start && \
psql --command "CREATE USER oatadmin WITH SUPERUSER PASSWORD 'embedded';" && \
createdb -O oatadmin oatdb && \
/etc/init.d/postgresql stop
USER root
# Configure PostgreSQL
RUN sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/15/main/postgresql.conf && \
echo "host all all 127.0.0.1/32 md5" >> /etc/postgresql/15/main/pg_hba.conf
# Copy source code and migrations
COPY Cargo.toml Cargo.lock ./
COPY src ./src
COPY migrations ./migrations
COPY scripts ./scripts
COPY .sqlx .sqlx
# Set environment variables for build
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig
ENV DATABASE_URL="postgresql://oatadmin:embedded@localhost:5432/oatdb"
# Install sqlx-cli
RUN cargo install sqlx-cli --no-default-features --features postgres --locked
# Start PostgreSQL, run migrations, and build the app
RUN service postgresql start && \
# Wait for PostgreSQL to be ready
until pg_isready -h localhost -p 5432 -U postgres; do \
echo "Waiting for PostgreSQL..."; \
sleep 2; \
done && \
# Run migrations
if [ -d "migrations" ]; then \
for migration in migrations/*.sql; do \
if [ -f "$migration" ]; then \
echo "Running migration: $migration"; \
PGPASSWORD=embedded psql -h localhost -U oatadmin -d oatdb -f "$migration" || echo "Migration had errors"; \
fi; \
done; \
fi && \
# Generate sqlx metadata if needed
cargo sqlx prepare --database-url="${DATABASE_URL}" || true && \
# Build the application (sqlx macros will validate against running database)
cargo build --release && \
# Stop PostgreSQL after build
service postgresql stop
# Set runtime environment variables
ENV DATABASE_URL="postgresql://oatadmin:embedded@localhost:5432/oatdb" \
OAT_SERVER_HOST="0.0.0.0" \
OAT_SERVER_PORT="7061" \
RUST_LOG="debug,sqlx=debug,oat_db_rust=trace" \
SQLX_LOG="debug" \
LOAD_SEED_DATA="false"
# Create logs directory
RUN mkdir -p /app/logs
# Expose port
EXPOSE 7061
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=5 \
CMD curl -f http://localhost:7061/health || exit 1
# Start PostgreSQL and then the Rust application
CMD service postgresql start && \
until pg_isready -h localhost -p 5432 -U postgres; do \
echo "Waiting for PostgreSQL..."; \
sleep 2; \
done && \
echo "PostgreSQL is ready!" && \
/app/target/release/oat-db-rust