-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
83 lines (68 loc) · 3.12 KB
/
Dockerfile
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
FROM rust:bookworm AS builder
ARG BUILD_TYPE=release
ENV BUILD_TYPE=${BUILD_TYPE}
WORKDIR /app/gallery-backend
COPY ./gallery-backend/Cargo.lock /app/gallery-backend/Cargo.lock
COPY ./gallery-backend/Cargo.toml /app/gallery-backend/Cargo.toml
COPY ./gallery-backend/src /app/gallery-backend/src
COPY ./gallery-backend/lib /app/gallery-backend/lib
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Build the backend binary based on the build type
RUN if [ "${BUILD_TYPE}" = "release" ]; then \
cargo build --release --bin urocissa; \
elif [ "${BUILD_TYPE}" = "debug" ]; then \
cargo build --bin urocissa; \
else \
cargo build --profile "${BUILD_TYPE}" --bin urocissa; \
fi
RUN cp /app/gallery-backend/target/${BUILD_TYPE}/urocissa /app/gallery-backend/urocissa
######################
# Frontend builder stage
######################
FROM node:lts AS frontend-builder
WORKDIR /app/gallery-frontend
COPY ./gallery-frontend /app/gallery-frontend
RUN npm ci && npm run build
######################
# Runtime stage
######################
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app/gallery-backend
# Copy backend binary
COPY --from=builder /app/gallery-backend/urocissa /app/gallery-backend/urocissa
# Copy frontend assets
COPY --from=frontend-builder /app/gallery-frontend/dist /app/gallery-frontend/dist
COPY --from=frontend-builder /app/gallery-frontend/public /app/gallery-frontend/public
# Add an entrypoint script that will:
# 1. Check if UROCISSA_PATH is set
# 2. Move /app/gallery-* to ${UROCISSA_PATH}/gallery-* if set
# 3. Run the urocissa binary
WORKDIR /app
# Create the entrypoint script
RUN echo '#!/bin/sh' > /entrypoint.sh && \
echo 'set -e' >> /entrypoint.sh && \
echo 'if [ -z "${UROCISSA_PATH}" ]; then' >> /entrypoint.sh && \
echo ' echo "Error: UROCISSA_PATH is not set. Terminating."' >> /entrypoint.sh && \
echo ' exit 1' >> /entrypoint.sh && \
echo 'else' >> /entrypoint.sh && \
echo ' mkdir -p "${UROCISSA_PATH}/gallery-backend"' >> /entrypoint.sh && \
echo ' mkdir -p "${UROCISSA_PATH}/gallery-frontend"' >> /entrypoint.sh && \
echo ' mv /app/gallery-backend/* "${UROCISSA_PATH}/gallery-backend"' >> /entrypoint.sh && \
echo ' mv /app/gallery-frontend/* "${UROCISSA_PATH}/gallery-frontend"' >> /entrypoint.sh && \
echo ' echo "Listing ${UROCISSA_PATH}/gallery-backend:"' >> /entrypoint.sh && \
echo ' ls -al "${UROCISSA_PATH}/gallery-backend"' >> /entrypoint.sh && \
echo ' echo "Listing ${UROCISSA_PATH}/gallery-frontend:"' >> /entrypoint.sh && \
echo ' ls -al "${UROCISSA_PATH}/gallery-frontend"' >> /entrypoint.sh && \
echo ' cd "${UROCISSA_PATH}/gallery-backend"' >> /entrypoint.sh && \
echo 'fi' >> /entrypoint.sh && \
echo 'echo "Attempting to run ./urocissa"' >> /entrypoint.sh && \
echo 'exec ./urocissa' >> /entrypoint.sh && \
chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]