Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Unable to build & release to the Heroku #14

Open
wants to merge 30 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.git/
.git/
/.idea
78 changes: 35 additions & 43 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,32 @@ function export_env_dir() {
function indent() {
sed -u 's/^/ /'
}

BUILD_DIR=${1:-}
CACHE_DIR=${2:-}

export_env_dir "$3"

# Create the cache directory if not exist.
mkdir -p $CACHE_DIR
if [ -n "$FLUTTER_BUILD_DIR" ]; then
APP_DIR=$BUILD_DIR/$FLUTTER_BUILD_DIR
else
APP_DIR=$BUILD_DIR
fi
cd "$APP_DIR"

cd $BUILD_DIR

if [ -d $CACHE_DIR/flutter ]; then
if [ -d "$CACHE_DIR/flutter" ]; then
print "Restoring Flutter SDK from CACHE"
cp -R $CACHE_DIR/flutter $BUILD_DIR
cp -R $CACHE_DIR/flutter $APP_DIR
else
print "Installing SDK from Github repository."
git clone https://github.com/flutter/flutter.git --quiet
git clone https://github.com/flutter/flutter.git --branch $FLUTTER_VERSION --quiet --single-branch | indent
fi

# Check if FLUTTER_VERSION variables is set.
if [ -n "$FLUTTER_VERSION" ]; then
# Load bash variables from flutter --machine --version and read it like $FLUTTER_VERSION variable.
flutter/bin/flutter --machine --version >flutter.json
FLUTTER_INSTALLED_VERSION=$(grep -o '"frameworkVersion": *"[^"]*' flutter.json | grep -o '[^"]*$')

# Check if the FLUTTER_VERSION is the same with the installed one.
if [ "$FLUTTER_VERSION" != "$FLUTTER_INSTALLED_VERSION" ]; then
print "Installing Flutter SDK version : $FLUTTER_VERSION"
flutter/bin/flutter version $FLUTTER_VERSION --quiet | indent
fi
rm flutter.json

else

print "Running flutter upgrade command"
if [ $channel != "beta" ]; then
flutter/bin/flutter channel beta | indent
fi

flutter/bin/flutter upgrade --quiet | indent
if [ -n "$FLUTTER_ENV_FILE" ]; then
print "Generate .env file"
touch .env
echo $FLUTTER_ENV_FILE | base64 --decode > .env
fi

print "Enabling Web support"
Expand All @@ -74,7 +60,7 @@ print "Running flutter clean command."
flutter/bin/flutter clean --quiet | indent

print "Getting packages from Flutter project"
flutter/bin/flutter pub get --quiet | indent
flutter/bin/flutter pub get | indent

PATH="$PATH":"$(pwd)/flutter/bin/"

Expand All @@ -92,9 +78,9 @@ mkdir -p $PUB_CACHE
if [ -x flutter/bin/flutter ]; then
print "Saving Flutter SDK in Cache"
rm -rf $CACHE_DIR/flutter
cp -R $BUILD_DIR/flutter $CACHE_DIR/flutter
mv $BUILD_DIR/flutter/bin/cache/dart-sdk/ $BUILD_DIR
rm -rf $BUILD_DIR/flutter
cp -R $APP_DIR/flutter $CACHE_DIR/flutter
mv $APP_DIR/flutter/bin/cache/dart-sdk/ $APP_DIR
rm -rf $APP_DIR/flutter
fi

# To read hidden directories and use move with exclusion.
Expand All @@ -103,11 +89,11 @@ shopt -s extglob
# Check FLUTTER_CLEANUP var to delete all files or keep it.
if [ "$FLUTTER_CLEANUP" != false ]; then

mkdir -p $BUILD_DIR/TO_DELETE
mkdir -p $APP_DIR/TO_DELETE

mv !("TO_DELETE") TO_DELETE
mv TO_DELETE/build/web/* $BUILD_DIR
mv TO_DELETE/dart-sdk $BUILD_DIR
mv TO_DELETE/build/web/* $APP_DIR
mv TO_DELETE/dart-sdk $APP_DIR
rm -rf TO_DELETE

fi
Expand All @@ -116,21 +102,27 @@ fi
# Is taken from my Github repo because some variables need to be changed every run
# like PORT from environment.

if [ -d "$CACHE_DIR/.pub-cache/" ]; then
print "dhttpd Found in cache. Restoring."
cp -R $CACHE_DIR/.pub-cache/* $PUB_CACHE
else
#if [ -d "$CACHE_DIR/.pub-cache/" ]; then
# print "dhttpd Found in cache. Restoring."
# cp -R $CACHE_DIR/.pub-cache/* $PUB_CACHE
#else
print "Getting dhttpd to run web service."
$BUILD_DIR/dart-sdk/bin/dart pub global activate -sgit https://github.com/diezep/dhttpd.git | indent
$APP_DIR/dart-sdk/bin/dart pub global activate dhttpd | indent

print "Getting dhtppd to run web service."
mkdir -p $CACHE_DIR/.pub-cache/
cp -R $PUB_CACHE/* $CACHE_DIR/.pub-cache/
fi
#fi

# Moving to the build, after running the compile. All will be deleted and removed to app directory.
# Copying the result, the files will be kept in storage.
cp -R $PUB_CACHE $BUILD_DIR
cp -R $PUB_CACHE $APP_DIR

if [ -n "$FLUTTER_DEPLOY_DIR" ]; then
cp -r "$APP_DIR" "$BUILD_DIR/$FLUTTER_DEPLOY_DIR"
fi

du -h -d 2 | sort -n

export PATH="$PATH":"/app/dart-sdk/bin/"
export PATH="$PATH":"/app/.pub-cache/bin"
export PATH="$PATH":"/$APP_DIR/dart-sdk/bin/"
export PATH="$PATH":"/$APP_DIR/.pub-cache/bin"
15 changes: 10 additions & 5 deletions bin/release
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/bin/sh

BUILD_DIR=${1:-}
# If the FLUTTER_CLEANUP is in false, or in true.
if [ -d $BUILD_DIR/build/web ]; then
DEPLOY_DIR="/app/build/web/"
if [ -n "$FLUTTER_DEPLOY_DIR" ]; then
DEPLOY_DIR="$FLUTTER_DEPLOY_DIR"
else
DEPLOY_DIR="/app/"

# If the FLUTTER_CLEANUP is in false, or in true.
if [ -d $BUILD_DIR/build/web ]; then
DEPLOY_DIR="/app/build/web/"
else
DEPLOY_DIR="/app/"
fi
fi

cat <<EOF
---
default_process_types:
web: /app/dart-sdk/bin/dart pub global run dhttpd --host 0.0.0.0 --path ${DEPLOY_DIR}
web: /app/dart-sdk/bin/dart pub global run dhttpd --host=0.0.0.0 --path=${DEPLOY_DIR} --port=\$PORT

EOF