Dockerize flutter web project - flutter

I'm trying to dockerize my flutter web project. And an image was created and the site run perfectly just the pictures of my website are not found and not displayed and I don't know why.it gave me this error :
172.17.0.1 - - [12/May/2022 14:25:04] "GET / HTTP/1.1" 200 -
172.17.0.1 - - [12/May/2022 14:25:04] code 404, message File not found
172.17.0.1 - - [12/May/2022 14:25:04] "GET /packages/image_cropper_for_web/src/croppie/js/croppie.css HTTP/1.1" 404 -
172.17.0.1 - - [12/May/2022 14:25:05] code 404, message File not found
172.17.0.1 - - [12/May/2022 14:25:09] "GET /assets/photos/bgfinal.png HTTP/1.1" 404 -
172.17.0.1 - - [12/May/2022 14:25:09] code 404, message File not found
Dockerfile:
FROM ubuntu:20.04
RUN apt-get update
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3
RUN apt-get clean
# download Flutter SDK from Flutter Github repo
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter
# Set flutter environment path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
# Run flutter doctor
RUN flutter doctor
# Enable flutter web
RUN flutter channel master
RUN flutter upgrade
RUN flutter config --enable-web
# Copy files to container and build
RUN mkdir /app/
COPY . /app/
WORKDIR /app/
RUN flutter build web
# Record the exposed port
EXPOSE 5000
# make server startup script executable and start the web server
RUN ["chmod", "+x", "/app/server/server.sh"]
ENTRYPOINT [ "/app/server/server.sh"]
this is server.sh file:
#!/bin/bash
# Set the port
PORT=5000
# Stop any program currently running on the set port
echo 'preparing port' $PORT '...'
fuser -k 5000/tcp
# switch directories
cd build/web/
# Start the server
echo 'Server starting on port' $PORT '...'
python3 -m http.server $PORT

So here is the thing. I think there are some problems with his code. As I tried to build with his code yesterday but things weren't working as they should be. I spend 2hours with his code of which 50% was spent on building the image but it was never completed. No problem I tried to modify some things and I am sharing some code with you on GitHub https://github.com/ash-0001/fludino.git. Just keep learning and sharing. Good Is Image.
The final image looks like this:
You have to use two commands to initialize this:
Before that move into the directory with your cmd
docker build -t flut .
docker run -i -p 808:4040 -td flut

Related

running elixir on buildkite with docker-compose fails with dependencies

i have the following dockerfile for an elixir+phoenix app
FROM elixir:latest as build_base
RUN apt-get -y update
RUN apt-get -y install inotify-tools curl
ARG TARGETARCH
RUN if [ ${TARGETARCH} = arm64 ]; then \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-${TARGETARCH}.tar.gz \
;else \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-x64.tar.gz \
;fi
RUN tar -xvf /tmp/dart-sass.tar.gz -C /tmp
RUN mv /tmp/dart-sass/sass /usr/local/bin/sass
RUN mkdir -p /app
WORKDIR /app
COPY mix.* ./
RUN mix local.hex --force
RUN mix archive.install hex phx_new --force
RUN mix local.rebar --force
RUN mix deps.clean --all
RUN mix deps.get
RUN mix --version
RUN mix deps.compile
COPY assets assets
COPY vendor vendor
COPY lib lib
COPY config config
COPY priv priv
COPY test test
RUN mix compile
the docker-compose file looks like the following
services:
web:
build:
context: .
dockerfile: Dockerfile
target: build_base
volumes:
- ./:/app
ports:
- "80:80"
command: mix phx.server
I'm trying to run docker-compose as part of the build step in buildkite, this is an extract of the step in buildkite
- label: "run web"
key: "web"
commands:
- mix phx.server
plugins:
- docker-compose#v4.9.0:
run: web
config: docker-compose.yml
however when running web i see everything happens properly including the package installation, however when running the application i see the following error
web_1 | Unchecked dependencies for environment dev:
web_1 | * telemetry_metrics (Hex package)
web_1 | the dependency is not available, run "mix deps.get"
and the list goes on and on, this works fine on my local machine, its only when running on buildkite. does anyone have any idea on how to fix this ?

How should I set up cipher suites for Java TLS

i build myself docker image use jre1.8.0_341 + alpine + glibc(2.33)
first:
I downloaded the jar package of jre1.8.0_341
Below is my Dockerfile:
FROM alpine:latest
ADD jre1.8.0_341/jre8.tar.gz /usr/java/jdk/
ENV JAVA_HOME /usr/java/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk
RUN apk add glibc-2.33-r0.apk
WORKDIR /
Next build the docker image
docker build -f Dockerfile -t myself:latest .
when i run this imgaes
docker run -it myself:latest /bin/bash
Get java version
but i use "FeignClient" to Request other services
report an error: “javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure”
so i add Java startup parameters -Djavax.net.debug=all
and Compare TLS packets using "openjdk:8-jre-alpine" as the base image
I found that there is no "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" in the "cipher suites" parameter during the "Produced ClientHello handshake message" phase
How should I set up cipher suites for Java TLS?

How inject URL while creating flutter build web using docker

I am trying to inject URL while creating flutter build web. For Inject URL I am using environment variable. Docker file success fully create the docker image and docker container. But when I open web application on browser the environment variable is empty. I did not understand what I am missing. Previously I have no experience with docker That was my first time. Please Guide me what I am doing wrong.
To build docker image I am using command.
docker build . -t test-application
To run docker container I using command
docker run -ti -p 5000:4040 -e API_URL=example.com test-application
My docker file.
# Install dependencies
FROM debian:latest AS build-env
RUN apt-get update
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3 psmisc
RUN apt-get clean
# Clone the flutter repo
RUN git clone https://github.com/flutter/flutter.git -b stable /usr/local/flutter
# Set flutter path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
# Enable flutter web
# RUN flutter channel stable
# RUN flutter upgrade
# RUN flutter config --enable-web
# Run flutter doctor
RUN flutter doctor -v
# Copy the app files to the container
COPY . /usr/local/bin/app
# Set the working directory to the app files within the container
WORKDIR /usr/local/bin/app
# Get App Dependencies
RUN flutter clean
# Get App Dependencies
RUN flutter pub get
# Build the app for the web
RUN flutter build web --release --dart-define API_URL=${API_URL:-}
# Document the exposed port
EXPOSE 4040
# Set the server startup script as executable
RUN ["chmod", "+x", "/usr/local/bin/app/server/server.sh"]
# Start the web server
ENTRYPOINT [ "/usr/local/bin/app/server/server.sh" ]
my server.sh file
#!/bin/bash
# Welcome
echo 'Server start script initialized'
# Set the port
PORT=4040
# Kill anything that is already running on that port
echo 'Cleaning port' $PORT
fuser -k 4040/tcp
# Change directories to the release folder
cd build/web/
# Start the server
echo 'Starting server on port' $PORT
python3 -m http.server $PORT
# Exit
echo 'Server exited...'
Getting my environment variable
static const baseUrl =
"${const String.fromEnvironment("API_URL")}/public";
To use a build argument, you need to add an ARG statement in your dockerfile. To also have it available at runtime, you can add an ENV statement, that sets an environment variable with the value of the build argument
# Install dependencies
FROM debian:latest AS build-env
# Add the following two lines
ARG API_URL
ENV API_URL=$API_URL
RUN apt-get update
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3 psmisc
RUN apt-get clean
# Clone the flutter repo
RUN git clone https://github.com/flutter/flutter.git -b stable /usr/local/flutter
# Set flutter path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
# Enable flutter web
# RUN flutter channel stable
# RUN flutter upgrade
# RUN flutter config --enable-web
# Run flutter doctor
RUN flutter doctor -v
# Copy the app files to the container
COPY . /usr/local/bin/app
# Set the working directory to the app files within the container
WORKDIR /usr/local/bin/app
# Get App Dependencies
RUN flutter clean
# Get App Dependencies
RUN flutter pub get
# Build the app for the web
RUN flutter build web --release --dart-define API_URL=${API_URL:-}
# Document the exposed port
EXPOSE 4040
# Set the server startup script as executable
RUN ["chmod", "+x", "/usr/local/bin/app/server/server.sh"]
# Start the web server
ENTRYPOINT [ "/usr/local/bin/app/server/server.sh" ]
Then when you build, you add the value you want like this
docker build --build-arg API_URL=example.com -t test-application .
You then don't need to specify it at runtime unless you want to override it, so your run command becomes. Overriding it will only override the environment variable and won't change what was put into the image at build time, of course.
docker run -ti -p 5000:4040 test-application

Continuous integration using bitbucket pipelines FAILED for OpenEdx

I am trying to set up CI process using bitbucket pipelines for my Openedx site. The script that i am using in my bitbucket-pipelines.yml file is given below. I am trying to just set up the build process on LMS (themes), so that whenever someone make any change in the front end of the site, the build updates paver assets and recompile the assets.The problem is that it is failing on paver update assets.
I have tried to copy the devstack code to my bitbucket repo instead of cloning from git, the problem is Devstack has been updated to Ironwood, but my site is using hawthorn version. I am trying to make the devstack repo hawthorn compatible due to which i am using "hawthorn.master" branch. I have also increased the memory to the most I possibly could.
Also, i saw that cloning was not working well due to which i have set up origin inside the docker environment and then it was fetching all the required files but then it gives the Subprocess return code 1 error. The script in my bitbucket-pipleines.yml is :
image: python:3.5.6
definitions:
services:
docker:
memory: 7168
options:
size: 2x # all steps in this repo get 8GB memory
pipelines:
default:
- step:
services:
- docker
script:
# Upgrade Docker Compose to the latest version test
- python --version
- export DOCKER_COMPOSE_VERSION=1.13.0
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- mv docker-compose /usr/local/bin
- export OPENEDX_RELEASE=hawthorn.master
- git clone https://github.com/sanjaysample/devstack.git
- cd devstack
- git checkout open-release/hawthorn.master
- make dev.checkout
- make requirements
- make dev.clone
- ls
- make pull
- make dev.up
- sleep 60 # LMS needs like 60 seconds to come up
- docker cp ../metronic edx.devstack.lms:/edx/app/edxapp/edx-platform/themes
- docker cp ../pavelib edx.devstack.lms:/edx/app/edxapp/edx-platform
- wget https://raw.githubusercontent.com/sumbul03/edx-theme/master/lms.env.json
- docker cp lms.env.json edx.devstack.lms:/edx/app/edxapp/lms.env.json
- rm lms.env.json
- docker cp edx.devstack.lms:/edx/app/edxapp/lms.env.json .
- cat lms.env.json
- docker ps
- docker-compose restart lms
- docker-compose exec -T lms bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && git init && git remote add origin https://github.com/edx/edx-platform.git && git fetch origin open-release/hawthorn.master && git checkout -f open-release/hawthorn.master && paver install_prereqs && paver update_assets lms --settings=devstack_docker --debug'
The build fails at this error:
python manage.py lms --settings=devstack_docker print_setting STATIC_ROOT 2>/dev/null
Build failed running pavelib.assets.update_assets: Subprocess return code: 1
Does anyone know the solution to this problem? Please suggest.

OWASP/ZAP dangling when trying to scan

I am trying out OWASP/ZAP to see if it is something we can use for our project, but I cannot make it work I don't know what I am doing wrong and the documentation really does not help. What I am trying is to run a scan on my api running in a docker container locally on my windows machine so I run the command:
docker run -v $(pwd):/zap/wrk/:rw -t owasp/zap2docker-stable zap-baseline.py -t http://172.21.0.2:8080/swagger.json -g gen.conf -r testreport.html the ip 172.21.0.2 is the IPAddress of my api container even tried with localhost and 127.0.0.1
but it just hangs in the following log message:
_XSERVTransmkdir: ERROR: euid != 0,directory /tmp/.X11-unix will not be created.
Feb 14, 2019 1:43:31 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Nothing happens and my zap docker container is in a unhealthy state, after some time it just crashes and ends up with a bunch of NullPointerExceptions. Is zap docker only working for linux, something specifically I need to do when running it on a windows machine? I don't get why this is not working even when I am following specifically the guideline in https://github.com/zaproxy/zaproxy/wiki/Docker
Edit 1
My latest try where I am trying to target my host ip address directly and the port that I am exposing my api to gives me the following error:
_XSERVTransmkdir: ERROR: euid != 0,directory /tmp/.X11-unix will not be created.
Feb 14, 2019 2:12:07 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Total of 3 URLs
ERROR Permission denied
2019-02-14 14:12:57,116 I/O error(13): Permission denied
Traceback (most recent call last):
File "/zap/zap-baseline.py", line 347, in main
with open(base_dir + generate, 'w') as f:
IOError: [Errno 13] Permission denied: '/zap/wrk/gen.conf'
Found Java version 1.8.0_151
Available memory: 3928 MB
Setting jvm heap size: -Xmx982m
213 [main] INFO org.zaproxy.zap.DaemonBootstrap
When you run docker with: docker run -v $(pwd):/zap/wrk/:rw ...
you are mapping the /zap/wrk/ directory in the docker image to the current working directory (cwd) of the machine in which you are running docker.
I think the problem is that your current user doesn't have write access to the cwd.
Try below command, hope it resolves issue.
$docker run --user $(id -u):$(id -g) -v $(pwd):/zap/wrk/:rw --rm -t owasp/zap2docker-stable zap-baseline.py -t https://your_url -g gen.conf -r testreport.html
The key error here is:
IOError: [Errno 13] Permission denied: '/zap/wrk/gen.conf'
This means that the script cannot write to the gen.conf file that you have mounted on /zap/wrk
Do you have write access to the cwd when its not mounted?
The reason for that is, if you use -r parameter, zap will attempt to generate the file report.html at location /zap/wrk/. In order to make this work, we have to mount a directory to this location /zap/wrk.
But when you do so, it is important that the zap container is able to perform the write operations on the mounted directory.
So, below is the working solution using gitlab ci yml. I started with this approach of using image: owasp/zap2docker-stable however then had to go to the vanilla docker commands to execute it.
test_site:
stage: test
image: docker:latest
script:
# The folder zap-reports created locally will be mounted to owasp/zap2docker docker container,
# On execution it will generate the reports in this folder. Current user is passed so reports can be generated"
- mkdir zap-reports
- cd zap-reports
- docker pull owasp/zap2docker-stable:latest || echo
- docker run --name zap-container --rm -v $(pwd):/zap/wrk -u $(id -u ${USER}):$(id -g ${USER}) owasp/zap2docker-stable zap-baseline.py -t "https://example.com" -r report.html
artifacts:
when: always
paths:
- zap-reports
allow_failure: true
So the trick in the above code is
Mount local directory zap-reports to /zap/wrk as in $(pwd):/zap/wrk
Pass the current user and group on the host machine to the docker container so the process is using the same user / group. This allows writing of reports on the directory mounted from local host. This is done by -u $(id -u ${USER}):$(id -g ${USER})
Below is the working code with image: owasp/zap2docker-stable
test_site:
variables:
GIT_STRATEGY: none
stage: test
image:
name: owasp/zap2docker-stable:latest
before_script:
- mkdir -p /zap/wrk
script:
- zap-baseline.py -t "https://example.com" -g gen.conf -I -r testreport.html
- cp /zap/wrk/testreport.html testreport.html
artifacts:
when: always
paths:
- zap.out
- testreport.html