Giter Site home page Giter Site logo

edwardinubuntu / flutter-web-dockerfile Goto Github PK

View Code? Open in Web Editor NEW
90.0 90.0 42.0 75 KB

A demo how to setup flutter web in docker container

Home Page: https://flutter.soleiltw.me/myanimate/

License: MIT License

Dockerfile 20.58% Kotlin 6.76% Swift 6.61% Objective-C 0.62% Dart 48.45% HTML 16.97%
flutterweb

flutter-web-dockerfile's People

Contributors

ed-weex avatar edwardinubuntu avatar tienisto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter-web-dockerfile's Issues

Update Dockerfile: checkout to tag version

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

This solution is amazing, but it can improve

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 ๐Ÿ‘

I use this Dockerfile to mak a docker image, and use this image to create a container,I use this container to run 'flutter build web', but is still downlaod web sdk

[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

The command '/bin/sh -c /usr/local/flutter/bin/flutter doctor -v' returned a non-zero code: 134

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

flutter: not found

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.