Skip to content

Commit a0f131d

Browse files
Merge pull request #1361 from DDMAL/k8s-migration
Add k8s manifests
2 parents 547b2b4 + cd2a173 commit a0f131d

8 files changed

Lines changed: 203 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build, Push, and Deploy
2+
3+
on:
4+
push:
5+
6+
permissions:
7+
contents: read
8+
packages: write
9+
10+
jobs:
11+
build-and-push:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
20+
- name: Sanitize branch name
21+
id: branch
22+
run: echo "name=$(echo '${{ github.ref_name }}' | sed 's/[^a-zA-Z0-9._-]/-/g')" >> $GITHUB_OUTPUT
23+
24+
- name: Login to GitHub Container Registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Build and push
32+
uses: docker/build-push-action@v5
33+
with:
34+
context: .
35+
push: true
36+
tags: |
37+
ghcr.io/ddmal/neon:${{ steps.branch.outputs.name }}-latest
38+
ghcr.io/ddmal/neon:${{ github.sha }}
39+
cache-from: type=gha
40+
cache-to: type=gha,mode=max
41+
42+
deploy:
43+
runs-on: ubuntu-latest
44+
needs: build-and-push
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
49+
- name: Set up kubectl
50+
uses: azure/setup-kubectl@v3
51+
52+
- name: Set kubeconfig
53+
run: |
54+
mkdir -p $HOME/.kube
55+
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
56+
chmod 600 $HOME/.kube/config
57+
58+
- name: Apply manifests
59+
run: kubectl apply -f k8s/
60+
61+
- name: Restart deployment
62+
run: kubectl rollout restart deployment/neon -n neon

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
/cypress/screenshots
1313
/cypress/downloads
1414

15+
.idea

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:18-alpine AS builder
2+
RUN apk add --no-cache git
3+
ENV NODE_OPTIONS=--openssl-legacy-provider
4+
WORKDIR /app
5+
6+
COPY package.json yarn.lock ./
7+
RUN yarn install --frozen-lockfile
8+
9+
COPY . .
10+
RUN yarn build:prod
11+
12+
FROM nginx:1.25-alpine
13+
COPY --from=builder /app/deployment/server /usr/share/nginx/html
14+
COPY k8s/nginx.conf /etc/nginx/conf.d/default.conf
15+
EXPOSE 80
16+
CMD ["nginx", "-g", "daemon off;"]

k8s/configmap.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: neon-nginx-conf
5+
namespace: neon
6+
data:
7+
default.conf: |
8+
server {
9+
listen 80;
10+
server_name _;
11+
root /usr/share/nginx/html;
12+
index index.html;
13+
14+
gzip on;
15+
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
16+
17+
# Cache compiled assets long-term; no-cache for HTML entry points
18+
location /Neon-gh/ {
19+
expires 1y;
20+
add_header Cache-Control "public, immutable";
21+
}
22+
23+
location ~* \.(html|htm)$ {
24+
expires -1;
25+
add_header Cache-Control "no-cache";
26+
}
27+
28+
location / {
29+
try_files $uri $uri/ =404;
30+
}
31+
}

k8s/deployment.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: neon
5+
namespace: neon
6+
labels:
7+
app: neon
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: neon
13+
template:
14+
metadata:
15+
labels:
16+
app: neon
17+
spec:
18+
imagePullSecrets:
19+
- name: ghcr-pull-secret
20+
containers:
21+
- name: neon
22+
image: ghcr.io/ddmal/neon:develop-latest
23+
imagePullPolicy: Always
24+
ports:
25+
- containerPort: 80
26+
volumeMounts:
27+
- name: nginx-conf
28+
mountPath: /etc/nginx/conf.d/default.conf
29+
subPath: default.conf
30+
resources:
31+
requests:
32+
memory: "64Mi"
33+
cpu: "50m"
34+
limits:
35+
memory: "256Mi"
36+
cpu: "200m"
37+
volumes:
38+
- name: nginx-conf
39+
configMap:
40+
name: neon-nginx-conf

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: neon
5+
namespace: neon
6+
spec:
7+
rules:
8+
- host: neon.simssa.ca
9+
http:
10+
paths:
11+
- path: /
12+
pathType: Prefix
13+
backend:
14+
service:
15+
name: neon
16+
port:
17+
number: 80

k8s/nginx.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
gzip on;
8+
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
9+
10+
# Cache compiled assets long-term; no-cache for HTML entry points
11+
location /Neon-gh/ {
12+
expires 1y;
13+
add_header Cache-Control "public, immutable";
14+
}
15+
16+
location ~* \.(html|htm)$ {
17+
expires -1;
18+
add_header Cache-Control "no-cache";
19+
}
20+
21+
location / {
22+
try_files $uri $uri/ =404;
23+
}
24+
}

k8s/service.yaml

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

0 commit comments

Comments
 (0)