Skip to content

Commit

Permalink
Merge branch 'main' into feature/336-allow-student-prototype-to-accep…
Browse files Browse the repository at this point in the history
…t-folders
  • Loading branch information
lucsomers101 committed Feb 1, 2024
2 parents ceacc53 + cf082c2 commit c6cc493
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/triggerDocsUpdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches:
- main
- documentation
paths:
- "docs/**"

Expand Down
2 changes: 1 addition & 1 deletion RAP4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This script is meant to build from the root directory of your RAP-repo.
# Ampersand compiler is also needed for RAP4 to compile student scripts

FROM ampersandtarski/prototype-framework:main
FROM ampersandtarski/prototype-framework:v1.17.0
# this prototype-framework builds on an Apache server

# Install docker, so students can run their prototypes
Expand Down
25 changes: 15 additions & 10 deletions RAP4/customizations/bootstrap/files/ExecEngineFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@
$zipContentForCommandline = base64_encode($zipContent);
$mainAldForCommandLine = base64_encode("main.adl");

$pattern = '/[\W+]/';

$userName=strtolower($userName);
$userName = preg_replace($pattern, '-', $userName);

$deployment = getenv('RAP_DEPLOYMENT');
if ($deployment == 'Kubernetes') {
/** Deployed on Kubernetes Cluster
Expand All @@ -354,24 +359,19 @@
* - run kubectl apply -f "student-manifest-{{student}}.yaml"
*/

$pattern = '/[\W+]/';

$studentName=strtolower($userName);
$studentName = preg_replace($pattern, '-', $studentName);

$namespace=getenv('RAP_KUBERNETES_NAMESPACE');
$containerImage=getenv('RAP_STUDENT_PROTO_IMAGE');

$hostname=getenv('RAP_HOST_NAME');
$hostname="{$studentName}.{$hostname}";
$hostname="{$userName}.{$hostname}";

$suffix=substr($namespace, 3);

$dbName="rap-db{$suffix}";

$dbSecret="db-secrets{$suffix}";

$tlsSecret="{$studentName}-tls{$suffix}";
$tlsSecret="{$userName}-tls{$suffix}";

// Location to save files
$manifestFile = $ee->getApp()->getSettings()->get('global.absolutePath') . '/bootstrap/files/student-manifest-template.yaml';
Expand All @@ -382,7 +382,7 @@
throw new Exception("Student manifest template not found for '{$scriptVersionAtom}', workDir: {$workDir}, manifestFile: {$manifestFile}", 500);
}
// replace {{student}}, {{namespace}} and {{scriptContent}}
$manifest=str_replace("{{student}}", $studentName, $manifest);
$manifest=str_replace("{{student}}", $userName, $manifest);
$manifest=str_replace("{{namespace}}", $namespace, $manifest);
$manifest=str_replace("{{containerImage}}", $containerImage, $manifest);
// $manifest=str_replace("{{scriptContent}}", $scriptContentForCommandline, $manifest);
Expand All @@ -394,7 +394,7 @@
$manifest=str_replace("{{mainAdl}}", $mainAldForCommandLine, $manifest);

// Save manifest file
$studentManifestFile="{$workDir}/student-manifest-{$studentName}.yaml";
$studentManifestFile="{$workDir}/student-manifest-{$userName}.yaml";
file_put_contents($studentManifestFile, $manifest);

// Call Kubernetes API to add script
Expand Down Expand Up @@ -426,6 +426,7 @@
[ "--name \"{$userName}\"",
"--rm", # deletes the container when it is stopped. Useful to prevent container disk space usage to explode.
"-i",
"-p 8000:80",
"-a stdin", // stdin ensures that the content of the script is available in the container.
"--network proxy", // the reverse proxy Traefik is in the proxy network
"--label traefik.enable=true", // label for Traefik to route trafic
Expand All @@ -447,7 +448,11 @@
$command->execute();

// Add docker container also to rap_db network
$command2 = new Command("docker network connect rap_db {$userName}", null, $ee->getLogger());
$command2 = new Command(
"docker network connect rap_db {$userName}",
[],
$ee->getLogger()
);
$command2->execute();
}

Expand Down
4 changes: 2 additions & 2 deletions RAP4/customizations/extensions/RAP4/src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Command
*
* @var string[]
*/
protected $args;
protected array $args;

/**
* Exit code returned after execution of command
Expand All @@ -39,7 +39,7 @@ class Command
*/
protected $logger = null;

public function __construct(string $cmd, array $args = null, LoggerInterface $logger = null)
public function __construct(string $cmd, array $args = [], LoggerInterface $logger = null)
{
$this->cmd = $cmd;
$this->args = $args;
Expand Down
2 changes: 1 addition & 1 deletion RAP4USER/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ampersandtarski/prototype-framework:main
FROM ampersandtarski/prototype-framework:v1.17.0

RUN apt-get update \
&& apt-get install -y \
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services:
context: RAP4USER

rap4:
image: ampersandtarski/ampersand-rap:latest
image: ampersandtarski/ampersand-rap:dev-latest
container_name: rap4
build:
context: RAP4
Expand All @@ -61,7 +61,7 @@ services:
- AMPERSAND_DBNAME=rap4
- AMPERSAND_SERVER_URL=https://${SERVER_HOST_NAME} # from .env file
- RAP_HOST_NAME=${SERVER_HOST_NAME}
- RAP_STUDENT_PROTO_IMAGE=ampersandtarski/rap4-student-prototype:v1.1.1
- RAP_STUDENT_PROTO_IMAGE=ampersandtarski/rap4-student-prototype:dev-latest
- RAP_STUDENT_PROTO_LOG_CONFIG=logging.yaml
- APACHE_RUN_DIR=/var/www
volumes:
Expand Down

0 comments on commit c6cc493

Please sign in to comment.