Add CI/CD
This commit is contained in:
parent
8856f15f68
commit
130182c156
15
.dockerignore
Normal file
15
.dockerignore
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
.env
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.dockerignore
|
||||||
|
.gitignore
|
||||||
|
.docusaurus
|
||||||
|
build
|
||||||
|
README.md
|
||||||
|
Dockerfile
|
||||||
|
kubernetes
|
||||||
|
|
||||||
|
# Artifacts that will be built during image creation.
|
||||||
|
# This should contain all files created during `npm run build`.
|
||||||
|
build
|
||||||
|
node_modules
|
||||||
2
.github/CODEOWNERS
vendored
Normal file
2
.github/CODEOWNERS
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/.github/ @ditkrg/devops
|
||||||
|
/kubernetes/ @ditkrg/devops
|
||||||
57
.github/workflows/deploy-base.yaml
vendored
Normal file
57
.github/workflows/deploy-base.yaml
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
name: Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
image:
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
env_url:
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
env_name:
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
KUBECONFIG:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
NAMESPACE: dit-docs
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
timeout-minutes: 10
|
||||||
|
runs-on: [self-hosted, ubuntu-focal]
|
||||||
|
environment:
|
||||||
|
url: ${{ inputs.env_url }}
|
||||||
|
name: ${{ inputs.env_name }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Kubectl tool installer
|
||||||
|
uses: Azure/setup-kubectl@v1
|
||||||
|
|
||||||
|
- uses: azure/k8s-set-context@v1
|
||||||
|
with:
|
||||||
|
method: kubeconfig
|
||||||
|
kubeconfig: ${{ secrets.KUBECONFIG }}
|
||||||
|
|
||||||
|
- name: Setup Kustomize
|
||||||
|
uses: imranismail/setup-kustomize@v1
|
||||||
|
with:
|
||||||
|
kustomize-version: "4.4.1"
|
||||||
|
|
||||||
|
- name: Edit kustomization file
|
||||||
|
working-directory: kubernetes/base
|
||||||
|
run: kustomize edit set image IMAGE="${{ inputs.image }}"
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
working-directory: kubernetes/${{ inputs.env_name }}
|
||||||
|
run: |-
|
||||||
|
|
||||||
|
kustomize build | kubectl apply -f -
|
||||||
|
kubectl rollout -n "$NAMESPACE" status deployment/dsm-client-deployment -w --timeout=3m
|
||||||
54
.github/workflows/deploy-dev.yaml
vendored
Normal file
54
.github/workflows/deploy-dev.yaml
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
name: Deploy To Development
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
paths-ignore:
|
||||||
|
- "README.md"
|
||||||
|
- ".vscode/**"
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: deploy-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
setup:
|
||||||
|
name: Setup
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
env:
|
||||||
|
IMAGE_REPO: reg.dev.krd/dit-docs/dsm-client
|
||||||
|
steps:
|
||||||
|
- name: Extract image name
|
||||||
|
run: |
|
||||||
|
REF_NAME=$(echo ${GITHUB_REF##*/})
|
||||||
|
echo "IMAGE=$IMAGE_REPO:$REF_NAME" >> $GITHUB_ENV
|
||||||
|
outputs:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
image-sha: ${{ env.IMAGE }}-${{ github.sha }}
|
||||||
|
|
||||||
|
test:
|
||||||
|
uses: ditkrg/dit-digital-service-manual/.github/workflows/tests-base.yaml@dev
|
||||||
|
|
||||||
|
build:
|
||||||
|
uses: ditkrg/common-github-workflows/.github/workflows/build-push-image.yaml@main
|
||||||
|
needs: [setup, test]
|
||||||
|
with:
|
||||||
|
tags: |-
|
||||||
|
${{ needs.setup.outputs.image }}
|
||||||
|
${{ needs.setup.outputs.image-sha }}
|
||||||
|
cache-from: type=registry,ref=${{ needs.setup.outputs.image }}
|
||||||
|
secrets:
|
||||||
|
username: ${{ secrets.HARBOR_USER }}
|
||||||
|
password: ${{ secrets.HARBOR_TOKEN }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
uses: ditkrg/dit-digital-service-manual/.github/workflows/deploy-base.yaml@dev
|
||||||
|
needs: [setup, build]
|
||||||
|
with:
|
||||||
|
image: ${{ needs.setup.outputs.image-sha }}
|
||||||
|
env_url: https://service-manual.docs.dev.krd
|
||||||
|
env_name: development
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
KUBECONFIG: ${{ secrets.KUBECONFIG }}
|
||||||
32
.github/workflows/tests-base.yaml
vendored
Normal file
32
.github/workflows/tests-base.yaml
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
name: Run Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run-tests:
|
||||||
|
name: Run Tests
|
||||||
|
timeout-minutes: 10
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Kubectl tool installer
|
||||||
|
uses: Azure/setup-kubectl@v1
|
||||||
|
|
||||||
|
- name: Setup Kustomize
|
||||||
|
uses: imranismail/setup-kustomize@v1
|
||||||
|
with:
|
||||||
|
kustomize-version: "4.4.1"
|
||||||
|
|
||||||
|
- name: Build k8s manifests
|
||||||
|
working-directory: kubernetes
|
||||||
|
run: |
|
||||||
|
envs=( "development" )
|
||||||
|
|
||||||
|
for i in "${envs[@]}"
|
||||||
|
do
|
||||||
|
kustomize build "$i"
|
||||||
|
done
|
||||||
40
.github/workflows/tests-run.yaml
vendored
Normal file
40
.github/workflows/tests-run.yaml
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
name: Run Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- dev
|
||||||
|
- staging
|
||||||
|
- main
|
||||||
|
paths-ignore:
|
||||||
|
- "**.md"
|
||||||
|
- ".vscode/**"
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run-tests:
|
||||||
|
name: Run Tests
|
||||||
|
timeout-minutes: 10
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Kubectl tool installer
|
||||||
|
uses: Azure/setup-kubectl@v1
|
||||||
|
|
||||||
|
- name: Setup Kustomize
|
||||||
|
uses: imranismail/setup-kustomize@v1
|
||||||
|
with:
|
||||||
|
kustomize-version: "4.4.1"
|
||||||
|
|
||||||
|
- name: Build k8s manifests
|
||||||
|
working-directory: kubernetes
|
||||||
|
run: |
|
||||||
|
envs=( "development" )
|
||||||
|
|
||||||
|
for i in "${envs[@]}"
|
||||||
|
do
|
||||||
|
kustomize build "$i"
|
||||||
|
done
|
||||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
FROM reg.dev.krd/hub.docker/library/node:16 as build-stage
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY src src
|
||||||
|
COPY docs docs
|
||||||
|
COPY static static
|
||||||
|
COPY *.js ./
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM reg.dev.krd/hub.docker/library/nginx:1.20-alpine AS production
|
||||||
|
|
||||||
|
COPY --from=build-stage /app/build /usr/share/nginx/html
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
38
kubernetes/base/deployment.yaml
Normal file
38
kubernetes/base/deployment.yaml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deployment
|
||||||
|
labels:
|
||||||
|
app: dsm-client
|
||||||
|
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: dsm-client
|
||||||
|
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: dsm-client
|
||||||
|
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: dsm-client
|
||||||
|
image: IMAGE
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 32Mi
|
||||||
|
cpu: 500m
|
||||||
|
requests:
|
||||||
|
memory: 32Mi
|
||||||
|
cpu: 5m
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
|
||||||
|
livenessProbe:
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 15
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 80
|
||||||
18
kubernetes/base/ingress.yaml
Normal file
18
kubernetes/base/ingress.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: ingress
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-cluster-issuer
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: service
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
12
kubernetes/base/kustomization.yaml
Normal file
12
kubernetes/base/kustomization.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
namespace: dit-docs
|
||||||
|
|
||||||
|
commonLabels:
|
||||||
|
app: dsm-client
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- ingress.yaml
|
||||||
|
- service.yaml
|
||||||
|
- deployment.yaml
|
||||||
13
kubernetes/base/service.yaml
Normal file
13
kubernetes/base/service.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: service
|
||||||
|
labels:
|
||||||
|
app: dsm-client
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: dsm-client
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
type: ClusterIP
|
||||||
14
kubernetes/development/kustomization.yaml
Normal file
14
kubernetes/development/kustomization.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
namespace: dit-docs
|
||||||
|
namePrefix: dsm-client-
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
|
||||||
|
patches:
|
||||||
|
- path: patches/ingress-host.yaml
|
||||||
|
target:
|
||||||
|
kind: Ingress
|
||||||
9
kubernetes/development/patches/ingress-host.yaml
Normal file
9
kubernetes/development/patches/ingress-host.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
- op: add
|
||||||
|
path: /spec/rules/0/host
|
||||||
|
value: service-manual.docs.dev.krd
|
||||||
|
- op: add
|
||||||
|
path: /spec/tls
|
||||||
|
value:
|
||||||
|
- hosts:
|
||||||
|
- service-manual.docs.dev.krd
|
||||||
|
secretName: ingress-cert-dit-docs-dsm-client
|
||||||
15
nginx.conf
Normal file
15
nginx.conf
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /health {
|
||||||
|
access_log off;
|
||||||
|
default_type text/plain;
|
||||||
|
return 200 "Healthy\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user