Skip to content

Commit

Permalink
dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
lodberg1999 committed Nov 22, 2023
1 parent 901ee2d commit 4fb0213
Showing 1 changed file with 61 additions and 28 deletions.
89 changes: 61 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,79 @@
# Brug det officielle Flutter-billede
# Docker image for building Flutter app for Android and iOS
FROM ubuntu:latest

# Installer nødvendige afhængigheder
# Set the environment variables
ENV ANDROID_HOME="/opt/android-sdk"
ENV PATH="$PATH:$ANDROID_HOME/tools"
ENV FLUTTER_HOME="/flutter"
ENV PATH="$PATH:$FLUTTER_HOME/bin"

# Update and install necessary tools
RUN apt-get update && \
apt-get install -y curl git unzip xz-utils openjdk-11-jdk && \
apt-get install -y curl git unzip xz-utils openjdk-11-jdk libxml2-utils sudo && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Installer Flutter SDK
RUN git clone https://github.com/flutter/flutter.git /flutter
ENV PATH="/flutter/bin:${PATH}"

# Sørg for, at Flutter er opdateret
RUN flutter upgrade
# Clone Flutter repository
RUN git clone https://github.com/flutter/flutter.git $FLUTTER_HOME

# Installer Android SDK
RUN mkdir -p /opt/android-sdk && \
curl -L https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -o /tmp/android-sdk.zip && \
unzip -qq /tmp/android-sdk.zip -d /opt/android-sdk && \
rm -f /tmp/android-sdk.zip
# Upgrade Flutter
RUN $FLUTTER_HOME/bin/flutter upgrade

# Konfigurer Android SDK-miljøvariabler
ENV ANDROID_HOME /opt/android-sdk
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
# Download and extract Android SDK
RUN mkdir -p $ANDROID_HOME && \
curl -L https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip -o /tmp/android-sdk.zip && \
unzip /tmp/android-sdk.zip -d $ANDROID_HOME && \
rm /tmp/android-sdk.zip

# Accepter licensaftaler
RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses
# Accept Android SDK licenses
RUN mkdir -p $ANDROID_HOME/licenses/ && \
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME/licenses/android-sdk-license && \
yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses

# Sæt arbejdsområdet til /app
# Set working directory to /app
WORKDIR /app

# Kopier pubspec-filerne for at cache afhængigheder
COPY pubspec.yaml pubspec.lock /app/
# Add a non-root user
RUN groupadd -r nonroot && useradd -r -g nonroot -m nonroot

# Installer appafhængigheder
RUN flutter pub get
# Change ownership of the Flutter directory
RUN chown -R nonroot:nonroot /flutter

# Kopier resten af appen til arbejdsområdet
# Copy the rest of the application code to the container
COPY . /app/

# Byg Flutter-appen
# Change ownership of necessary directories
RUN chown -R nonroot:nonroot /app/
# Switch to the nonroot user
USER nonroot

# Get Flutter dependencies
RUN flutter pub get

# Check for outdated dependencies
RUN flutter pub outdated

USER root
# Fix permissions for .flutter-plugins-dependencies
RUN sudo chown -R nonroot:nonroot /app/.flutter-plugins-dependencies



# Sæt miljøvariablen for Android SDK# Sæt miljøvariablen for Android SDK
ENV ANDROID_SDK_ROOT="/opt/android-sdk"

# Opret mappen til Android SDK og tildel rettigheder
RUN mkdir -p $ANDROID_SDK_ROOT && \
chown -R nonroot:nonroot $ANDROID_SDK_ROOT

# Installer de påkrævede Android SDK-komponenter
RUN yes | /opt/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT --licenses
RUN /opt/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT "platforms;android-31" "build-tools;30.0.3"

USER nonroot

# Build Flutter app for release
RUN flutter build apk --release

# Eksekverbar kommando
CMD ["flutter", "run", "--release"]
# Build iOS app for release
RUN flutter build ios --release

0 comments on commit 4fb0213

Please sign in to comment.