Initial commit
This commit is contained in:
commit
924174d4ae
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
./node_modules
|
||||||
|
./build
|
||||||
|
.git
|
||||||
|
*.md
|
||||||
|
.gitignore
|
||||||
|
.idea/
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.vscode
|
||||||
|
.idea/
|
||||||
|
.env
|
||||||
|
node_nodules/
|
||||||
|
.kpt-pipeline/
|
||||||
|
|
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# pull official node image
|
||||||
|
FROM node AS dev
|
||||||
|
|
||||||
|
# define /app as working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# copy package.json and package-lock.json to /app
|
||||||
|
COPY package.json /app
|
||||||
|
COPY package-lock.json /app
|
||||||
|
|
||||||
|
# install node dependencies
|
||||||
|
RUN npm install
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
# launch node server
|
||||||
|
ENTRYPOINT npm run dev
|
||||||
|
|
||||||
|
# production
|
||||||
|
FROM dev AS prod
|
||||||
|
ENTRYPOINT npm run start
|
22
README.md
Normal file
22
README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Node.js and skaffold example
|
||||||
|
## How to get going?
|
||||||
|
1. Change `image` URLs in `skaffold.yaml` according to your desired image registry and image name
|
||||||
|
2. Change `ingress` definition in `k8s/dev/application.yml`:
|
||||||
|
- Traefik's URL `external-dns.alpha.kubernetes.io/target:`
|
||||||
|
- `- host:`
|
||||||
|
3. Attempt to run Skaffold:
|
||||||
|
- `skaffold dev --namespace <your Kubernetes namespace> [--kube-context <your kubeconfig context, if applicable>]`
|
||||||
|
4. When working and finished, you can leave the application running:
|
||||||
|
- copy `k8s/dev/application.yml` to `k8s/staging/`
|
||||||
|
- run `skaffold run` with the same parameters as earlier
|
||||||
|
|
||||||
|
## How to use harbor.codemowers.eu
|
||||||
|
1. Log in in web browser
|
||||||
|
2. Create a project or use one destined for you
|
||||||
|
3. Make it public in the `Configuration` tab so that Kubernetes can easily download the image (do not do this for actual production applications)
|
||||||
|
4. Create a robot account in `Robot Accounts tab`
|
||||||
|
- Name the account in some way, give it some expiring date
|
||||||
|
- Keep the modal with login open
|
||||||
|
- Run `docker login --username <robot-acc-username> --password <robot-acc-password> harbor.codemowers.eu`.
|
||||||
|
**Beware!** Harbor uses `$` character in the username which bash and other shells would interpret as start of an variable.
|
||||||
|
Escape it with `\ `, like so: `docker login --username robot\$eaas+docker --password ...`
|
56
k8s/dev/application.yaml
Normal file
56
k8s/dev/application.yaml
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: node-skaffold-example
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: traefik
|
||||||
|
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||||
|
traefik.ingress.kubernetes.io/router.tls: "true"
|
||||||
|
external-dns.alpha.kubernetes.io/target: traefik-c7ra9.codemowers.ee
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: hello-c7ra9.codemowers.ee
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- pathType: Prefix
|
||||||
|
path: "/"
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: node-skaffold-example
|
||||||
|
port:
|
||||||
|
number: 8080
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- "*.codemowers.ee"
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: node-skaffold-example
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
selector:
|
||||||
|
app: node-skaffold-example
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 8080
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: node-skaffold-example
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: node-skaffold-example
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: node-skaffold-example
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: node-skaffold-example
|
||||||
|
image: harbor.codemowers.eu/eaas/node-skaffold-example
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
0
k8s/staging/.gitkeep
Normal file
0
k8s/staging/.gitkeep
Normal file
21
package.json
Normal file
21
package.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "app",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"dev": "nodemon server.js -e ejs,js,css,html,jpg,png,scss",
|
||||||
|
"prod": "node.js server.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.17.2",
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.20"
|
||||||
|
}
|
||||||
|
}
|
14
server.js
Normal file
14
server.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
const host = '0.0.0.0';
|
||||||
|
const port = 8080;
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
res.statusCode = 200;
|
||||||
|
res.setHeader('Content-Type', 'text/plain');
|
||||||
|
res.end('Hello World!');
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(port, host, () => {
|
||||||
|
console.log('Web server running at http://%s:%s',host,port );
|
||||||
|
});
|
34
skaffold.yaml
Normal file
34
skaffold.yaml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
apiVersion: skaffold/v3alpha1
|
||||||
|
kind: Config
|
||||||
|
metadata:
|
||||||
|
name: node-skaffold-example
|
||||||
|
|
||||||
|
build:
|
||||||
|
artifacts:
|
||||||
|
- image: harbor.codemowers.eu/eaas/node-skaffold-example
|
||||||
|
docker:
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
kubectl: {}
|
||||||
|
|
||||||
|
manifests:
|
||||||
|
rawYaml:
|
||||||
|
- k8s/staging/application.yaml
|
||||||
|
|
||||||
|
profiles:
|
||||||
|
- name: dev
|
||||||
|
activation:
|
||||||
|
- command: dev
|
||||||
|
build:
|
||||||
|
artifacts:
|
||||||
|
- image: harbor.codemowers.eu/eaas/node-skaffold-example
|
||||||
|
docker:
|
||||||
|
target: dev
|
||||||
|
sync:
|
||||||
|
manual:
|
||||||
|
- src: '**/*.js'
|
||||||
|
dest: .
|
||||||
|
manifests:
|
||||||
|
rawYaml:
|
||||||
|
- k8s/dev/application.yaml
|
Loading…
Reference in New Issue
Block a user