feat: implements a better kubernetes deployment setup
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
.gitignore
|
.gitignore
|
||||||
Dockerfile
|
Dockerfile
|
||||||
README.md
|
README.md
|
||||||
|
.k8s
|
||||||
@@ -2,6 +2,12 @@ name: ci
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Tag to deploy'
|
||||||
|
required: false
|
||||||
|
default: 'latest'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -70,3 +76,33 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker push $IMAGE_LATEST
|
docker push $IMAGE_LATEST
|
||||||
docker push $IMAGE_SHA
|
docker push $IMAGE_SHA
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
needs: [docker]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main')
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Kubeconfig
|
||||||
|
uses: azure/setup-kubectl@v3
|
||||||
|
with:
|
||||||
|
method: kubeconfig
|
||||||
|
kubeconfig: ${{ secrets.PORTFOLIO_KUBECONFIG }}
|
||||||
|
|
||||||
|
- name: Deploy to Kubernetes
|
||||||
|
run: |
|
||||||
|
OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
REPO=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
IMAGE_BASE="ghcr.io/${OWNER}/${REPO}"
|
||||||
|
TAG="${{ github.event.inputs.tag || 'latest' }}"
|
||||||
|
|
||||||
|
kubectl config set-context --current --namespace=$KUBE_NAMESPACE
|
||||||
|
|
||||||
|
# Apply any other configuration changes if needed
|
||||||
|
envsubst < .k8s/config.yml | kubectl apply -f -
|
||||||
|
envsubst < .k8s/deployment.yaml | kubectl apply -f -
|
||||||
|
envsubst < .k8s/service.yaml | kubectl apply -f -
|
||||||
|
envsubst < .k8s/ingress.yaml | kubectl apply -f -
|
||||||
8
.k8s/config.yml
Normal file
8
.k8s/config.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
namespace: ${KUBE_NAMESPACE}
|
||||||
|
name: frontend-config
|
||||||
|
data:
|
||||||
|
BACKEND_URL: "${BACKEND_URL}"
|
||||||
|
GITHUB_USER: "${GH_USER}"
|
||||||
59
.k8s/deployment.yaml
Normal file
59
.k8s/deployment.yaml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
namespace: ${KUBE_NAMESPACE}
|
||||||
|
name: frontend-deployment
|
||||||
|
labels:
|
||||||
|
app: frontend
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: frontend
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: frontend
|
||||||
|
spec:
|
||||||
|
nodeSelector:
|
||||||
|
${WORKER_NODE_LABEL}
|
||||||
|
initContainers:
|
||||||
|
- name: wait-backend-init
|
||||||
|
image: busybox:latest
|
||||||
|
args:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- >
|
||||||
|
set -x;
|
||||||
|
while [ $(curl -sw '%{http_code}' "backend-service:8000/health" -o /dev/null) -ne 200 ]; do
|
||||||
|
sleep 15;
|
||||||
|
done
|
||||||
|
containers:
|
||||||
|
- name: frontend
|
||||||
|
image: ${IMAGE_BASE}:${TAG}
|
||||||
|
imagePullPolicy: "Always"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "75m"
|
||||||
|
limits:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "256m"
|
||||||
|
ports:
|
||||||
|
- containerPort: 5000
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 5000
|
||||||
|
initialDelaySeconds: 10
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 5000
|
||||||
|
initialDelaySeconds: 10
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: frontend-config
|
||||||
|
env:
|
||||||
|
- name: PORT
|
||||||
|
value: "5000"
|
||||||
25
.k8s/ingress.yaml
Normal file
25
.k8s/ingress.yaml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
namespace: ${KUBE_NAMESPACE}
|
||||||
|
name: nginx-ingress
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: nginx
|
||||||
|
nginx.ingress.kubernetes.io/use-regex: "true"
|
||||||
|
nginx.ingress.kubernetes.io/rewrite-target: /
|
||||||
|
spec:
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- ${KUBE_DOMAIN}
|
||||||
|
secretName: letsencrypt-cluster-certificate-tls
|
||||||
|
rules:
|
||||||
|
- host: ${KUBE_DOMAIN}
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: frontend-service
|
||||||
|
port:
|
||||||
|
number: 5000
|
||||||
13
.k8s/service.yaml
Normal file
13
.k8s/service.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
namespace: ${KUBE_NAMESPACE}
|
||||||
|
name: frontend-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: frontend
|
||||||
|
ports:
|
||||||
|
- port: 5000
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 5000
|
||||||
|
type: ClusterIP
|
||||||
@@ -16,8 +16,6 @@ export class AuthService {
|
|||||||
|
|
||||||
readonly BACKEND_PATH = environment.backendPath;
|
readonly BACKEND_PATH = environment.backendPath;
|
||||||
|
|
||||||
readonly BACKEND_OAUTH_PATH = environment.backendOAuthPath;
|
|
||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
login(userAuthAtempt: User): void {
|
login(userAuthAtempt: User): void {
|
||||||
this.validateUser(this.loginUser(userAuthAtempt));
|
this.validateUser(this.loginUser(userAuthAtempt));
|
||||||
@@ -25,14 +23,14 @@ export class AuthService {
|
|||||||
|
|
||||||
googleLogin() {
|
googleLogin() {
|
||||||
window.open(
|
window.open(
|
||||||
this.BACKEND_OAUTH_PATH + '/oauth2/authorization/google',
|
this.BACKEND_PATH + '/oauth2/authorization/google',
|
||||||
'_self',
|
'_self',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
githubLogin() {
|
githubLogin() {
|
||||||
window.open(
|
window.open(
|
||||||
this.BACKEND_OAUTH_PATH + '/oauth2/authorization/github',
|
this.BACKEND_PATH + '/oauth2/authorization/github',
|
||||||
'_self',
|
'_self',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -112,7 +110,7 @@ export class AuthService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return this.http
|
return this.http
|
||||||
.get<User>(this.BACKEND_OAUTH_PATH + '/login/oauth2/code/google', {
|
.get<User>(this.BACKEND_PATH + '/login/oauth2/code/google', {
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
params: params,
|
params: params,
|
||||||
})
|
})
|
||||||
@@ -125,7 +123,7 @@ export class AuthService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return this.http
|
return this.http
|
||||||
.get<User>(this.BACKEND_OAUTH_PATH + '/login/oauth2/code/github', {
|
.get<User>(this.BACKEND_PATH + '/login/oauth2/code/github', {
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
params: params,
|
params: params,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: true,
|
production: true,
|
||||||
backendPath: (<any>window)['env']['BACKEND_URL'],
|
backendPath: (<any>window)['env']['BACKEND_URL'],
|
||||||
backendOAuthPath: (<any>window)['env']['BACKEND_OAUTH_URL'],
|
|
||||||
githubUser: (<any>window)['env']['GITHUB_USER'],
|
githubUser: (<any>window)['env']['GITHUB_USER'],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
backendPath: 'http://localhost:8070',
|
backendPath: 'http://localhost:8070',
|
||||||
backendOAuthPath: 'http://localhost:8070',
|
|
||||||
githubUser: 'HideyoshiNakazone',
|
githubUser: 'HideyoshiNakazone',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user