7 Commits

3 changed files with 56 additions and 4 deletions

42
.jenkins/Jenkinsfile vendored
View File

@ -10,6 +10,7 @@ pipeline {
CLIENT_ID = 'c302726f-fafb-4143-94c1-67a70975574a'
DOCKER_REGISTRY_URL = 'marcin00.azurecr.io'
DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}"
DEPLOY_REPO = 'https://gitea.marcin00.pl/pikram/user-microservice-deploy.git'
}
stages {
@ -37,13 +38,46 @@ pipeline {
steps {
container('docker') {
sh '''
docker build -t ${DOCKER_IMAGE} .
az login --identity --client-id ${CLIENT_ID}
az acr login --name ${ACR_NAME}
docker push ${DOCKER_IMAGE}
docker build -t ${DOCKER_IMAGE} .
az login --identity --client-id ${CLIENT_ID}
az acr login --name ${ACR_NAME}
docker push ${DOCKER_IMAGE}
'''
}
}
}
stage('Commit new version to GitOps repo') {
steps {
container('git') {
sh '''
git config --global user.name "jenkins[bot]"
git config --global user.email "jenkins@marcin00.pl"
'''
sh 'git clone ${DEPLOY_REPO} --branch jenkins-kubernetes'
dir('user-microservice-deploy') {
sh '''
# Podmień tag obrazu w pliku deploy.yaml
awk -v commit="ssh-creds-id$GIT_COMMIT" '
$0 ~ /name:[[:space:]]*api/ { in_api_container = 1; print; next }
in_api_container && $0 ~ /^[[:space:]]*image:[[:space:]]*/ {
sub(/:[^:[:space:]]+$/, ":" commit)
in_api_container = 0
print
next
}
{ print }
' deploy.yaml > deploy.tmp && mv deploy.tmp deploy.yaml
'''
sh 'git commit -am "JENKINS: Changed deployed version to $GIT_COMMIT"'
sshagent(['gitea-deploy-key']) {
sh '''
git remote set-url origin ssh://git@srv22.mikr.us:20343/pikram/user-microservice-deploy.git
git push
'''
}
}
}
}
}
}
}

View File

@ -40,6 +40,16 @@ spec:
- name: workspace-volume
mountPath: /home/jenkins/agent
- name: git
image: alpine/git:latest
command:
- cat
tty: true
workingDir: /home/jenkins/agent
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
nodeSelector:
kubernetes.io/os: linux

View File

@ -2,6 +2,7 @@ from flask import Blueprint, jsonify, request, abort
from flask_jwt_extended import create_access_token, set_access_cookies, jwt_required, \
verify_jwt_in_request, get_jwt_identity, unset_jwt_cookies, get_jwt
from models import db, RevokedToken, User
import os
from utils import admin_required, validate_access, get_user_or_404
from werkzeug.security import check_password_hash, generate_password_hash
@ -110,3 +111,10 @@ def user_logout():
response = jsonify({"msg": "User logged out successfully."})
unset_jwt_cookies(response)
return response
@user_bp.route('/version', methods=['GET'])
def version():
return jsonify({
"version": os.getenv("APP_VERSION", "unknown"),
"build_time": os.getenv("BUILD_DATE", "unknown")
})