// Copyright Avroid, Ltd. 2023-2024 // // You can not use the contents of the file in any way without // AVROID, Ltd. written permission. // // To obtain such a permit, you should contact AVROID, Ltd. // at https://avroid.ru @Library('shared-lib') _ // Pod configuration String buildThreads = '4' String podMemoryLimits = '6' String podMemoryRequests = '6' String harborProject = 'devops' String dockerImapSyncWrapperImageName = 'imapsync-wrapper' String dockerImapSyncWrapperImageTag = '1.0-10' // imapsync-wrapper configuration env.RUN_ID = currentBuild.number env.SOURCE_HOST_ADDRESS = 'mail.avroid.tech' env.DESTINATION_HOST_ADDRESS = 'mail.avroid.team' env.MAXIMUM_ERRORS_ALLOW = '10' env.MAX_BYTES_PER_SECOND = '5000000' env.MAX_MESSAGES_PER_SECOND = '10' env.PG_HOST = 'h-postgres-imapsync.avroid.tech' env.PG_PORT = '5432' env.PG_DBNAME = 'imapsync' // Get PG configuration from HVault def configuration = [ vaultUrl: 'https://vault.avroid.tech', vaultCredentialId: 'vault-role', engineVersion: 2 ] def dbSecrets = [ [path: 'team-devops/services/databases/postgres/h-postgres-imapsync.avroid.tech', engineVersion: 2, secretValues: [ [vaultKey: 'db_user_imapsync_login'], [vaultKey: 'db_user_imapsync_password'], ] ] ] properties([ buildDiscarder(logRotator(artifactNumToKeepStr: '1', numToKeepStr: '300')), parameters([ string(name: 'MAILBOX_NAME', defaultValue: 'ivan.ivanov', description: 'Укажите свою доменную учетную запись. Пример: ivan.ivanov'), password(name: 'MAIL_PASSWORD', description: 'Введите пароль от учетной записи.'), ]) ]) // Let the user to input mail without domain or with domain env.SOURCE_HOST_USER = params.MAILBOX_NAME.split('@')[0].trim() + "@avroid.tech" // Destination uses user's name without domain env.DESTINATION_HOST_USER = params.MAILBOX_NAME.split('@')[0] podTemplate(yaml: """ apiVersion: v1 kind: Pod spec: containers: - name: linux image: $env.JENKINS_DOCKER_REGISTRY/${harborProject}/${dockerImapSyncWrapperImageName}:${dockerImapSyncWrapperImageTag} command: - sleep args: - 5d resources: limits: cpu: ${buildThreads} memory: ${podMemoryLimits}Gi requests: cpu: ${buildThreads} memory: ${podMemoryRequests}Gi imagePullSecrets: - name: $env.JENKINS_K8S_HARBOR_SECRET """ ){ node(POD_LABEL) { timestamps { timeout(time:3, unit:'HOURS') { try { container(name: 'linux') { stage('Build') { wrap([$class: "MaskPasswordsBuildWrapper", varPasswordPairs: [[password: params.MAIL_PASSWORD]]]) { withVault([configuration: configuration, vaultSecrets: dbSecrets]) { sh ''' python3 /app/main.py \ --run_id $RUN_ID \ --source_host_address $SOURCE_HOST_ADDRESS \ --source_host_user $SOURCE_HOST_USER \ --source_host_pass $MAIL_PASSWORD \ --destination_host_address $DESTINATION_HOST_ADDRESS \ --destination_host_user $DESTINATION_HOST_USER \ --destination_pass $MAIL_PASSWORD \ --maximum_errors_allow $MAXIMUM_ERRORS_ALLOW \ --max_bytes_per_second $MAX_BYTES_PER_SECOND \ --max_messages_per_second $MAX_MESSAGES_PER_SECOND \ --pg_host $PG_HOST \ --pg_port $PG_PORT \ --pg_dbname $PG_DBNAME \ --pg_username $db_user_imapsync_login \ --pg_password $db_user_imapsync_password ''' } } } } } catch (err) { println 'ERROR: ' + err.getMessage() currentBuild.result = 'FAILURE' } finally { currentBuild.description = "${env.DESTINATION_HOST_USER}" } } } } }