Skip to content

Commit

Permalink
Add example container source for ASCII cows
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Sep 5, 2022
1 parent d0bae3b commit 067fb6a
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ cows.yaml:

```yaml
$ cat <<EOF > cows.yaml
image: alexellis2/cows:latest
# Multi-arch image for arm64, amd64 and armv7l
image: alexellis2/cows:2022-09-05-1955
name: cows
EOF
```
Expand Down
5 changes: 2 additions & 3 deletions cows.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Note: this is not a multi-arch image
# and won't run on your Raspberry Pi
image: alexellis2/cows:latest
# Multi-arch image for arm64, amd64 and armv7l
image: alexellis2/cows:2022-09-05-1955
name: cows
3 changes: 3 additions & 0 deletions examples/cows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
template
build
node_modules
23 changes: 23 additions & 0 deletions examples/cows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16 as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

RUN mkdir -p /home/app

RUN apk add --no-cache nodejs npm

# Add non root user
RUN addgroup -S app && adduser app -S -G app
RUN chown app /home/app

WORKDIR /home/app
USER app

COPY package.json .
RUN npm install --omit=dev
COPY index.js .

CMD ["/usr/bin/node", "./index.js"]
3 changes: 3 additions & 0 deletions examples/cows/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: build
build:
faas-cli publish --platforms linux/amd64,linux/arm64,linux/arm/v7 -f cows.yml
21 changes: 21 additions & 0 deletions examples/cows/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var cows = require('cows')
var all = cows();

function show(cow) {
var cowText = all[cow];
console.log(cowText);
}

var cowArgument = process.argv[2]
if(!cowArgument || isNaN(Number(cowArgument))) {
var randomCow = Math.floor((Math.random() * all.length) + 1);
show(randomCow);
}
else {
var cowNumber = Number(cowArgument);
if(cowNumber && cowNumber <= all.length) {
show(cowNumber);
} else {
console.log("Enter cow number between [1-"+all.length+"]")
}
}
30 changes: 30 additions & 0 deletions examples/cows/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/cows/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "cows",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cows": "^2.1.1"
}
}
10 changes: 10 additions & 0 deletions examples/cows/stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 1.0
provider:
name: openfaas
gateway: http://127.0.0.1:8080

functions:
cows:
lang: dockerfile
handler: ./
image: alexellis2/cows:2022-09-05-1955

0 comments on commit 067fb6a

Please sign in to comment.