From ba5843e2badd3df79f5139517a144f55c70d08be Mon Sep 17 00:00:00 2001 From: ScottLatte Date: Tue, 19 Mar 2024 13:40:37 +0700 Subject: [PATCH] 'docker' --- .devcontainer/devcontainer.json | 13 ++++++++ Dockerfile | 57 +++++++++++++++++++++++++++++++++ docker-compose.yml | 8 +++++ lib/home.dart | 3 +- server/server.sh | 18 +++++++++++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 server/server.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..05b1516 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,13 @@ +{ + "name": "flutter_docker", + "context": "..", + "dockerFile": "../Dockerfile", + "remoteUser": "developer", + "settings": { + "terminal.integrated.shell.linux": null + }, + "runArgs": ["--privileged"], + "extensions": ["dart-code.flutter"], + "workspaceMount": "source=${localWorkspaceFolder}/workspace,target=/home/developer/workspace,type=bind,consistency=delegated", + "workspaceFolder": "/home/developer/workspace" + } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e701d9c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +# Install Operating system and dependencies +FROM ubuntu:20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update +RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback python3 +RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget +RUN apt-get clean + +ENV DEBIAN_FRONTEND=dialog +ENV PUB_HOSTED_URL=https://pub.flutter-io.cn +ENV FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn + +# 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 + + + + +# Prepare Android directories and system variables +RUN mkdir -p Android/sdk +ENV ANDROID_SDK_ROOT /home/developer/Android/sdk +RUN mkdir -p .android && touch .android/repositories.cfg + +# Set up Android SDK +RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip +RUN unzip sdk-tools.zip && rm sdk-tools.zip +RUN mv tools Android/sdk/tools +RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses +RUN cd Android/sdk/tools/bin && ./sdkmanager "build-tools;34.0.0" "platform-tools" "platforms;android-33" "sources;android-33" +ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools" + +# Record the exposed port +EXPOSE 8001 + +# make server startup script executable and start the web server +RUN ["chmod", "+x", "/app/server/server.sh"] + +ENTRYPOINT [ "/app/server/server.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1a7d52f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ + version: '4' + + services: + frontend: + build: + context: ./ + ports: + - "8001" \ No newline at end of file diff --git a/lib/home.dart b/lib/home.dart index 3f0e448..9801cd1 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -64,11 +64,12 @@ class _NotepadHomePageState extends State { }, child: const MouseRegion( cursor: SystemMouseCursors.click, - child: Text('Notease - v0.3 | 16 Maret 2024'), + child: Text('Notease - v0.3.2.1 | 18 Maret 2024'), ), ), backgroundColor: const Color.fromARGB(255, 227, 179, 235), actions: [ + IconButton( icon: const Icon(Icons.folder_open), onPressed: () async { diff --git a/server/server.sh b/server/server.sh new file mode 100644 index 0000000..fe8842a --- /dev/null +++ b/server/server.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Define the port +PORT=8001 + +# Check if the port is in use and release it if necessary. +echo "Checking if port $PORT is in use..." +if [ "$(lsof -t -i :$PORT)" ]; then + echo "Port $PORT is in use. Stopping the process on that port..." + fuser -k -n tcp $PORT +fi + +# Switch to the web construction directory +cd /app/build/web/ + +# Start the web server on the specified port +echo "Starting the server on port $PORT..." +python3 -m http.server $PORT \ No newline at end of file