-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
73 lines (63 loc) · 2.2 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
pipeline {
agent any
stages {
stage('Checkout') {
steps {
// Get some code from a GitHub repository
git branch: 'orm', url: 'https://github.com/tsadimas/fastapi-postgres-example.git'
}
}
stage('Test') {
steps {
sh '''
python3.9 -m venv fvenv
source fvenv/bin/activate
pip install -r requirements.txt
cd app
cp .env.example .env
rm test.db || true
pytest
'''
}
}
stage('docker build and push') {
environment {
DOCKER_TOKEN = credentials('docker-push-secret')
DOCKER_USER = 'tsadimas'
DOCKER_SERVER = 'ghcr.io'
DOCKER_PREFIX = 'ghcr.io/tsadimas/myfastapi'
}
steps {
sh '''
HEAD_COMMIT=$(git rev-parse --short HEAD)
TAG=$HEAD_COMMIT-$BUILD_ID
docker build --rm -t $DOCKER_PREFIX:$TAG -t $DOCKER_PREFIX:latest -f fastapi.Dockerfile .
'''
sh '''
echo $DOCKER_TOKEN | docker login $DOCKER_SERVER -u $DOCKER_USER --password-stdin
docker push ghcr.io/tsadimas/myfastapi --all-tags
'''
}
}
stage('deploy postgres to k8s') {
steps {
sh '''
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm upgrade --install my-postgres bitnami/postgresql -f k8s/db/values.yaml
'''
}
}
stage('deploy to k8s') {
steps {
sh '''
kubectl config use-context microk8s
cd k8s/fastapi
ls *.yml | while read fl ; do kubectl apply -f $fl; done
cd ../db
ls *.yml | while read fl ; do kubectl apply -f $fl; done
'''
}
}
}
}