Cizz22 10 months ago
parent 067c1fe229
commit a969c53acb

@ -27,6 +27,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
make \ make \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Create non-root user with password
RUN useradd -r -m -s /bin/bash appuser && \
echo "appuser:your_password_here" | chpasswd
# Set environment variables for Poetry # Set environment variables for Poetry
ENV POETRY_VIRTUALENVS_IN_PROJECT=1 \ ENV POETRY_VIRTUALENVS_IN_PROJECT=1 \
PATH="/app/.venv/bin:$PATH" PATH="/app/.venv/bin:$PATH"
@ -34,22 +38,27 @@ ENV POETRY_VIRTUALENVS_IN_PROJECT=1 \
# Copy Poetry installation from builder # Copy Poetry installation from builder
COPY --from=builder /app/.venv /app/.venv COPY --from=builder /app/.venv /app/.venv
# Copy authentication script and entrypoint script
ENV PASSWORD="supersecret"
COPY auth.sh entrypoint.sh /app/
RUN chmod +x /app/auth.sh /app/entrypoint.sh
# Copy application files # Copy application files
COPY . /app/ COPY . /app/
# Delete Tests for production # Delete Tests for production
RUN rm -rf /app/tests/ RUN rm -rf /app/tests/
# Restrict file permissions in /app
RUN chmod -R o-rwx,g-rwx /app/ && \
chown -R appuser:appuser /app/
# Disable root login
RUN chsh -s /usr/sbin/nologin root
# Expose port for the application # Expose port for the application
EXPOSE 3000 EXPOSE 3000
# Set the working directory # Set the working directory
WORKDIR /app WORKDIR /app
# Use our new entrypoint script # Switch to non-root user
CMD ["/app/entrypoint.sh"] USER appuser
# Run `make run` as the entry point
CMD ["make", "run"]

@ -1,11 +0,0 @@
#!/bin/bash
# Use the environment variable for the password
echo -n "Enter password to access container: "
read -s input_password
echo ""
if [ "$input_password" != "$PASSWORD" ]; then
echo "Access denied!"
exit 1
fi
echo "Access granted!"

@ -1,9 +0,0 @@
#!/bin/bash
# Run the authentication check first
/app/auth.sh
# If authentication passes, run the application
if [ $? -eq 0 ]; then
make run
fi
Loading…
Cancel
Save