26 Commits

Author SHA1 Message Date
831cb06f33 JENKINS: Changed deployed version to dedd162bb5375ece91f4c98c3a06029f38b409b4 2025-07-19 19:52:02 +02:00
6333f7eb70 JENKINS: Changed deployed version to d273a4254f80928152216fb72def233a7700f73a 2025-07-19 19:51:57 +02:00
49ae3a7bf3 JENKINS: Changed deployed version to 2ddee5ddbb2baf61a410bd630bf336d843565dd9 2025-07-19 19:51:52 +02:00
0230b19a87 JENKINS: Changed deployed version to 033493b3f5faa92ae7e9dcff801c39ac80e7febb 2025-07-19 19:51:47 +02:00
0778b8cee6 JENKINS: Changed deployed version to 039c9df549086262a7f7eb313914f58c3f613fb7 2025-07-19 19:51:42 +02:00
33c1f1d10c JENKINS: Changed deployed version to 65992ecc7526b359c97f8f84c4e2a0b25e09fe1b 2025-07-19 19:51:36 +02:00
e1b24c52fe JENKINS: Changed deployed version to 034743134145ff3e4a1c85762ae22cfd292d3861 2025-07-19 19:51:28 +02:00
0b59103e6c JENKINS: Changed deployed version to 696d4557ab26f2983e96e74835ac47614da15f20 2025-07-19 19:51:23 +02:00
ecdf32a90d JENKINS: Changed deployed version to d07f41ece6b5e2db72497073861c0d3ff77dab1a 2025-07-19 19:51:19 +02:00
933c71fce7 JENKINS: Changed deployed version to c2bc6761c339279e3bbf3ecf41ca46e68e0ae856 2025-07-19 19:51:14 +02:00
24597b22f7 JENKINS: Changed deployed version to 76383b030b131b2d7f8757e341502ccce0ca3922 2025-07-19 19:51:09 +02:00
7d10b29160 JENKINS: Changed deployed version to 17ca39e4b04d4f5950f75b1076864465459377fc 2025-07-19 19:51:03 +02:00
41b7f2e959 JENKINS: Changed deployed version to d04b88c6b847cc41e01be832ea26bddca8aa711c 2025-07-19 19:50:55 +02:00
a4b07ad984 JENKINS: Changed deployed version to 9a746322f9a691530c5701458a8753c6e7777372 2025-07-19 19:50:49 +02:00
9017f29d7a JENKINS: Changed deployed version to 22bb43f63f4c0e76484cdd216be653a9c62ba8b5 2025-07-19 19:50:42 +02:00
161c03960a JENKINS: Changed deployed version to 97716abc4c0fc03583fe9388a8faf3972cca9f74 2025-07-19 19:50:34 +02:00
d0bd5f8332 JENKINS: Changed deployed version to 501c9cc7c7ec90761a4e85ea792e67b118ddbb4d 2025-07-19 19:50:26 +02:00
949e6c235d JENKINS: Changed deployed version to b02c240e5b75df151f3f2789203de6915d096c91 2025-07-19 19:50:17 +02:00
7cd408950f JENKINS: Changed deployed version to d3cc1f6ff9f26985800e121752b7a749477ecbf6 2025-07-19 19:49:58 +02:00
739da302fd JENKINS: Changed deployed version to ab75cec74a28e93649bc161db11124dc9a3c4f12 2025-07-19 19:49:20 +02:00
e7bc2a962d Updated image - added wait_for_db and healthcheck to app 2025-07-19 18:52:44 +02:00
698fa9e1d1 Add client id of managed identity 2025-07-19 18:52:37 +02:00
edc669507c Merged tasks for both containers 2025-07-19 18:52:31 +02:00
87994b727f Prepared Docker image to run for pod agent 2025-07-19 18:52:17 +02:00
ebbad36f96 Created pipeline for Jenkins in Kubernetes cluster 2025-07-19 18:52:07 +02:00
9f9086b0d6 Updated managed identity 2025-07-19 18:51:59 +02:00
7 changed files with 146 additions and 38 deletions

32
.jenkins/Dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM debian:bookworm-slim
# Zapobiega interaktywnym promptom
ENV DEBIAN_FRONTEND=noninteractive
# Instalacja zależności systemowych
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
apt-transport-https \
software-properties-common \
unzip \
bash \
&& rm -rf /var/lib/apt/lists/*
# Instalacja Azure CLI
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
# Instalacja kubectl (najświeższa stabilna wersja)
RUN curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/v1.33.1/bin/linux/amd64/kubectl \
&& chmod +x /usr/local/bin/kubectl
# Instalacja kubelogin
RUN curl -sLo /tmp/kubelogin.zip https://github.com/Azure/kubelogin/releases/latest/download/kubelogin-linux-amd64.zip \
&& unzip -j /tmp/kubelogin.zip -d /usr/local/bin \
&& chmod +x /usr/local/bin/kubelogin \
&& rm /tmp/kubelogin.zip
# Domyślna komenda po starcie kontenera
CMD ["bash"]

86
.jenkins/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,86 @@
pipeline {
agent {
kubernetes {
yamlFile '.jenkins/podTemplate.yaml'
}
}
environment {
RESOURCE_GROUP = 'tst-aks-rg'
CLUSTER_NAME = 'build'
DEPLOY_FILES = 'namespace.yaml secret-store.yaml deploy.yaml ingress.yaml'
NAMESPACE = 'user-microservice'
DEPLOYMENT = 'api'
CLIENT_ID = 'c302726f-fafb-4143-94c1-67a70975574a'
}
stages {
stage('Checkout') {
steps {
container('kubectl') {
checkout scm
}
}
}
stage('Login to Azure & Get Kubeconfig') {
steps {
container('kubectl') {
sh '''
az login --identity --client-id ${CLIENT_ID}
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --overwrite-existing
kubelogin convert-kubeconfig -l azurecli
'''
}
}
}
stage('Apply Kubernetes Resources') {
steps {
container('kubectl') {
script {
def files = DEPLOY_FILES.tokenize()
for (file in files) {
sh "kubectl apply -f ${file}"
}
}
}
}
}
stage('Verify Deployment') {
steps {
container('kubectl') {
script {
// Waiting until all pods reach "ready" status
sh '''
echo "Waiting for deployment rollout..."
kubectl rollout status deployment/$DEPLOYMENT -n $NAMESPACE --timeout=60s
'''
}
}
}
}
stage('Health Check') {
steps {
container('kubectl') {
script {
// Check if app is healthy
def ingressUrl = "https://user-microservice.marcin00.pl/health"
sh """
echo "Checking app health ${ingressUrl}..."
for i in {1..30}; do
if curl -sf $ingressUrl; then
echo "Health check OK"
exit 0
else
echo "Health check failed. Retry \$i..."
sleep 5
fi
done
echo "Health check failed."
exit 1
"""
}
}
}
}
}
}

24
.jenkins/podTemplate.yaml Normal file
View File

@ -0,0 +1,24 @@
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: jenkins-agent
spec:
containers:
- name: kubectl
image: marcin00.azurecr.io/azure-cli-kubectl:latest
command:
- cat
tty: true
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
volumes:
- name: workspace-volume
emptyDir: {}
nodeSelector:
kubernetes.io/os: linux
restartPolicy: Never

34
Jenkinsfile vendored
View File

@ -1,34 +0,0 @@
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Get credentials to Cluster') {
steps {
sh '''
az login --identity
az aks get-credentials --resource-group tst-aks-rg --name edu
kubelogin convert-kubeconfig -l azurecli
'''
}
}
stage('Apply to Cluster') {
steps {
sh '''
kubectl apply -f namespace.yaml
kubectl apply -f secret-store.yaml
kubectl apply -f deploy.yaml
kubectl apply -f ingress.yaml
'''
}
}
}
post {
cleanup {
sh 'rm -f ~/.kube/config || true'
}
}
}

View File

@ -81,7 +81,7 @@ spec:
spec:
containers:
- name: api
image: marcin00.azurecr.io/user-microservice:76a351710fffe2be1ae10471bc1a2f511f481126
image: marcin00.azurecr.io/user-microservice:dedd162bb5375ece91f4c98c3a06029f38b409b4
ports:
- containerPort: 80
env:

View File

@ -4,7 +4,7 @@ metadata:
name: deployer-binding
subjects:
- kind: User
name: daabce80-f745-413f-8377-00472517521c
name: f91aef65-7d2a-4df8-a884-e33b05d54a31
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole

View File

@ -24,8 +24,8 @@ spec:
parameters:
usePodIdentity: "false"
useVMManagedIdentity: "true"
userAssignedIdentityID: "0c2780e4-8594-4aab-8f1a-8a19f71924bd" # client_id of the user-assigned managed identity
clientID: "0c2780e4-8594-4aab-8f1a-8a19f71924bd" # client_id of the user-assigned managed identity
userAssignedIdentityID: "f91aef65-7d2a-4df8-a884-e33b05d54a31" # client_id of the user-assigned managed identity
clientID: "f91aef65-7d2a-4df8-a884-e33b05d54a31" # client_id of the user-assigned managed identity
keyvaultName: "dev-aks"
objects: |
array: