Skip to content

Commit 4449a3c

Browse files
Feat: Add k8s manifests
1 parent e82e97d commit 4449a3c

10 files changed

Lines changed: 215 additions & 2 deletions

File tree

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
.git/
3+
gh-pages/
4+
.github/
5+
dev/server/Cress-gh/
6+
.idea/
7+
*.md
8+
yarn-error.log

.github/workflows/build-deploy.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build and Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ghcr.io/ddmal/cress
11+
12+
jobs:
13+
build-and-deploy:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Log in to GitHub Container Registry
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Extract metadata for Docker
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ${{ env.IMAGE_NAME }}
35+
tags: |
36+
type=raw,value=latest
37+
type=sha,format=short
38+
39+
- name: Build and push Docker image
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: .
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
46+
47+
- name: Set up kubectl
48+
uses: azure/setup-kubectl@v3
49+
50+
- name: Configure kubeconfig
51+
run: |
52+
mkdir -p ~/.kube
53+
echo "${{ secrets.KUBE_CONFIG }}" > ~/.kube/config
54+
chmod 600 ~/.kube/config
55+
56+
- name: Apply Kubernetes manifests
57+
run: kubectl apply -f k8s/
58+
59+
- name: Roll out updated image
60+
run: |
61+
SHA_TAG="${{ env.IMAGE_NAME }}:sha-$(echo ${{ github.sha }} | cut -c1-7)"
62+
kubectl set image deployment/cress cress="${SHA_TAG}" -n cress
63+
kubectl rollout status deployment/cress -n cress

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
.DS_Store
33
.awcache
44
.vscode
5+
.idea
56

67
/dev/server/Cress-gh
78
/dev/public
89
/dist
910

10-
/gh-pages/
11+
/gh-pages/

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:20-alpine AS builder
2+
WORKDIR /app
3+
4+
COPY package.json yarn.lock ./
5+
RUN yarn install --frozen-lockfile
6+
7+
COPY . .
8+
RUN yarn build:k8s
9+
10+
FROM nginx:alpine
11+
COPY --from=builder /app/dev/server /usr/share/nginx/html
12+
COPY nginx.conf /etc/nginx/conf.d/default.conf
13+
EXPOSE 80

k8s/deployment.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: cress
5+
namespace: cress
6+
spec:
7+
replicas: 2
8+
selector:
9+
matchLabels:
10+
app: cress
11+
template:
12+
metadata:
13+
labels:
14+
app: cress
15+
spec:
16+
containers:
17+
- name: cress
18+
image: ghcr.io/ddmal/cress:latest
19+
ports:
20+
- containerPort: 80
21+
resources:
22+
requests:
23+
cpu: 50m
24+
memory: 64Mi
25+
limits:
26+
cpu: 200m
27+
memory: 128Mi

k8s/ingress.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: cress
5+
namespace: cress
6+
spec:
7+
rules:
8+
- host: cress.simssa.ca
9+
http:
10+
paths:
11+
- path: /
12+
pathType: Prefix
13+
backend:
14+
service:
15+
name: cress
16+
port:
17+
number: 80

k8s/service.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: cress
5+
namespace: cress
6+
spec:
7+
selector:
8+
app: cress
9+
ports:
10+
- port: 80
11+
targetPort: 80

nginx.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
server {
2+
listen 80;
3+
root /usr/share/nginx/html;
4+
index index.html;
5+
6+
gzip on;
7+
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
8+
gzip_min_length 1024;
9+
10+
# Long-lived cache for immutable webpack bundles and assets
11+
location /Cress-gh/ {
12+
expires 1y;
13+
add_header Cache-Control "public, immutable";
14+
try_files $uri =404;
15+
}
16+
17+
# HTML pages — no cache so updates are picked up immediately
18+
location ~* \.html$ {
19+
expires -1;
20+
add_header Cache-Control "no-store";
21+
try_files $uri =404;
22+
}
23+
24+
location / {
25+
try_files $uri $uri/ =404;
26+
}
27+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"start": "http-server dev/server/ -p 9000",
88
"build": "rm -rf dev/server/Cress-gh && webpack --config webpack.config.js && cp -R assets src/workers dev/server/Cress-gh",
9-
"bundle:pages": "rm -rf gh-pages/Cress/Cress-gh && webpack --config webpack.pages-config.js && cp -R assets src/workers gh-pages/Cress/Cress-gh"
9+
"bundle:pages": "rm -rf gh-pages/Cress/Cress-gh && webpack --config webpack.pages-config.js && cp -R assets src/workers gh-pages/Cress/Cress-gh",
10+
"build:k8s": "rm -rf dev/server/Cress-gh && webpack --config webpack.k8s-config.js && cp -R assets src/workers dev/server/Cress-gh"
1011
},
1112
"repository": "https://github.com/DDMAL/Cress.git",
1213
"author": {

webpack.k8s-config.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
4+
5+
module.exports = {
6+
mode: 'production',
7+
entry: {
8+
landing: './dev/scripts/landing.ts',
9+
dashboard: './dev/scripts/dashboard.ts',
10+
editor: './dev/scripts/editor.ts',
11+
},
12+
output: {
13+
path: path.resolve(__dirname, 'dev', 'server', 'Cress-gh'),
14+
publicPath: '/',
15+
filename: '[name].js',
16+
},
17+
module: {
18+
rules: [
19+
{
20+
test: /\.tsx?$/,
21+
use: ['ts-loader'],
22+
exclude: /node_modules/,
23+
},
24+
{
25+
test: /Worker\.js$/,
26+
use: [
27+
{
28+
loader: 'worker-loader',
29+
options: { publicPath: '/Cress-gh/' },
30+
},
31+
],
32+
},
33+
],
34+
},
35+
resolve: {
36+
extensions: ['.ts', '.js'],
37+
},
38+
plugins: [
39+
new NodePolyfillPlugin(),
40+
new webpack.DefinePlugin({
41+
__LINK_LOCATION__: JSON.stringify('/'),
42+
__ASSET_PREFIX__: JSON.stringify('/Cress-gh/'),
43+
}),
44+
],
45+
};

0 commit comments

Comments
 (0)