edwardinubuntu / flutter-web-dockerfile Goto Github PK
View Code? Open in Web Editor NEWA demo how to setup flutter web in docker container
Home Page: https://flutter.soleiltw.me/myanimate/
License: MIT License
A demo how to setup flutter web in docker container
Home Page: https://flutter.soleiltw.me/myanimate/
License: MIT License
Hello @edwardinubuntu, here I leave you the latest version of the dockerfile, notice that I change line 15 (17 now) where the checkout to the hash of the version is made to the checkout to the tag. I think that this way it is understood a little better and makes it easier to use different versions.
#STEP 1: BUILD
# Environemnt to install flutter and build web
FROM debian:latest AS build-env
#install all needed stuff
RUN apt-get update
RUN apt-get install -y curl git unzip
#define variables
ARG FLUTTER_VERSION=3.13.0
ARG FLUTTER_SDK_LOCATION=/usr/local/flutter
ARG APP_LOCATION=/app/
#clone flutter
RUN git clone https://github.com/flutter/flutter.git $FLUTTER_SDK_LOCATION
#change dir to current flutter folder and make a checkout to the specific version
RUN cd $FLUTTER_SDK_LOCATION && git checkout tags/$FLUTTER_VERSION
#setup the flutter path as an environment variable
ENV PATH="$FLUTTER_SDK_LOCATION/bin:$FLUTTER_SDK_LOCATION/bin/cache/dart-sdk/bin:${PATH}"
#Start to run Flutter commands
#doctor to see if all was installed ok
RUN flutter doctor -v
#create folder to copy source code
RUN mkdir $APP_LOCATION
#copy source code to folder
COPY . $APP_LOCATION
#stup new folder as the working directory
WORKDIR $APP_LOCATION
#Run build: 1 - clean, 2 - pub get, 3 - build web
RUN flutter clean
RUN flutter pub get
RUN flutter build web
#once heare the app will be compiled and ready to deploy
#STEP 2: DEPLOY
#use nginx to deploy
FROM nginx:1.25.2-alpine
#copy the info of the builded web app to nginx
COPY --from=build-env /app/build/web /usr/share/nginx/html
#Expose port and run nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
I made my version of this project, check it out
After trying different ways to compile in the shortest possible time and as structured as possible, I arrived at this final solution for the dockerfile, which I currently have running wonderful on the servers:
# Environemnt to install flutter and build web
FROM debian:latest AS build-env
#install all needed stuff
RUN apt-get update
RUN apt-get install -y curl git unzip
#define variables
ARG FLUTTER_SDK=/usr/local/flutter
ARG APP=/app/
#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 checkout efbf63d9c66b9f6ec30e9ad4611189aa80003d31
#setup the flutter path as an enviromental variable
ENV PATH="$FLUTTER_SDK/bin:$FLUTTER_SDK/bin/cache/dart-sdk/bin:${PATH}"
#Start to run Flutter commands
#doctor to see if all was installes ok
RUN flutter doctor -v
#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
#Run build: 1 - clean, 2 - pub get, 3 - build web
RUN flutter clean
RUN flutter pub get
RUN flutter build web
#once heare the app will be compiled and ready to deploy
#use nginx to deploy
FROM nginx:1.25.2-alpine
#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;"]
In the line RUN cd $FLUTTER_SDK && git checkout efbf63d9c66b9f6ec30e9ad4611189aa80003d31
, we can go to the flutter committee/version we want, in this case, version 3.13.0 named: [flutter_releases] Flutter stable 3.13.0 Framework Cherrypicks (# 132610)
, has as a hash: "efbf63d9c66b9f6ec30e9ad4611189aa80003d31", and therefore the checkout is made to that specific committee/version.
Hope this help someone ๐
[2021-06-23T06:15:31.313Z] $ cd flutter && flutter build web --web-renderer html --release
[2021-06-23T06:16:18.964Z] Downloading Web SDK... 46.8s
[2021-06-23T06:16:20.876Z]
[2021-06-23T06:16:20.876Z] Building without sound null safety
[2021-06-23T06:16:20.876Z] For more information see https://dart.dev/null-safety/unsound-null-safety
[2021-06-23T06:16:20.876Z]
[2021-06-23T06:16:59.608Z] Compiling lib/main.dart for the Web... 33.9s
I was able to run on my mac but got failed on my AWS EC2, still checking on why.
Step 5/16 : RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter
---> Running in b11215259464
Cloning into '/usr/local/flutter'...
Removing intermediate container b11215259464
---> 586d04321e5f
Step 6/16 : RUN /usr/local/flutter/bin/flutter doctor -v
---> Running in d152aa3c3184
Downloading Dart SDK from Flutter engine 810727bf3f8f7a9d23ee8e65a5209944c80fde58...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 211M 100 211M 0 0 42.5M 0 0:00:04 0:00:04 --:--:-- 44.5M
Building flutter tool...
===== CRASH =====
si_signo=Bus error(7), si_code=2, si_addr=0x7fe0af437000
version=2.8.0-dev.11.0.flutter-57462f9ca5 (Wed Mar 4 04:18:53 2020 +0000) on "linux_x64"
thread=387, isolate=(null)((nil))
isolate_instructions=0, vm_instructions=15f3540
Stack dump aborted because InitialRegisterCheck failed.
/usr/local/flutter/bin/flutter: line 59: 383 Aborted "$DART" $FLUTTER_TOOL_ARGS --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" --no-enable-mirrors "$SCRIPT_PATH"
The command '/bin/sh -c /usr/local/flutter/bin/flutter doctor -v' returned a non-zero code: 134
Hi,
I am using the docker file attached in the repo.
While building the image, i found that the flutter directory is not being copied in the image. I tried explicitly creating the directory before running the command to no avail.
I am out of ideas at this point, but wanted to reach out in case you encountered a similar issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.