Files
tmail-flutter/Dockerfile
T
2026-01-29 10:32:35 +07:00

53 lines
2.1 KiB
Docker

ARG FLUTTER_VERSION=3.32.8
# Sentry build-time configuration (used only during the build stage)
# These values are provided via GitHub Actions secrets and are NOT persisted
# into the final runtime image.
ARG SENTRY_AUTH_TOKEN
ARG SENTRY_ORG
ARG SENTRY_PROJECT
ARG SENTRY_URL
ARG SENTRY_RELEASE
# Stage 1 - Install dependencies and build the app
# This matches the flutter version on our CI/CD pipeline on Github
FROM --platform=amd64 ghcr.io/instrumentisto/flutter:${FLUTTER_VERSION} AS build-env
# Set directory to Copy App
WORKDIR /app
COPY . .
# Install Sentry CLI for uploading source maps when configuration is provided.
# If the install script fails (e.g. offline/local build), we log and continue.
RUN curl -sL https://sentry.io/get-cli/ | bash || echo "Sentry CLI install failed, continuing without sourcemap upload"
# Precompile tmail flutter
RUN ./scripts/prebuild.sh
# Build flutter for web (with source maps for Sentry)
RUN flutter build web --release --source-maps
# Upload source maps to Sentry when all required variables are available.
# The build will NOT fail if this step or Sentry CLI is unavailable.
RUN if [ -n "$SENTRY_AUTH_TOKEN" ] && [ -n "$SENTRY_ORG" ] && [ -n "$SENTRY_PROJECT" ] && [ -n "$SENTRY_RELEASE" ]; then \
echo "Sentry configuration detected, uploading sourcemaps for release $SENTRY_RELEASE" && \
sentry-cli releases new "$SENTRY_RELEASE" && \
sentry-cli releases set-commits "$SENTRY_RELEASE" --auto || echo "Sentry set-commits failed, continuing" && \
sentry-cli releases files "$SENTRY_RELEASE" upload-sourcemaps build/web --url-prefix "~/"; \
else \
echo "Sentry configuration not complete, skipping sourcemap upload"; \
fi || echo "Sentry sourcemap upload step failed, continuing build"
# Stage 2 - Create the run-time image
FROM nginx:alpine
RUN apk add gzip
COPY --from=build-env /app/server/nginx.conf /etc/nginx
COPY --from=build-env /app/build/web /usr/share/nginx/html
# Record the exposed port
EXPOSE 80
# Before stating NGinx, re-zip all the content to ensure customizations are propagated
CMD gzip -k -r -f /usr/share/nginx/html/ && nginx -g 'daemon off;'