Skip to content

Commit

Permalink
Merge pull request #22 from SAM-IT/make-runtime-configurable
Browse files Browse the repository at this point in the history
feat: make env json file path configurable
  • Loading branch information
SamMousa authored Apr 26, 2024
2 parents 7f5db0d + 87b3a0c commit 9379ed1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continous integration
name: Continuous integration
on:
pull_request:
push:
Expand Down Expand Up @@ -34,10 +34,10 @@ jobs:
needs: [test, cs]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 21
- run: >
npx
-p "@semantic-release/commit-analyzer"
Expand Down
27 changes: 5 additions & 22 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ final class Module extends \yii\base\Module
'post_max_size' => '25M'
];

public string $envJsonFile = '/runtime/env.json';

/**
* @var array<string, string> $fpmConfig Global directives
* @see http://php.net/manual/en/install.fpm.configuration.php
Expand Down Expand Up @@ -105,28 +107,11 @@ private function createEntrypoint(string $entryScript): string
$result = [];
$result[] = '#!/bin/sh';

// Check if runtime directory is writable.
$result[] = <<<SH
su nobody -s /bin/touch /runtime/testfile && rm /runtime/testfile;
if [ $? -ne 0 ]; then
echo Runtime directory is not writable;
exit 1
fi
SH;

// Check if runtime is a tmpfs.
$message = Console::ansiFormat('/runtime should really be a tmpfs.', [Console::FG_RED]);
$result[] = <<<SH
grep 'tmpfs /runtime' /proc/mounts;
if [ $? -ne 0 ]; then
echo $message;
fi
SH;
$result[] = <<<SH
su nobody -s /bin/touch /runtime/env.json
jq -n -s 'env' > /runtime/env.json
su nobody -s /bin/touch {$this->envJsonFile}
jq -n -s 'env' > {$this->envJsonFile}
if [ $? -ne 0 ]; then
echo "failed to store env in /runtime/env.json";
echo "failed to store env in {$this->envJsonFile}";
exit 1
fi
SH;
Expand Down Expand Up @@ -174,8 +159,6 @@ public function createBuildContext(

$context->from($this->baseImage);
$context->run('apk add --update --no-cache jq');
$context->run('mkdir -p /runtime && chown nobody:nobody /runtime');
$context->volume('/runtime');
$context->copyFromLayer("/project", "0", "/build");

$context->add('/entrypoint.sh', $this->createEntrypoint($entryScript));
Expand Down

0 comments on commit 9379ed1

Please sign in to comment.