11 Commits

Author SHA1 Message Date
Marcin-Ramotowski
1b7204c2ba Changed name of variable to store ACR name instead of ACR username 2025-06-10 20:17:25 +00:00
Marcin-Ramotowski
8f9aed299d Added managed identity client id 2025-06-10 19:32:40 +00:00
Marcin-Ramotowski
6522977280 Changed basic auth to managed identity 2025-06-10 18:50:37 +00:00
Marcin-Ramotowski
c707974a2e Corrected agent declaration in Jenkinsfile 2025-06-08 16:56:35 +00:00
Marcin-Ramotowski
cc2f224d60 Moved pod agent code from Jenkins master to YAML file in repo 2025-06-08 16:45:05 +00:00
Marcin-Ramotowski
b14e6cf873 Restored dind container usage 2025-06-07 21:44:24 +00:00
Marcin-Ramotowski
87e3c0df80 Removed Goss tests 2025-06-07 21:14:40 +00:00
Marcin-Ramotowski
aea09a6081 Added bash installation 2025-06-07 15:08:58 +00:00
Marcin-Ramotowski
d05cede409 The command curl is replaced with wget 2025-06-07 15:06:19 +00:00
Marcin-Ramotowski
17162027b6 Removed unnecessary post cleanup 2025-06-07 14:57:35 +00:00
Marcin-Ramotowski
8887f1b2bd Updated Jenkins pipeline to use in Kubernetes 2025-06-07 13:31:03 +00:00
2 changed files with 67 additions and 40 deletions

54
Jenkinsfile vendored
View File

@@ -1,19 +1,22 @@
pipeline { pipeline {
agent any agent {
kubernetes {
label 'kubernetes-agent'
yamlFile 'podTemplate.yaml'
}
}
environment { environment {
ACR_NAME = 'marcin00'
CLIENT_ID = 'c302726f-fafb-4143-94c1-67a70975574a'
DOCKER_REGISTRY_URL = 'marcin00.azurecr.io' DOCKER_REGISTRY_URL = 'marcin00.azurecr.io'
DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}" DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}"
ACR_NAME = 'marcin00'
} }
stages { stages {
stage('Checkout') { stage('Code Tests') {
steps { steps {
checkout scm container('python') {
}
}
stage('Test python app') {
steps {
script {
dir('api') { dir('api') {
sh ''' sh '''
python3 -m venv env python3 -m venv env
@@ -30,33 +33,13 @@ pipeline {
} }
} }
} }
stage('Build & test docker image') {
steps {
script {
appImage = docker.build("${DOCKER_IMAGE}")
sh label: 'Install dgoss', script: ''' stage('Build & Push Docker') {
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -o goss
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -o dgoss
chmod +rx *goss
'''
withEnv(['GOSS_OPTS=-f junit', 'GOSS_PATH=./goss', 'GOSS_SLEEP=3', 'SQLALCHEMY_DATABASE_URI=sqlite:///:memory:']) {
sh label: 'run image tests', script: './dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: ${DOCKER_IMAGE} > goss_junit.xml'
}
}
}
post {
always {
junit testResults: '**/*goss_junit.xml'
}
}
}
stage('Deploy') {
steps { steps {
script { container('docker') {
sh ''' sh '''
az login --identity docker build -t ${DOCKER_IMAGE} .
az login --identity --client-id ${CLIENT_ID}
az acr login --name ${ACR_NAME} az acr login --name ${ACR_NAME}
docker push ${DOCKER_IMAGE} docker push ${DOCKER_IMAGE}
''' '''
@@ -64,9 +47,4 @@ pipeline {
} }
} }
} }
post {
cleanup {
script { cleanWs() }
}
}
} }

49
podTemplate.yaml Normal file
View File

@@ -0,0 +1,49 @@
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins: "slave"
jenkins/label: "kubernetes-agent"
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:alpine
tty: false
workingDir: /home/jenkins/agent
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
env:
- name: JENKINS_WEB_SOCKET
value: "true"
- name: REMOTING_OPTS
value: "-noReconnectAfter 1d"
- name: python
image: python:3.11.7-alpine
command:
- cat
tty: true
workingDir: /home/jenkins/agent
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
- name: docker
image: marcin00.azurecr.io/azure-cli-docker:slim-bookworm
tty: true
workingDir: /home/jenkins/agent
securityContext:
privileged: true
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
nodeSelector:
kubernetes.io/os: linux
restartPolicy: Never
volumes:
- name: workspace-volume
emptyDir: {}