-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example container source for ASCII cows
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
- Loading branch information
Showing
9 changed files
with
109 additions
and
4 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
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 |
---|---|---|
@@ -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 |
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,3 @@ | ||
template | ||
build | ||
node_modules |
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,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"] |
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,3 @@ | ||
.PHONY: build | ||
build: | ||
faas-cli publish --platforms linux/amd64,linux/arm64,linux/arm/v7 -f cows.yml |
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 @@ | ||
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+"]") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"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" | ||
} | ||
} |
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 @@ | ||
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 |