Skip to content

Commit

Permalink
Add k8s deployment file and pipeline job
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrebeauguitte committed Apr 15, 2024
1 parent ab80c72 commit d4e41b9
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 36 deletions.
55 changes: 19 additions & 36 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: CI/CD pipeline

on: [push]

env:
APP_VERSION: ${{ github.ref_name }}

jobs:

lint-and-test:
Expand Down Expand Up @@ -32,39 +35,7 @@ jobs:
- name: Running tests
run: python -m pytest --cov=metadata_extract

# build:
# name: Create Docker image
# needs: lint-and-test
# runs-on: ubuntu-latest
# steps:
# - name: Check out the repo
# uses: actions/checkout@v4

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: nationallibraryofnorway/meteor
# tags: |
# type=semver,pattern={{version}}
# type=ref,event=branch
# type=ref,event=pr

# - name: Build image
# uses: docker/build-push-action@v4
# with:
# push: false
# context: .
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# file: Dockerfile
# build-args: |
# USE_GIELLA=true

publish:
build-and-publish:
name: Create and push Docker image
needs: lint-and-test
# if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
Expand Down Expand Up @@ -114,7 +85,7 @@ jobs:

deploy-to-stage:
name: Deploy to kubernetes stage environment
needs: publish
needs: build-and-publish
runs-on: [self-hosted, Linux]
environment: stage
steps:
Expand All @@ -130,12 +101,24 @@ jobs:
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: |
kv/team/text/data/k8s-text-stage *
kv/team/text/data/harvestk8s-text-stage *
- name: Setup Kubectl
uses: azure/setup-kubectl@v4
with:
version: 'v1.26.5'

- name: Deploy to k8s
run: echo "TODO..."
run: |
echo "Deploy version ${{ env.APP_VERSION }}" to stage
kubectl config set-cluster k8s --server="${{ steps.import-secrets.outputs.K8S_STAGE_SERVER }}"
kubectl config set clusters.k8s.certificate-authority-data ${{ steps.import-secrets.outputs.K8S_STAGE_NB_NO_CA }}
kubectl config set-credentials ${{ steps.import-secrets.outputs.K8S_STAGE_USER }} --token=${{ steps.import-secrets.outputs.K8S_STAGE_NB_NO_TOKEN }}
kubectl config set-context meteor --cluster=k8s --user=${{ steps.import-secrets.outputs.K8S_STAGE_USER }} --namespace=tekst-stage
kubectl config use-context meteor
kubectl config view
kubectl version
sed -i "s/<version>/${{ env.APP_VERSION }}/g" k8s/stage/meteor.yml
sed -i "s/<host_url>/${{ steps.import-secrets.outputs.K8S_HOST_URL }}/g" k8s/stage/meteor.yml
kubectl apply -f k8s/stage/meteor.yml
kubectl rollout restart deploy/meteor
94 changes: 94 additions & 0 deletions k8s/stage/meteor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: meteor
spec:
replicas: 1
selector:
matchLabels:
app: meteor
template:
metadata:
labels:
app: meteor
spec:
volumes:
- name: dimo-file-server-volume
persistentVolumeClaim:
claimName: dimo-fileserver-pvc
containers:
- name: app
image: nationallibraryofnorway/meteor:<version>
ports:
- containerPort: 8000
env:
- name: REGISTRY_HOST
valueFrom:
secretKeyRef:
name: meteor-registry-secret
key: host
- name: REGISTRY_DATABASE
valueFrom:
secretKeyRef:
name: meteor-registry-secret
key: database
- name: REGISTRY_USER
valueFrom:
secretKeyRef:
name: meteor-registry-secret
key: username
- name: REGISTRY_PASSWORD
valueFrom:
secretKeyRef:
name: meteor-registry-secret
key: password
- name: MOUNT_FOLDER
value: "/dimo-file-server"
- name: MAX_FILE_SIZE_MB
value: "10000"
- name: ENVIRONMENT
value: "stage"
- name: LANGUAGES
value: "mul,eng,nob,nno"
- name: USE_GIELLADETECT
value: "True"
- name: GIELLADETECT_LANGS
value: "nno,nob,eng,sme,sma,smj"
volumeMounts:
- name: dimo-file-server-volume
mountPath: /dimo-file-server
imagePullPolicy: Always

---

apiVersion: v1
kind: Service
metadata:
name: meteor-service
spec:
ports:
- port: 8000
name: http
targetPort: 8000
selector:
app: meteor
type: ClusterIP

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: meteor-ingress
spec:
rules:
- host: <host_url>
http:
paths:
- path: /meteor
pathType: Prefix
backend:
service:
name: meteor-service
port:
number: 8000

0 comments on commit d4e41b9

Please sign in to comment.