forked from sixeyed/kiamol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
3,874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Ch21 Image Builds | ||
|
||
on: | ||
push: | ||
paths: | ||
- ".github/workflows/ch21.yaml" | ||
- "ch21/docker-images/**" | ||
schedule: | ||
- cron: "0 0-7 * * *" | ||
|
||
jobs: | ||
ch21: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- uses: azure/docker-login@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
- name: ch21 | ||
working-directory: ./ch21/docker-images | ||
run: | | ||
docker-compose build | ||
docker-compose push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: "3.7" | ||
|
||
services: | ||
ch21-serverless-cli: | ||
image: kiamol/ch21-serverless-cli | ||
build: | ||
context: ./serverless-cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM node:12 | ||
|
||
ENV SERVERLESS_VERSION="1.77.1" \ | ||
KUBERNETES_VERSION="1.18.5" | ||
|
||
RUN npm install -g serverless@${SERVERLESS_VERSION} | ||
|
||
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl && \ | ||
chmod +x kubectl && \ | ||
mv kubectl /usr/local/bin/ | ||
|
||
COPY start.sh / | ||
RUN chmod +x /start.sh | ||
CMD /start.sh | ||
WORKDIR /kiamol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
# set up access to Kube API | ||
kubectl config set-cluster default --server=https://kubernetes.default --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt | ||
kubectl config set-context default --cluster=default | ||
kubectl config set-credentials user --token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) | ||
kubectl config set-context default --user=user | ||
kubectl config use-context default | ||
|
||
cd / | ||
git clone https://github.com/sixeyed/kiamol | ||
|
||
while true; do sleep 1000; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ch21.net.kiamol; | ||
|
||
import io.kubeless.Event; | ||
import io.kubeless.Context; | ||
|
||
public class Kiamol { | ||
public String hello(io.kubeless.Event event, io.kubeless.Context context) { | ||
return "Hello from chapter 21!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: networking.k8s.io/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: todo-api | ||
labels: | ||
kiamol: ch21 | ||
spec: | ||
rules: | ||
- host: api.todo.kiamol.local | ||
http: | ||
paths: | ||
- path: /todos | ||
backend: | ||
serviceName: todo-api | ||
servicePort: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "todo-api", | ||
"version": "0.1.0", | ||
"main": "server.js", | ||
"author": "kiamol", | ||
"dependencies": { | ||
"nats" : "1.4.9", | ||
"uuid" : "8.2.0" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const NATS = require('nats') | ||
const nc = NATS.connect({url: 'nats://message-queue:4222', json: true}) | ||
const { v4: uuidv4 } = require('uuid'); | ||
|
||
function handler(event, context) { | ||
console.log('** todo-api handler called'); | ||
|
||
var newItemEvent = { | ||
Subject: "events.todo.newitem", | ||
Item: { | ||
Item: event.data, | ||
DateAdded: new Date().toISOString() | ||
}, | ||
CorrelationId: uuidv4() | ||
} | ||
|
||
nc.publish('events.todo.newitem', newItemEvent) | ||
console.log(`** New item published, event ID: ${newItemEvent.CorrelationId}`); | ||
} | ||
|
||
module.exports = { handler } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import json | ||
|
||
def handler(event, context): | ||
new_item = json.loads(event.data) | ||
print(f"AUDIT @ {new_item['Item']['DateAdded']}: {new_item['Item']['Item']}") |
28 changes: 28 additions & 0 deletions
28
ch21/functions/todo-mutating-handler/mutating-handler.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: kubeless.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: todo-mutating-handler | ||
namespace: default | ||
label: | ||
created-by: kubeless | ||
spec: | ||
runtime: php7.3 | ||
timeout: "10" | ||
handler: todo-mutating-handler.mutate | ||
deps: "" | ||
function-content-type: text | ||
function: | | ||
<?php | ||
function mutate($event, $context) { | ||
fwrite(STDOUT, '* Mutating handler called.'); | ||
$conn = pg_connect('host=todo-db dbname=todo user=postgres password=kiamol-2*2*'); | ||
if (!$conn) { | ||
echo 'Connection failed'; | ||
exit; | ||
} | ||
$sql = 'UPDATE "public"."ToDos" SET "Item"=\'Leave a nice review for KIAMOL :)\''; | ||
$result = pg_query($conn, $sql); | ||
fwrite(STDOUT, '* Mutation complete.'); | ||
return "* Mutated..."; | ||
} |
Oops, something went wrong.