dockerfile fix
This commit is contained in:
97
Dockerfile
97
Dockerfile
@@ -1,78 +1,47 @@
|
||||
# syntax=docker/dockerfile:1.6
|
||||
# Environemnt to install flutter and build web
|
||||
FROM debian:latest AS build-env
|
||||
|
||||
###############################################
|
||||
# Build stage: compile Flutter web artifacts. #
|
||||
###############################################
|
||||
FROM ubuntu:22.04 AS build
|
||||
# install all needed stuff
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y curl git unzip
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
FLUTTER_CHANNEL=stable \
|
||||
FLUTTER_VERSION=3.24.3 \
|
||||
FLUTTER_HOME=/opt/flutter
|
||||
# define variables
|
||||
ARG FLUTTER_SDK=/usr/local/flutter
|
||||
ARG FLUTTER_VERSION=3.31.0
|
||||
ARG APP=/app/
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
curl \
|
||||
git \
|
||||
unzip \
|
||||
xz-utils \
|
||||
zip \
|
||||
libglu1-mesa && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
#clone flutter
|
||||
RUN git clone https://github.com/flutter/flutter.git $FLUTTER_SDK
|
||||
# change dir to current flutter folder and make a checkout to the specific version
|
||||
RUN cd $FLUTTER_SDK && git fetch && git checkout $FLUTTER_VERSION
|
||||
|
||||
RUN curl -fsSL "https://storage.googleapis.com/flutter_infra_release/releases/${FLUTTER_CHANNEL}/linux/flutter_linux_${FLUTTER_VERSION}-${FLUTTER_CHANNEL}.tar.xz" \
|
||||
| tar -xJ -C /opt && \
|
||||
ln -s ${FLUTTER_HOME} /usr/local/flutter
|
||||
# setup the flutter path as an enviromental variable
|
||||
ENV PATH="$FLUTTER_SDK/bin:$FLUTTER_SDK/bin/cache/dart-sdk/bin:${PATH}"
|
||||
|
||||
ENV PATH="${FLUTTER_HOME}/bin:${FLUTTER_HOME}/bin/cache/dart-sdk/bin:${PATH}"
|
||||
# Start to run Flutter commands
|
||||
# doctor to see if all was installes ok
|
||||
RUN flutter doctor -v
|
||||
|
||||
# Create a non-root user for Flutter
|
||||
RUN useradd -m -s /bin/bash flutter && \
|
||||
chown -R flutter:flutter ${FLUTTER_HOME}
|
||||
# create folder to copy source code
|
||||
RUN mkdir $APP
|
||||
# copy source code to folder
|
||||
COPY . $APP
|
||||
# stup new folder as the working directory
|
||||
WORKDIR $APP
|
||||
|
||||
# Switch to non-root user for Flutter commands
|
||||
USER flutter
|
||||
|
||||
RUN flutter config --enable-web && \
|
||||
flutter doctor -v
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --chown=flutter:flutter pubspec.yaml pubspec.lock ./
|
||||
# Run build: 1 - clean, 2 - pub get, 3 - build web
|
||||
RUN flutter clean
|
||||
RUN flutter pub get
|
||||
RUN flutter build web
|
||||
|
||||
COPY --chown=flutter:flutter . .
|
||||
RUN flutter build web --release
|
||||
# once heare the app will be compiled and ready to deploy
|
||||
|
||||
##########################################
|
||||
# Runtime stage: serve assets via nginx. #
|
||||
##########################################
|
||||
FROM ubuntu:22.04 AS runner
|
||||
# use nginx to deploy
|
||||
FROM nginx:1.25.2-alpine
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends nginx && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Remove default site definition to avoid duplicate configs.
|
||||
RUN rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
# Provide a minimal nginx site config for the Flutter web assets.
|
||||
RUN printf 'server {\n\
|
||||
listen 80 default_server;\n\
|
||||
listen [::]:80 default_server;\n\
|
||||
root /var/www/html;\n\
|
||||
index index.html;\n\
|
||||
location / {\n\
|
||||
try_files $uri $uri/ /index.html;\n\
|
||||
}\n\
|
||||
}\n' > /etc/nginx/conf.d/flutter.conf
|
||||
|
||||
COPY --from=build /app/build/web /var/www/html
|
||||
# copy the info of the builded web app to nginx
|
||||
COPY --from=build-env /app/build/web /usr/share/nginx/html
|
||||
|
||||
# Expose and run nginx
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user