Compare commits

...

12 Commits

Author SHA1 Message Date
Marcin-Ramotowski
76a351710f Added variable APP_PORT to customize application port 2025-05-04 16:42:43 +00:00
Marcin-Ramotowski
c1f0da4a9c Extended Goss sleep 2025-05-04 15:37:47 +00:00
Marcin-Ramotowski
eefc952ff0 Updated app port in Goss YAML config 2025-05-04 15:26:21 +00:00
Marcin-Ramotowski
8c35b3bd8c Changed development server to production 2025-05-04 15:23:05 +00:00
Marcin-Ramotowski
60011b1c72 Added GOSS_SLEEP flag to wait for container full start before tests 2025-05-04 11:03:12 +00:00
Marcin-Ramotowski
859a962c12 Corrected python command name in Goss config YAML 2025-05-04 11:02:09 +00:00
Marcin-Ramotowski
0e9df4f859 Corrected command to run tests in Goss 2025-05-04 10:14:36 +00:00
Marcin-Ramotowski
1554404657 Corrected port to check in Goss YAML config 2025-05-04 10:14:18 +00:00
Marcin-Ramotowski
925af7d314 Corrected commands to test python app 2025-05-04 06:55:10 +00:00
Marcin-Ramotowski
fb260a0f6d Corrected directory in jenkins pipeline 2025-05-03 20:21:02 +00:00
Marcin-Ramotowski
dcd9a39b46 Corrected shell commands in jenkins pipeline 2025-05-03 20:05:32 +00:00
Marcin-Ramotowski
8194e3e9fe Added Jenkins pipeline to test code and container 2025-05-03 19:47:27 +00:00
4 changed files with 77 additions and 2 deletions

72
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,72 @@
pipeline {
agent any
environment {
DOCKER_REGISTRY_URL = 'marcin00.azurecr.io'
DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}"
ACR_NAME = 'marcin00'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Test python app') {
steps {
script {
dir('api') {
sh '''
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt pytest
python3 -m pytest --junit-xml=pytest_junit.xml
'''
}
}
}
post {
always {
junit testResults: '**/*pytest_junit.xml'
}
}
}
stage('Build & test docker image') {
steps {
script {
appImage = docker.build("${DOCKER_IMAGE}")
sh label: 'Install dgoss', script: '''
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 {
script {
sh '''
az login --identity
az acr login --name ${ACR_NAME}
docker push ${DOCKER_IMAGE}
'''
}
}
}
}
post {
cleanup {
script { cleanWs() }
}
}
}

View File

@ -61,5 +61,7 @@ def create_app(config_name="default"):
# Server start only if we run app directly # Server start only if we run app directly
if __name__ == "__main__": if __name__ == "__main__":
from waitress import serve
app = create_app() app = create_app()
app.run(host="0.0.0.0") port = os.getenv("APP_PORT", "80")
serve(app, host="0.0.0.0", port=port)

View File

@ -11,4 +11,5 @@ mysql-connector-python==9.2.0
python-dotenv==1.0.0 python-dotenv==1.0.0
SQLAlchemy==2.0.23 SQLAlchemy==2.0.23
typing_extensions==4.8.0 typing_extensions==4.8.0
waitress==3.0.2
Werkzeug==3.0.1 Werkzeug==3.0.1

View File

@ -4,5 +4,5 @@ port:
ip: ip:
- 0.0.0.0 - 0.0.0.0
process: process:
python: python3:
running: true running: true