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