Skip to content

Commit 7a132ac

Browse files
committed
Setup khz-k3s deployment
1 parent c8d1b5e commit 7a132ac

File tree

8 files changed

+198
-47
lines changed

8 files changed

+198
-47
lines changed

.github/workflows/master.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: ['master']
9+
pull_request:
10+
branches: ['master']
11+
12+
jobs:
13+
test:
14+
if: ${{ ! endsWith(github.event.head_commit.message, '[skip ci]') }}
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
target: ['lint-all', 'test-all']
20+
node-version: [20.x, 22.x]
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
cache: 'npm'
29+
- run: npm install
30+
- run: npm run ${{ matrix.target }}
31+
32+
build:
33+
if: ${{ ! endsWith(github.event.head_commit.message, '[skip ci]') }}
34+
runs-on: ubuntu-latest
35+
36+
strategy:
37+
matrix:
38+
package: ['base-node', 'archive']
39+
node-version: [20.x]
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v2
44+
45+
- name: Setup node 20
46+
uses: actions/setup-node@v3
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
cache: 'npm'
50+
51+
- name: Run npm install
52+
run: npm install
53+
54+
- name: Run node build
55+
run: npx nx run ${{ matrix.package }}:node:build --output-style=stream
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v2
59+
60+
- name: Login to GitHub Container Registry
61+
uses: docker/login-action@v2
62+
with:
63+
registry: ghcr.io
64+
username: ${{ github.actor }}
65+
password: ${{ secrets.GITHUB_TOKEN }}
66+
67+
- name: Build and push Docker image
68+
uses: docker/build-push-action@v3
69+
with:
70+
context: ./packages/${{ matrix.package }}
71+
push: true
72+
tags: ghcr.io/${{ github.repository }}/${{ matrix.package}}:latest, ghcr.io/${{ github.repository }}/${{ matrix.package}}:${{ github.sha }}
73+
74+
- uses: mikefarah/yq@master
75+
with:
76+
cmd: yq --version
77+
78+
- name: Update image version tag
79+
run: |
80+
git config --global user.email "juhani.pelli@gmail.com"
81+
git config --global user.name "Juhani Pelli"
82+
yq e '.images[0].newTag = "${{ github.sha }}"' -i packages/${{ matrix.package }}/.khz-k3s/kustomization.yaml
83+
git add packages/${{ matrix.package }}/.khz-k3s/kustomization.yaml
84+
git commit -m "Deploy ${{ github.sha }} [skip ci]"
85+
git push origin ${{ github.event.repository.default_branch }}

.github/workflows/node.js.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

nx.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
},
2727
"start": {
2828
"dependsOn": ["node:build"]
29-
},
30-
"docker:build": {
31-
"dependsOn": ["^docker:build"]
32-
},
33-
"docker:run": {
34-
"dependsOn": ["docker:build"]
35-
},
36-
"gcloud:build": {
37-
"dependsOn": ["^gcloud:build"]
3829
}
3930
}
4031
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: ruuvipuserrin-archive
5+
6+
labels:
7+
app: ruuvipuserrin-archive
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: ruuvipuserrin-archive
13+
template:
14+
metadata:
15+
labels:
16+
app: ruuvipuserrin-archive
17+
spec:
18+
imagePullSecrets:
19+
- name: github-registry-secret
20+
containers:
21+
- name: ruuvipuserrin-archive
22+
image: ghcr.io/unkhz/ruuvipuserrin/archive:latest
23+
ports:
24+
- containerPort: 80
25+
environment:
26+
- name: PG_HOST
27+
value: 'nope'
28+
- name: PG_HOSTPORT
29+
value: 'nope'
30+
- name: PG_HOSTUSER
31+
value: 'nope'
32+
- name: PG_HOSTPASSWORD
33+
value: 'nope'
34+
- name: PG_HOSTDB
35+
value: 'nope'
36+
- name: PG_HOSTCERT
37+
value: 'nope'
38+
resources:
39+
requests:
40+
memory: '32Mi'
41+
cpu: '50m'
42+
limits:
43+
memory: '256Mi'
44+
cpu: '200m'
45+
readinessProbe:
46+
httpGet:
47+
path: /health
48+
port: 80
49+
livenessProbe:
50+
httpGet:
51+
path: /health
52+
port: 80
53+
initialDelaySeconds: 30
54+
periodSeconds: 300
55+
timeoutSeconds: 15
56+
---
57+
apiVersion: v1
58+
kind: Service
59+
metadata:
60+
name: ruuvipuserrin-archive-service
61+
62+
annotations:
63+
external-dns.alpha.kubernetes.io/hostname: archive.ruuvipuserrin.khz.fi
64+
external-dns.alpha.kubernetes.io/cloudflare-proxied: 'false'
65+
66+
spec:
67+
selector:
68+
app: ruuvipuserrin-archive
69+
ports:
70+
- protocol: TCP
71+
port: 80
72+
targetPort: 80
73+
type: ClusterIP
74+
---
75+
apiVersion: networking.k8s.io/v1
76+
kind: Ingress
77+
metadata:
78+
name: ruuvipuserrin-archive-ingress
79+
80+
annotations:
81+
kubernetes.io/ingress.class: 'traefik'
82+
cert-manager.io/cluster-issuer: 'letsencrypt-prod'
83+
spec:
84+
rules:
85+
- host: archive.ruuvipuserrin.khz.fi
86+
http:
87+
paths:
88+
- path: /
89+
pathType: Prefix
90+
backend:
91+
service:
92+
name: ruuvipuserrin-archive-service
93+
port:
94+
number: 80
95+
tls:
96+
- hosts:
97+
- archive.ruuvipuserrin.khz.fi
98+
secretName: ruuvipuserrin-archive-tls
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: apps
4+
resources:
5+
- deployment.yaml
6+
images:
7+
- name: ghcr.io/unkhz/ruuvipuserrin/archive
8+
newTag: latest

packages/archive/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
"node:build": "tsc --project tsconfig.build.json",
1414
"dev": "nodemon --watch './**/*.ts' --exec 'ts-node' index.ts",
1515
"start": "node dist/index.js",
16-
"docker:build": "docker build . --tag=ruuvipuserrin/archive",
1716
"docker:run": "docker run --name=ruuvipuserrin-archive --env-file=../../.env.local --rm -p 4000:4000 ruuvipuserrin/archive",
18-
"docker:stop": "docker stop ruuvipuserrin-archive",
19-
"gcloud:build": "gcloud builds submit --tag gcr.io/ruuvipuserrin/archive",
20-
"gcloud:deploy": "gcloud run deploy archive --image gcr.io/ruuvipuserrin/archive --update-secrets=PG_HOST=PG_HOST:latest,PG_PORT=PG_PORT:latest,PG_DB=PG_DB:latest,PG_USER=PG_USER:latest,PG_PASSWORD=PG_PASSWORD:latest,PG_CERT=PG_CERT:latest --service-account=archive-identity --no-allow-unauthenticated",
21-
"gcloud:update-secrets": "./update-secrets.sh"
17+
"docker:stop": "docker stop ruuvipuserrin-archive"
2218
},
2319
"devDependencies": {
2420
"@types/express": "^4.17.17"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: apps
4+
images:
5+
- name: ghcr.io/unkhz/ruuvipuserrin/base-node
6+
newTag: latest

packages/base-node/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"name": "@ruuvipuserrin/base-node",
33
"version": "0.0.0",
4-
"scripts": {
5-
"docker:build": "docker build ../.. --tag gcr.io/ruuvipuserrin/base-node",
6-
"gcloud:build": "cd ../..; gcloud builds submit --tag gcr.io/ruuvipuserrin/base-node"
7-
},
84
"devDependencies": {
95
"@types/jest": "^29.4.0",
106
"@types/node": "^18.11.18",

0 commit comments

Comments
 (0)