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

Create LAMP CSAR #211

Merged
merged 53 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
555ed22
copy template.yaml from docker-example
JensMueller2709 Nov 14, 2017
c1a37d0
add first node types to template.yaml
JensMueller2709 Nov 14, 2017
95a1a05
add some db nodetypes
JensMueller2709 Nov 14, 2017
98e2945
add node_templates for LAMP and delete node_types
JensMueller2709 Nov 14, 2017
184e1d5
add php Interface to my_app node_template
JensMueller2709 Nov 15, 2017
1f85a7a
add scripts to install php and start myphpapp
JensMueller2709 Nov 15, 2017
c400ce3
add create_db script
JensMueller2709 Nov 15, 2017
c626eee
add scripts for dbms
JensMueller2709 Nov 15, 2017
1589402
add scripts for apache
JensMueller2709 Nov 15, 2017
c65bac1
Complete compute node
mmunozba Nov 15, 2017
4239e62
Refactor LAMP yaml template
mmunozba Nov 15, 2017
3197946
Add inputs/outputs to lamp template
mmunozba Nov 15, 2017
839e8e5
Fix inputs/outputs in LAMP template
mmunozba Nov 15, 2017
998f2f7
Add db_host to LAMP template
mmunozba Nov 15, 2017
c94f782
change Y to y in installscripts
JensMueller2709 Nov 16, 2017
7882540
Fix some bugs in shellscripts
JensMueller2709 Nov 16, 2017
34f2dc7
Change structure and template
JensMueller2709 Nov 16, 2017
0d940fe
Add missing package to apache_install_script
JensMueller2709 Nov 16, 2017
23741e4
Export mysql credentials and move php
JensMueller2709 Nov 16, 2017
dda0626
Delete old duplicate file
JensMueller2709 Nov 16, 2017
b8df471
Change LAMP-CSAR structure
mmunozba Nov 16, 2017
d28bae1
Add no-input LAMP-CSAR
mmunozba Nov 16, 2017
fe8130d
Add CSAR-files for LAMP CSARs
mmunozba Nov 16, 2017
0ce405c
include mysql-credentials
JensMueller2709 Nov 16, 2017
376fc80
Fix no-input LAMP-CSAR
mmunozba Nov 16, 2017
0191a5a
Change package install in one line
JensMueller2709 Nov 18, 2017
f8eb6ae
Delete duplicate folder and copy second template
JensMueller2709 Nov 18, 2017
1d3ba14
Add update&upgrade to install scripts
JensMueller2709 Nov 20, 2017
9685f1a
Exchange deprecated version of starting service
JensMueller2709 Nov 20, 2017
f259aea
Delete unnecessary .service
JensMueller2709 Nov 20, 2017
5a62c52
Update msql configure
JensMueller2709 Nov 20, 2017
5a83798
Create two seperate folders for input & NoInput
JensMueller2709 Nov 20, 2017
8f23b33
Use environment variables in script to enable input
JensMueller2709 Nov 20, 2017
62cacc2
Added input references and removed unnecessary references to concrete…
mklopp Nov 20, 2017
86c5d31
Deleted unnecessary files
JensMueller2709 Nov 20, 2017
05e9d5d
Changed output to full URL
mklopp Nov 20, 2017
0106724
Adapted no_input template to input template
mklopp Nov 20, 2017
ef9751e
Add missing variables
JensMueller2709 Nov 20, 2017
0db48a5
Delete unnecessary files
JensMueller2709 Nov 20, 2017
d758fca
Remove mysl_dbms_install.sh from no-input LAMP-CSAR
mmunozba Nov 21, 2017
4c77efe
Rename lamp-csar folders to use lower-case
mmunozba Nov 21, 2017
0284d0c
Rebuild LAMP-CSARs
mmunozba Nov 21, 2017
1ac9d53
Removed concat function and replaced it by two outputs
mklopp Nov 21, 2017
bf8e5b5
Added configure script and adapted template
mklopp Nov 21, 2017
e6102cc
Update input-csar
JensMueller2709 Nov 22, 2017
917a289
FIx issues regarding phpapp's lifecycle
Nov 23, 2017
a5419f3
Merge branch 'master' into resources/lamp-csar
c-mueller Nov 24, 2017
81af335
Adapted no input csar
mklopp Nov 26, 2017
77d3a15
Fixed indentation error and build csars
mklopp Nov 26, 2017
52912e4
Non-normative Types aren't supported by the winery-parser so changed …
mklopp Nov 26, 2017
83b3104
Revert NodeTypes to non-normative ones
Nov 27, 2017
9e01ffb
Unify test csars and provide zip script
Nov 28, 2017
e860c2a
Fix simple-task csar
Nov 28, 2017
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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
sudo apt-get install apache2 -y
sudo apt-get install libapache2-mod-php7.0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you have to add -y here too.

You could also consider concatenation of both commands like that:
sudo apt-get install -y apache2 libapache2-mod-php7.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo service apache2 start
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# install php on a linux machine with php-mysql
sudo apt-get install php -y
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as webserver_install.sh

sudo apt-get install php-mysql -y
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
// include the credentials to connect to the db
//include_once "mysql-credentials.php";

$db_host = "127.0.0.1";
$db_user = "root";
$db_password = "abc";
$db_name = "mydb";
$db_port = 3306;

// get task from post after task was entered in form
$post = $_POST['task'];
if ($post != "") {
saveToDb($post);
}
/**
* saved task to db
*/
function saveToDb($task)
{
$conn = newDbConnection();
$task = htmlspecialchars($task);
if (!$conn->query("INSERT INTO tasks(task) VALUES('".$task."')")) {
echo("Creating task failed");
}
$conn->close();
}
/**
* reads from db and prints it in html
*/
function readFromDb()
{
$sql = "select * from tasks";
$conn = newDbConnection();
$result = $conn->query($sql);
$conn->close();
if ($result->num_rows > 0) {
// output data for each row
while ($row = $result->fetch_assoc()) {
echo htmlspecialchars("id: " . $row['id']. " - Task: " . $row['task'])."<br>";
}
return;
}
echo "0 results";
}
/**
* generates new DB connection with given credentials
*/
function newDbConnection()
{
extract($GLOBALS);
$conn = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
return $conn;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SimpleTaskApp</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>SimpleTaskApp</h1>
<!-- form to enter tasks -->
<form class="insertTask" action="myphpapp.php" method="post">
<input type="text" name="task" />
<button type="submit" name="button">submit</button>
</form>
<?php
//print tasks out of the db
readFromDb();
?>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$db_host = "127.0.0.1";
$db_user = "root";
$db_password = "abc";
$db_name = "mydb";
$db_port = 3306;
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
sudo mv myphpapp.php /var/www/html/
sudo mv mysql-credentials.php /var/www/html/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Setup MySQL root password and create user
cat << EOF | mysql -u root --password=abc
CREATE DATABASE mydb;
USE mydb;
create table tasks (id INT not null auto_increment,task varchar(255), primary key(id));
EXIT
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo mysqladmin -u root -p password abc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# install mysql-server without password promt.
# insert a fix pw
echo "mysql-server mysql-server/root_password password abc" | sudo debconf-set-selections
echo "mysql-server mysql-server/root_password_again password abc" | sudo debconf-set-selections
sudo apt-get install mysql-server -y
sudo systemctl enable mysql.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo systemctl start mysql.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: Template for deploying a LAMP stack.
metadata:
template_name: lamp-stack-template
template_author: stupro-toscana
template_version: 1.0


topology_template:
node_templates:
my_app:
type: tosca.nodes.WebApplication
requirements:
- host: apache_web_server
- database_endpoint: my_db
interfaces:
Standard:
create: my_app/install_php.sh
start:
implementation:
primary: my_app/start_myphpapp.sh
dependencies:
- myphpapp.php
- mysql-credentials.php

apache_web_server:
type: tosca.nodes.WebServer.Apache
requirements:
- host: server
interfaces:
Standard:
create: apache_web_server/webserver_install.sh
start: apache_web_server/webserver_start.sh

my_db:
type: tosca.nodes.Database.MySQL
properties:
name: { mydb }
user: { root }
password: { abc }
port: { 3306 }
capabilities:
database_endpoint:
properties:
port: { 3306 }
requirements:
- host: mysql_dbms
interfaces:
Standard:
create: my_db/db_create.sh

mysql_dbms:
type: tosca.nodes.DBMS.MySQL
properties:
root_password: { abc }
port: { 3306 }
requirements:
- host: server
interfaces:
Standard:
create: mysql_dbms/mysql_dbms_install.sh
start: mysql_dbms/mysql_dbms_start.sh
configure: mysql_dbms/mysql_dbms_configure.sh

server:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 1
disk_size: 25 GB
mem_size: 2048 MB
os:
properties:
type: linux
distribution: ubuntu
version: 16.04
outputs:
endpoint:
description: endpoint of the php-app
value: { get_attribute: [ server, public_address ] }
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
sudo apt-get install apache2 -y
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Really dont like the idea of having duplicate code here, maybe consider putting both variants in the same directory. Just change the name of the yaml file (assuming nothing else has changed)

sudo apt-get install libapache2-mod-php7.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo service apache2 start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service is deprecated; use sudo systemctl start apache2 instead

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# install php on a linux machine with php-mysql
sudo apt-get install php -y
sudo apt-get install php-mysql -y
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
// include the credentials to connect to the db
include_once "mysql-credentials.php";

// get task from post after task was entered in form
$post = $_POST['task'];
if ($post != "") {
saveToDb($post);
}
/**
* saved task to db
*/
function saveToDb($task)
{
$conn = newDbConnection();
$task = htmlspecialchars($task);
if (!$conn->query("INSERT INTO tasks(task) VALUES('".$task."')")) {
echo("Creating task failed");
}
$conn->close();
}
/**
* reads from db and prints it in html
*/
function readFromDb()
{
$sql = "select * from tasks";
$conn = newDbConnection();
$result = $conn->query($sql);
$conn->close();
if ($result->num_rows > 0) {
// output data for each row
while ($row = $result->fetch_assoc()) {
echo htmlspecialchars("id: " . $row['id']. " - Task: " . $row['task'])."<br>";
}
return;
}
echo "0 results";
}
/**
* generates new DB connection with given credentials
*/
function newDbConnection()
{
extract($GLOBALS);
$conn = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
return $conn;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SimpleTaskApp</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>SimpleTaskApp</h1>
<!-- form to enter tasks -->
<form class="insertTask" action="myphpapp.php" method="post">
<input type="text" name="task" />
<button type="submit" name="button">submit</button>
</form>
<?php
//print tasks out of the db
readFromDb();
?>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$db_host = "127.0.0.1";
$db_user = "root";
$db_password = "abc";
$db_name = "mydb";
$db_port = 3306;
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
sudo mv myphpapp.php /var/www/html/
sudo mv mysql-credentials.php /var/www/html/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Setup MySQL root password and create user
cat << EOF | mysql -u root --password=abc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use root pw from template

CREATE DATABASE mydb;
USE mydb;
create table tasks (id INT not null auto_increment,task varchar(255), primary key(id));
EXIT
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo mysqladmin -u root -p password db_root_password
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly do you intend to do here? AFAIK valid syntax would be:

sudo mysqladmin -u root -p $db_root_password

now you started the mysqladmin shell, but what now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this command you could change your root pw

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i looked it up. correct syntax would be:
sudo mysqladmin -u root password $db_root_password

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# install mysql-server without password promt.
# insert a fix pw
echo "mysql-server mysql-server/root_password password abc" | sudo debconf-set-selections
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use the my_mysql_rootpwd from the template?

echo "mysql-server mysql-server/root_password_again password abc" | sudo debconf-set-selections
sudo apt-get install mysql-server -y
sudo systemctl enable mysql.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo systemctl start mysql.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, when using sytemctl it's always save to drop the .service, because systemctl defaults to .service.

Loading