Skip to content

Commit

Permalink
Add swapfile for docker memory
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorosploumis committed Nov 14, 2017
1 parent b6abd1f commit 76242c3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 51 deletions.
35 changes: 13 additions & 22 deletions html/faaast.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

if (isset($_GET['compress'])) {
$compress_method = $_GET['compress'];
}
else {
} else {
$compress_method = "tar.gz";
}

Expand Down Expand Up @@ -51,8 +50,7 @@
echo "API=" . $api;
echo $debug_message;
exit();
}
else {
} else {
jsonResult(TRUE, $debug_message);
}
}
Expand Down Expand Up @@ -176,16 +174,15 @@
if ($api == 0) {
echo $debug_message;
exit();
}
else {
} else {
jsonResult(TRUE, $debug_message);
exit();
}
}

// Capture command output on a file and append the command
$cmd_main = $cmd . " > /error/" . $error_filename . " 2>&1";

// $cmd_exit = "$(if [ $(du -shb /home | awk '{print $1}') -lt 8000 ]; then exit; fi)"; // 8000 bytes
// $cmd_exit = "$(if [ (echo $?) != 0 ]; then exit; fi)";

Expand All @@ -196,8 +193,7 @@

if ($compress_method == "tar.gz") {
$cmd_compress = " tar -zcvf /downloads/" . $filename . " *";
}
else {
} else {
$cmd_compress = " zip -r /downloads/" . $filename . " *";
}
$cmd_chown_compressed = " chown -R www-data:www-data /downloads/ && chown -R www-data:www-data /error/ ";
Expand All @@ -216,8 +212,7 @@
if ($api == 0) {
echo $debug_message;
exit();
}
else {
} else {
jsonResult(TRUE, $debug_message);
}
}
Expand All @@ -227,8 +222,7 @@
if ($api == 0) {
print simpleHtml("An error occured", fileWithLines($error_initial_file_path, "<br>"));
exit();
}
else {
} else {
jsonResult(TRUE, fileWithLines($error_initial_file_path));
exit();
}
Expand All @@ -246,20 +240,19 @@
//downloadFile($compressed_path);
redirectTo($compressed_url);
exit();
}
else {
} else {
jsonResult(FALSE, "File exists", $compressed_url);
exit();
}
}
else {
} else {
if ($error == FALSE) {
if (!file_exists($current_build_folder)) {
mkdir($current_build_folder, 0777);
}

// Run docker and create the file if not exist
$volumes = $cache . " -v " . $current_build_folder . ":/downloads ";
$volumes = $cache;
$volumes .= " -v " . $current_build_folder . ":/downloads ";

// Error log etc
$error_volumes = " -v " . $current_error_folder . ":/error ";
Expand All @@ -279,8 +272,7 @@
//downloadFile($initial_compressed_path);
redirectTo($compressed_url);
exit();
}
else {
} else {
jsonResult(FALSE, "File exists", $compressed_url);
exit();
}
Expand All @@ -294,8 +286,7 @@
sleep(10);
rmdirRecursive($current_build_folder);
exit();
}
else {
} else {
jsonResult(TRUE, fileWithLines($error_initial_file_path));
sleep(10);
rmdirRecursive($current_build_folder);
Expand Down
65 changes: 37 additions & 28 deletions html/faqs.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@
<h2>About</h2>

<p>
Faaast is a package manager as a service (SaaS). Faaaster than your local machine!
Faaast is a package manager as a service (SaaS). Faaaster than your
local machine!
</p>

<p>
Instead of using your local machine to build software from repositories you can use Faaast.
Instead of using your local machine to build software from
repositories you can use Faaast.
</p>
</section>

<section class="faq">
<h2>What package managers are supported?</h2>

<p> Currently we support only these "package managers":<br>

<b>
<a href="https://www.npmjs.com/">npm</a>,
<a href="https://yarnpkg.com/">yarn</a>,
Expand All @@ -53,7 +55,7 @@
</b>.

</p>
The commands that are currently allowed are:
The commands that are currently allowed are:
<p>
<small>
- composer install/create-project<br>
Expand All @@ -62,7 +64,7 @@
- ied install<br>
- npm install/add<br>
- pnpm install<br>
- pip install<br>
- pip/pip3 install<br>
- yarn add<br>
</small>
</p>
Expand All @@ -77,9 +79,11 @@
<h2>Why use it?</h2>

<ul>
<li>Because sometimes there unknown errors with package managers.</li>
<li>Because sometimes there unknown errors with package managers.
</li>
<li>Because WiFi issues may corrupt packaging.</li>
<li>Because sometimes you don't want to spend time for packaging.</li>
<li>Because sometimes you don't want to spend time for packaging.
</li>
<li>Because not every machine can use package managers.</li>
<li>To experiment with package managers.</li>
<li>Because Docker can do this!</li>
Expand All @@ -90,31 +94,33 @@
<h2>Which is the software behind this?</h2>

<p>
I have built this tool as a proof of concept of a simple SaaS based on <b>Docker</b> and <b>php</b>.
I have built this tool as a proof of concept of a simple SaaS based
on <b>Docker</b> and <b>php</b>.
</p>

<p>
Everytime you use a package command you run a public
<a href="https://hub.docker.com/r/tplcom/faaast">Docker image</a> that contains:
<a href="https://hub.docker.com/r/tplcom/faaast">Docker image</a>
that contains:
</p>

<p>
<small>
- bundler 1.16.0<br>
- composer 1.5.2<br>
- drush 8.1.15<br>
- gem 2.5.1<br>
- ied 2.3.6<br>
- node v8.9.1<br>
- npm 5.5.1<br>
- pnpm 1.20.0<br>
- python 2.7.12<br>
- python3 3.5.2<br>
- pip 9.0.1<br>
- pip3 9.0.1<br>
- php 7.0.22<br>
- ruby 2.3.1p112<br>
- yarn 1.3.2<br>
- bundler 1.16.0<br>
- composer 1.5.2<br>
- drush 8.1.15<br>
- gem 2.5.1<br>
- ied 2.3.6<br>
- node v8.9.1<br>
- npm 5.5.1<br>
- pnpm 1.20.0<br>
- python 2.7.12<br>
- python3 3.5.2<br>
- pip 9.0.1<br>
- pip3 9.0.1<br>
- php 7.0.22<br>
- ruby 2.3.1p112<br>
- yarn 1.3.2<br>
</small>
</p>
</section>
Expand All @@ -127,16 +133,19 @@
</p>

<p>
A <a href="https://www.drupal.org/u/theodorosploumis">Drupal developer</a>
with devops skills. See <a href="https://theodorosploumis.github.io/portfolio/">my work here</a>.
A <a href="https://www.drupal.org/u/theodorosploumis">Drupal
developer</a>
with devops skills. See <a
href="https://theodorosploumis.github.io/portfolio/">my work
here</a>.
</p>
</section>

</section>

<footer>
<p>
<?php print footerMessage(); ?>
<?php print footerMessage(); ?>
</p>
</footer>

Expand Down
2 changes: 1 addition & 1 deletion scripts/faaast
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ URL="https://faaast.download/faaast.php?cmd=${COMMAND// /+}&id=${ID}&api=1"
ERROR_URL="https://faaast.download/faaast.php?cmd=${COMMAND// /+}&id=${ID}&error=true"

echo -e "Posting to ${URL}";
echo -e "";
echo -e "please wait...";

FILE=$(curl -s "$URL" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'file'"]';)

Expand Down
13 changes: 13 additions & 0 deletions scripts/server-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ apt-get autoremove

service apache2 reload

# Add swap file
# See more here: https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
cp /etc/fstab /etc/fstab.bak
echo "/swapfile none swap sw 0 0" | tee -a /etc/fstab
echo "vm.swappiness=10 " >> /etc/sysctl.conf
echo "vm.vfs_cache_pressure=50 " >> /etc/sysctl.conf
sysctl vm.swappiness=10
sysctl vm.vfs_cache_pressure=50

# Manually actions
# Set timezone
echo -n "Run: dpkg-reconfigure tzdata"

0 comments on commit 76242c3

Please sign in to comment.