This commit is contained in:
Kekskurse 2019-09-26 16:06:03 +02:00
parent ea6d0eea7c
commit 4d4c6dbaa3
26 changed files with 400 additions and 31 deletions

View file

@ -16,4 +16,4 @@ DB_USERNAME=dev
DB_PASSWORD=dev DB_PASSWORD=dev
CACHE_DRIVER=file CACHE_DRIVER=file
QUEUE_CONNECTION=sync QUEUE_CONNECTION=mysql

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}

View file

@ -1,9 +1,17 @@
version: '3.2' version: '3.2'
services: services:
queueworker:
build:
context: ./
dockerfile: resources/docker/Dockerfile-queueworker
volumes:
- ./:/app
links:
- mariadb
php: php:
build: build:
context: ./ context: ./
dockerfile: docker/Dockerfile-fpm dockerfile: resources/docker/Dockerfile-fpm
volumes: volumes:
- ./:/app - ./:/app
links: links:
@ -11,10 +19,10 @@ services:
nginx: nginx:
build: build:
context: ./ context: ./
dockerfile: docker/Dockerfile-nginx dockerfile: resources/docker/Dockerfile-nginx
volumes: volumes:
- ./:/app - ./:/app
- ./docker/nginx.conf:/etc/nginx/conf.d/default.conf - ./resources/docker/nginx.conf:/etc/nginx/conf.d/default.conf
ports: ports:
- 8083:80 - 8083:80
links: links:

View file

@ -1,4 +0,0 @@
FROM nginx:1.15.12-alpine
COPY ./ /app
COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf

17
resources/build/manual.sh Executable file
View file

@ -0,0 +1,17 @@
cd ../../
rm -r -f storage/logs/l*
chmod uog+rwx storage/logs
rm -r -f vendor
composer install --no-dev
docker build -t docker.keks.cloud/sampleapp/nginx:latest -f resources/docker/Dockerfile-nginx .
docker build -t docker.keks.cloud/sampleapp/fpm:latest -f resources/docker/Dockerfile-fpm .
docker build -t docker.keks.cloud/sampleapp/queueworker:latest -f resources/docker/Dockerfile-queueworker .
docker push docker.keks.cloud/sampleapp/nginx:latest
docker push docker.keks.cloud/sampleapp/fpm:latest
docker push docker.keks.cloud/sampleapp/queueworker:latest
rm -r -f vendor
composer install
cd resources/build

View file

@ -5,4 +5,4 @@ WORKDIR /app
COPY ./ /app COPY ./ /app
CMD ["sh", "/app/docker/start-fpm.sh"] CMD ["sh", "/app/resources/docker/start-fpm.sh"]

View file

@ -0,0 +1,4 @@
FROM nginx:1.15.12-alpine
COPY ./ /app
COPY ./resources/docker/nginx-kube.conf /etc/nginx/conf.d/default.conf

View file

@ -0,0 +1,8 @@
FROM php:7.3.5-cli-alpine3.9
RUN docker-php-ext-install pdo pdo_mysql
WORKDIR /app
COPY ./ /app
CMD ["sh", "/app/resources/docker/start-queueworker.sh"]

View file

@ -0,0 +1,21 @@
server {
index index.php index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

View file

@ -0,0 +1,9 @@
cd /app
until nc -z -v -w30 mariadb 3306
do
echo "Waiting for database connection..."
# wait for 5 seconds before check again
sleep 5
done
sleep 5
php /app/artisan queue:work

View file

@ -0,0 +1,19 @@
apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate
metadata:
name: sample.app.keks.cloud
namespace: sampleapp
spec:
secretName: sample-app-keks-cloud-tls
acme:
config:
- dns01:
provider: cf-dns
domains:
- 'sample.app.keks.cloud'
commonName: 'sample.app.keks.cloud'
dnsNames:
- sample.app.keks.cloud
issuerRef:
kind: ClusterIssuer
name: letsencrypt-prod

View file

@ -0,0 +1,17 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: env-app
namespace: sampleapp
data:
APP_DEBUG: "false"
DB_CONNECTION: "mysql"
DB_HOST: "mysql"
DB_PORT: "3306"
DB_PORT: "oauth"
DB_USERNAME: "oauth"
DB_PASSWORD: "oauth"
QUEUE_CONNECTION: "mysql"
APP_TIMEZONE: "UTC"
APP_KEY: "abc"
APP_URL: "https://sample.app.keks.cloud"

View file

@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: env-mysql-backup
namespace: sampleapp
data:
MYSQL_HOST: "mariadb"
MYSQL_PORT: "3306"
PROJEKT_NAME: "sampleapp"
MYSQL_USER: "root"
MYSQL_PASSWORD: "example"

View file

@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: env-mysql
namespace: sampleapp
data:
MYSQL_USER: "dev"
MYSQL_PASSWORD: "dev"
MYSQL_DATABASE: "dev"
MYSQL_ROOT_PASSWORD: "example"

View file

@ -0,0 +1,20 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: mysql-backup
namespace: sampleapp
spec:
schedule: "10 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: mysql-backup
image: docker.keks.cloud/backup/mysql:latest
envFrom:
- configMapRef:
name: env-mysql-backup
restartPolicy: OnFailure
imagePullSecrets:
- name: docker-keks-cloud

View file

@ -0,0 +1,27 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mariadb
namespace: sampleapp
spec:
replicas: 1
template:
metadata:
labels:
app: mariadb
spec:
containers:
- name: mariadb
image: mariadb:10.4.4
ports:
- containerPort: 3306
envFrom:
- configMapRef:
name: env-mysql
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql
volumes:
- name: mysql
persistentVolumeClaim:
claimName: mysql

View file

@ -0,0 +1,20 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: queueworker
namespace: sampleapp
spec:
replicas: 2
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: php
image: docker.keks.cloud/sampleapp/queueworker:latest
envFrom:
- configMapRef:
name: env-app
imagePullSecrets:
- name: docker-keks-cloud

View file

@ -0,0 +1,26 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp
namespace: sampleapp
spec:
replicas: 2
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: php
image: docker.keks.cloud/sampleapp/fpm:latest
ports:
- containerPort: 9000
envFrom:
- configMapRef:
name: env-app
- name: nginx
image: docker.keks.cloud/sampleapp/nginx:latest
ports:
- containerPort: 80
imagePullSecrets:
- name: docker-keks-cloud

View file

@ -0,0 +1,16 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: webapp
namespace: sampleapp
spec:
rules:
- host: sample.app.keks.cloud
http:
paths:
- backend:
serviceName: service-webapp
servicePort: 80
path: /
tls:
- secretName: sample-app-keks-cloud-tls

View file

@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: sampleapp

View file

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
annotations:
field.cattle.io/targetWorkloadIds: '["deployment:sampleapp:mariadb"]'
name: mariadb
namespace: sampleapp
spec:
ports:
- port: 3306
protocol: TCP
targetPort: 3306
type: ClusterIP
status:
loadBalancer: {}

View file

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
annotations:
field.cattle.io/targetWorkloadIds: '["deployment:sampleapp:webapp"]'
name: service-webapp
namespace: sampleapp
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
type: ClusterIP
status:
loadBalancer: {}

View file

@ -6,8 +6,9 @@
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" crossorigin="anonymous"></script>
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4"> <div class="container" style="margin-top: 30px;">
<a class="navbar-brand" href="#">Top navbar</a> <nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4">
<a class="navbar-brand" href="#">Lumen Example</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
@ -17,17 +18,51 @@
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#">Link</a> <a class="nav-link" href="https://www.keks.cloud">keks.cloud</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li> </li>
</ul> </ul>
<form class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div> </div>
</nav> </nav>
<div class="row">
<div class="col-md-12">
<h1>Lumen Example</h1>
This is a lumen sample app with docker and kubernetes config to run in the keks.cloud. It can be used to create small webguis or even better api endpoints. It contains the following content:<br><br>
<ul>
<li>Lumen Project</li>
<li>Config for Lumen queues</li>
<li>Docker container</li>
<li>Docker-compose config</li>
<li>Kubernetes config</li>
</ul>
<br>
I use this script that i can create a web or api prototyp without caring about the basic config each time.
<h3>What about crons?</h3>
<p>Use <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/">Kubernetes Crons</a>.</p>
<h3>What about queues?</h3>
<p>The Project setup is based on the mysql queue driver. The migrations will be execute while the start of the docker container.</p>
<h3>Where is the docker config?</h3>
<p>The docker config is in the /resources/docker folder, it contains the Dockerfiles and all needet files to run the project in docker with docker-compose.</p>
<h3>Build app</h3>
<p>To run the app in kubernetes you need to build the docker container. Therefor is a script in the resources/build folder. Before you first start the script change the name of the tag to your projectname, replace the sampleapp. Go in this folder and execute the script to build the container and push them to docker.keks.cloud.</p>
<h3>Run the App in Kubernetes?</h3>
<p>The App contains information to run it on kubernetes. All needet config files are in the resources/kubernetes folder. If you want to run the app in kubernetes you want to change the url and the enivoment files.</p>
<p>You need to change the Namespace name, in this app it is always "sampleapp" you can search it in the kubernetes folder and need to replace it in each file.</p>
<h4>MYSQL</h4>
<p>If you want to run a MYSQL-Server in Kubernetes (just do it if it a prototyp) you need to change and deploy the config-mysql.yml, deployment-mysql.yml and service-mysql.yml</p>
<p>To save the information you need a persistent volume called <code>mysql</code>, or you disabled it in the deplyoment-mysql.yml</p>
<p>If you run the MYSQL-Server in the keks.cloud you can add the config-mysql-backup.yml and cron-mysql-backup.yml to enabled the backup to s3</p>
<h2>Download / Git</h2>
<p>You can get the Project from <a href="https://git.keks.cloud/kekskurse/lumenInit">its git.keks.cloud project</a> or download the last version as <a href="https://git.keks.cloud/kekskurse/lumenInit/archive/master.zip">ZIP</a> or <a href="https://git.keks.cloud/kekskurse/lumenInit/archive/master.tar.gz">TAR.GZ</a>.</p>
</div>
</div>
</div>
</body> </body>
</html> </html>