From 4a72e8bab62d15592e0c9128974396012db692b3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 8 May 2024 17:25:31 +0300 Subject: [PATCH 001/241] python project complated --- polybot/app.py | 27 ----- polybot/bot.py | 225 +++++++++++++++++++++++------------ polybot/img_proc.py | 248 +++++++++++++++++++++++++++++---------- polybot/requirements.txt | 5 - requirements.txt | 64 ++++++++++ 5 files changed, 401 insertions(+), 168 deletions(-) delete mode 100644 polybot/app.py delete mode 100644 polybot/requirements.txt create mode 100644 requirements.txt diff --git a/polybot/app.py b/polybot/app.py deleted file mode 100644 index e88600d1..00000000 --- a/polybot/app.py +++ /dev/null @@ -1,27 +0,0 @@ -import flask -from flask import request -import os -from bot import Bot, QuoteBot, ImageProcessingBot - -app = flask.Flask(__name__) - -TELEGRAM_TOKEN = os.environ['TELEGRAM_TOKEN'] -TELEGRAM_APP_URL = os.environ['TELEGRAM_APP_URL'] - - -@app.route('/', methods=['GET']) -def index(): - return 'Ok' - - -@app.route(f'/{TELEGRAM_TOKEN}/', methods=['POST']) -def webhook(): - req = request.get_json() - bot.handle_message(req['message']) - return 'Ok' - - -if __name__ == "__main__": - bot = ImageProcessingBot(TELEGRAM_TOKEN, TELEGRAM_APP_URL) - - app.run(host='0.0.0.0', port=8443) diff --git a/polybot/bot.py b/polybot/bot.py index 7fea847b..7200dba8 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -1,78 +1,153 @@ import telebot -from loguru import logger -import os -import time -from telebot.types import InputFile +import cv2 from polybot.img_proc import Img +from dotenv import load_dotenv +import os - -class Bot: - - def __init__(self, token, telegram_chat_url): - # create a new instance of the TeleBot class. - # all communication with Telegram servers are done using self.telegram_bot_client - self.telegram_bot_client = telebot.TeleBot(token) - - # remove any existing webhooks configured in Telegram servers - self.telegram_bot_client.remove_webhook() - time.sleep(0.5) - - # set the webhook URL - self.telegram_bot_client.set_webhook(url=f'{telegram_chat_url}/{token}/', timeout=60) - - logger.info(f'Telegram Bot information\n\n{self.telegram_bot_client.get_me()}') - - def send_text(self, chat_id, text): - self.telegram_bot_client.send_message(chat_id, text) - - def send_text_with_quote(self, chat_id, text, quoted_msg_id): - self.telegram_bot_client.send_message(chat_id, text, reply_to_message_id=quoted_msg_id) - - def is_current_msg_photo(self, msg): - return 'photo' in msg - - def download_user_photo(self, msg): - """ - Downloads the photos that sent to the Bot to `photos` directory (should be existed) - :return: - """ - if not self.is_current_msg_photo(msg): - raise RuntimeError(f'Message content of type \'photo\' expected') - - file_info = self.telegram_bot_client.get_file(msg['photo'][-1]['file_id']) - data = self.telegram_bot_client.download_file(file_info.file_path) - folder_name = file_info.file_path.split('/')[0] - - if not os.path.exists(folder_name): - os.makedirs(folder_name) - - with open(file_info.file_path, 'wb') as photo: - photo.write(data) - - return file_info.file_path - - def send_photo(self, chat_id, img_path): - if not os.path.exists(img_path): - raise RuntimeError("Image path doesn't exist") - - self.telegram_bot_client.send_photo( - chat_id, - InputFile(img_path) - ) - - def handle_message(self, msg): - """Bot Main message handler""" - logger.info(f'Incoming message: {msg}') - self.send_text(msg['chat']['id'], f'Your original message: {msg["text"]}') - - -class QuoteBot(Bot): - def handle_message(self, msg): - logger.info(f'Incoming message: {msg}') - - if msg["text"] != 'Please don\'t quote me': - self.send_text_with_quote(msg['chat']['id'], msg["text"], quoted_msg_id=msg["message_id"]) - - -class ImageProcessingBot(Bot): - pass +# load environment variables +load_dotenv() +TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN') + +# Check if TELEGRAM_TOKEN is not none +if TELEGRAM_TOKEN is None: + print("Error: TELEGRAM_TOKEN is not set in the .env file.") + exit(1) + +# initialize telegram-bot +bot = telebot.TeleBot(TELEGRAM_TOKEN) + +# Dictionary to store images temporarily +user_images = {} + +# handler for the /start command +@bot.message_handler(commands=['start']) +def handle_start(message): + bot.send_message(message.chat.id, "Hello!\n\n Send me an image then choose a filter , options:\n" + "- Blur: Apply a blur to the image to reduce noise and detail.\n" + "- Rotate: turning the image upside down.\n" + "- Salt and Pepper: Adds random bright and dark pixels to an image.\n" + "- Segment: Divides an image into parts based on color.\n" + "- Grayscale: Converts the image to grayscale.\n" + "- Sharpen: Enhances the edges and details in the image.\n" + "- Emboss: Creates a raised effect by highlighting the edges.\n" + "- Invert Colors: Inverts the colors of the image.\n" + "- Oil Painting: Applies an oil painting-like effect to the image.\n" + "- Cartoonize: Creates a cartoon-like version of the image.\n") + +# handler for receiving photos +@bot.message_handler(content_types=['photo']) +def handle_image(message): + try: + print("Received a photo message") + # get the photo file id + file_id = message.photo[-1].file_id + # get the file object using the file id + file_info = bot.get_file(file_id) + # download the file + downloaded_file = bot.download_file(file_info.file_path) + + # save the file temporarily with a unique name based on the file id + image_path = f"images/{file_id}.jpg" + with open(image_path, 'wb') as new_file: + new_file.write(downloaded_file) + + # check if this is the first img or the second img for concat + if message.chat.id in user_images: + print("User already has an image in memory") + if 'concat_pending' in user_images[message.chat.id]: + print("This is the second image for concatenation") + # this is the second image for concat + second_image_path = image_path + first_image_path = user_images[message.chat.id]['concat_pending'] + del user_images[message.chat.id]['concat_pending'] # remove the pending to free it to next pending + + # load the images + first_image_data = cv2.imread(first_image_path) + second_image_data = cv2.imread(second_image_path) + + # concat the imges + img_processor = Img(first_image_path) + concatenated_image = img_processor.concat(second_image_data) + if concatenated_image is not None: + print("Concatenation successful") + # save and send the concat img + processed_image_path = img_processor.save_image(concatenated_image, suffix='_concatenated') + with open(processed_image_path, 'rb') as photo_file: + bot.send_photo(message.chat.id, photo_file) + else: + print("Error concatenating images.") + bot.reply_to(message, "Error concatenating images.") + + # clear user history + del user_images[message.chat.id] + else: + # this is the first img + print("This is the first image for concatenation") + user_images[message.chat.id]['concat_pending'] = image_path + bot.reply_to(message, "First image saved successfully! Now please send the second image to concatenate with.") + else: + # this is the first img + print("This is the first image received") + user_images[message.chat.id] = {'concat_pending': image_path} + bot.reply_to(message, "First image saved successfully! To apply the concatenation filter, please send another image or choose a filter from the list at the top of the page to apply a filter.") + except Exception as e: + print(f"Error handling image: {e}") + bot.reply_to(message, f"Error handling image: {e}") + +# handler for filter selection +@bot.message_handler(func=lambda message: message.text.lower() in ['blur', 'rotate', 'salt and pepper', 'segment','grayscale','sharpen','emboss','invert colors','oil painting','cartoonize']) +def handle_filter(message): + try: + # Check if the user has previously sent an image + if message.chat.id in user_images: + # Get the image path + if 'concat_pending' in user_images[message.chat.id]: + image_path = user_images[message.chat.id]['concat_pending'] + else: + image_path = user_images[message.chat.id]['first_image'] + + # apply the selected filter + img_processor = Img(image_path) + filter_name = message.text.lower() + + if filter_name == 'blur': + processed_image = img_processor.blur() + elif filter_name == 'rotate': + processed_image = img_processor.rotate() + elif filter_name == 'salt and pepper': + processed_image = img_processor.salt_n_pepper() + elif filter_name == 'segment': + processed_image = img_processor.segment() + elif filter_name == 'grayscale': + processed_image = img_processor.grayscale() + elif filter_name == 'sharpen': + processed_image = img_processor.sharpen() + elif filter_name == 'emboss': + processed_image = img_processor.emboss() + elif filter_name == 'invert colors': + processed_image = img_processor.invert_colors() + elif filter_name == 'oil painting': + processed_image = img_processor.oil_painting() + elif filter_name == 'cartoonize': + processed_image = img_processor.cartoonize() + else: + processed_image = None + + # check if the filter was applied successfully + if processed_image is not None: + # save and send the processed image + processed_image_path = img_processor.save_image(processed_image, suffix=f'_{filter_name.replace(" ", "_")}') + with open(processed_image_path, 'rb') as photo_file: + bot.send_photo(message.chat.id, photo_file) + else: + bot.reply_to(message, f"Error applying {filter_name} filter: Result is None.") + + # remove the image path from the dict + del user_images[message.chat.id] + else: + bot.reply_to(message, "Please send an image first.") + except Exception as e: + bot.reply_to(message, f"Error processing image: {e}") + + +bot.polling() \ No newline at end of file diff --git a/polybot/img_proc.py b/polybot/img_proc.py index 137ca70d..cb7005c5 100644 --- a/polybot/img_proc.py +++ b/polybot/img_proc.py @@ -1,67 +1,193 @@ -from pathlib import Path -from matplotlib.image import imread, imsave - - -def rgb2gray(rgb): - r, g, b = rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2] - gray = 0.2989 * r + 0.5870 * g + 0.1140 * b - return gray - +import os +import cv2 +import numpy as np class Img: - - def __init__(self, path): - """ - Do not change the constructor implementation - """ - self.path = Path(path) - self.data = rgb2gray(imread(path)).tolist() - - def save_img(self): - """ - Do not change the below implementation - """ - new_path = self.path.with_name(self.path.stem + '_filtered' + self.path.suffix) - imsave(new_path, self.data, cmap='gray') - return new_path + def __init__(self, image_path): + self.image_path = image_path + self.image_data = self.load_image() + + def load_image(self): + try: + image = cv2.imread(self.image_path) + if image is not None: + return image + else: + raise FileNotFoundError("Unable to load image.") + except Exception as e: + print(f"Error loading image: {e}") + return None + + def save_image(self, image_data, suffix='_filtered'): + try: + directory = 'images' + if not os.path.exists(directory): + os.makedirs(directory) + + file_path = os.path.join(directory, f"{os.path.basename(self.image_path).split('.')[0]}{suffix}.jpg") + cv2.imwrite(file_path, image_data) + print(f"Image saved successfully: {file_path}") + return file_path + except Exception as e: + print(f"Error saving image: {e}") + return None def blur(self, blur_level=16): - - height = len(self.data) - width = len(self.data[0]) - filter_sum = blur_level ** 2 - - result = [] - for i in range(height - blur_level + 1): - row_result = [] - for j in range(width - blur_level + 1): - sub_matrix = [row[j:j + blur_level] for row in self.data[i:i + blur_level]] - average = sum(sum(sub_row) for sub_row in sub_matrix) // filter_sum - row_result.append(average) - result.append(row_result) - - self.data = result - - def contour(self): - for i, row in enumerate(self.data): - res = [] - for j in range(1, len(row)): - res.append(abs(row[j-1] - row[j])) - - self.data[i] = res + try: + if self.image_data is None: + raise ValueError("No image data available.") + blur_level = max(1, blur_level) + blur_level = blur_level + 1 if blur_level % 2 == 0 else blur_level + blurred_image = cv2.GaussianBlur(self.image_data, (blur_level, blur_level), 0) + return blurred_image + except Exception as e: + print(f"Error applying blur: {e}") + return None def rotate(self): - # TODO remove the `raise` below, and write your implementation - raise NotImplementedError() - - def salt_n_pepper(self): - # TODO remove the `raise` below, and write your implementation - raise NotImplementedError() - - def concat(self, other_img, direction='horizontal'): - # TODO remove the `raise` below, and write your implementation - raise NotImplementedError() - - def segment(self): - # TODO remove the `raise` below, and write your implementation - raise NotImplementedError() + try: + img = cv2.imread(self.image_path) + if img is None: + raise FileNotFoundError("Unable to load image.") + rotated_img = cv2.rotate(img, cv2.ROTATE_180) + return rotated_img + except Exception as e: + print(f"Error rotating image: {e}") + return None + + def salt_n_pepper(self, amount=0.05): + try: + if self.image_data is None: + raise ValueError("No image data available.") + noisy_image = self.image_data.copy() + mask = np.random.choice([0, 1, 2], size=noisy_image.shape[:2], p=[amount / 2, amount / 2, 1 - amount]) + noisy_image[mask == 0] = 0 + noisy_image[mask == 1] = 255 + return noisy_image + except Exception as e: + print(f"Error adding salt and pepper noise: {e}") + return None + + def concat(self, other_image_data, direction='horizontal'): + try: + if self.image_data is None or other_image_data is None: + raise ValueError("Image data is missing.") + + if direction not in ['horizontal', 'vertical']: + raise ValueError("Invalid direction. Please use 'horizontal' or 'vertical'.") + + if direction == 'horizontal': + concatenated_img = np.concatenate((self.image_data, other_image_data), axis=1) + else: + concatenated_img = np.concatenate((self.image_data, other_image_data), axis=0) + + return concatenated_img + except Exception as e: + print(f"Error concatenating images: {e}") + return None + + def segment(self, num_clusters=100): + try: + if self.image_data is None: + raise ValueError("No image data available.") + + image_rgb = cv2.cvtColor(self.image_data, cv2.COLOR_BGR2RGB) + pixels = image_rgb.reshape((-1, 3)) + pixels = np.float32(pixels) + + criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.2) + _, labels, centers = cv2.kmeans(pixels, num_clusters, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS) + + centers = np.uint8(centers) + segmented_image = centers[labels.flatten()] + segmented_image = segmented_image.reshape(image_rgb.shape) + + # Convert segmented image back to BGR format + segmented_image_bgr = cv2.cvtColor(segmented_image, cv2.COLOR_RGB2BGR) + + # Darken the segmented image + segmented_image_bgr = segmented_image_bgr * 0.5 # Reduce brightness by 50% + + return segmented_image_bgr + except Exception as e: + print(f"Error segmenting image: {e}") + return None + + + + def grayscale(self): + try: + if self.image_data is None: + raise ValueError("No image data available.") + gray_image = cv2.cvtColor(self.image_data, cv2.COLOR_BGR2GRAY) + return cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR) + except Exception as e: + print(f"Error converting image to grayscale: {e}") + return None + + def sharpen(self): + try: + if self.image_data is None: + raise ValueError("No image data available.") + kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]]) + sharpened_image = cv2.filter2D(self.image_data, -1, kernel) + return sharpened_image + except Exception as e: + print(f"Error applying sharpen filter: {e}") + return None + + def emboss(self): + try: + if self.image_data is None: + raise ValueError("No image data available.") + kernel = np.array([[0, -1, -1], [1, 0, -1], [1, 1, 0]]) + embossed_image = cv2.filter2D(self.image_data, -1, kernel) + return embossed_image + except Exception as e: + print(f"Error applying emboss filter: {e}") + return None + + def invert_colors(self): + try: + if self.image_data is None: + raise ValueError("No image data available.") + inverted_image = cv2.bitwise_not(self.image_data) + return inverted_image + except Exception as e: + print(f"Error inverting colors: {e}") + return None + + def oil_painting(self, size=7, dynRatio=0.2): + try: + if self.image_data is None: + raise ValueError("No image data available.") + + # Convert image to grayscale + gray_image = cv2.cvtColor(self.image_data, cv2.COLOR_BGR2GRAY) + + # Apply median blur to create a smoother image + blurred_image = cv2.medianBlur(gray_image, size) + + # Apply adaptive threshold to create a binary image + _, mask = cv2.threshold(blurred_image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) + + # Create an output image using bitwise and operation with original image + oil_painting_effect = cv2.bitwise_and(self.image_data, self.image_data, mask=mask) + + return oil_painting_effect + except Exception as e: + print(f"Error applying oil painting effect: {e}") + return None + def cartoonize(self): + try: + if self.image_data is None: + raise ValueError("No image data available.") + gray_image = cv2.cvtColor(self.image_data, cv2.COLOR_BGR2GRAY) + blurred_image = cv2.medianBlur(gray_image, 7) + edges = cv2.adaptiveThreshold(blurred_image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9) + color = cv2.bilateralFilter(self.image_data, 9, 300, 300) + cartoon_image = cv2.bitwise_and(color, color, mask=edges) + return cartoon_image + except Exception as e: + print(f"Error cartoonizing image: {e}") + return None \ No newline at end of file diff --git a/polybot/requirements.txt b/polybot/requirements.txt deleted file mode 100644 index dbab2768..00000000 --- a/polybot/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pyTelegramBotAPI>=4.12.0 -loguru>=0.7.0 -requests>=2.31.0 -flask>=2.3.2 -matplotlib \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..10d3c570 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,64 @@ +anyio==4.3.0 +asgiref==3.8.1 +astroid==3.1.0 +backports.zoneinfo==0.2.1 +blinker==1.7.0 +certifi==2024.2.2 +charset-normalizer==3.3.2 +class-registry==2.1.2 +click==8.1.7 +colorama==0.4.6 +contourpy==1.1.1 +cycler==0.12.1 +dill==0.3.8 +Django==4.2.11 +django-request==1.6.3 +exceptiongroup==1.2.1 +filters==1.3.2 +Flask==3.0.2 +fonttools==4.51.0 +h11==0.14.0 +httpcore==1.0.5 +httpx==0.27.0 +idna==3.6 +img==2.5 +importlib-metadata==7.0.1 +importlib_resources==6.4.0 +isort==5.13.2 +itsdangerous==2.1.2 +Jinja2==3.1.3 +kiwisolver==1.4.5 +loguru==0.7.2 +MarkupSafe==2.1.5 +matplotlib==3.7.5 +mccabe==0.7.0 +numpy==1.24.4 +opencv-python==4.9.0.80 +packaging==24.0 +pillow==10.3.0 +platformdirs==4.2.0 +pylint==3.1.0 +pyparsing==3.1.2 +pyTelegramBotAPI==4.16.1 +python-dateutil==2.9.0.post0 +python-dotenv==1.0.1 +python-telegram-bot==21.1.1 +pytz==2024.1 +regex==2024.4.16 +requests==2.31.0 +rfc3986==1.5.0 +six==1.16.0 +sniffio==1.3.1 +sqlparse==0.5.0 +style==1.1.0 +telebot==0.0.5 +tomli==2.0.1 +tomlkit==0.12.4 +typing_extensions==4.10.0 +tzdata==2024.1 +update==0.0.1 +urllib3==2.2.1 +vboxapi==1.0 +Werkzeug==3.0.1 +win32-setctime==1.1.0 +zipp==3.17.0 From 1ce957d2c4dad878a0e17d7263ec7e13706ffb5c Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 20:05:15 +0300 Subject: [PATCH 002/241] jenkins --- jenkis_try/try.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 jenkis_try/try.py diff --git a/jenkis_try/try.py b/jenkis_try/try.py new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/jenkis_try/try.py @@ -0,0 +1 @@ +hello From 6ff659214a49b704370b527208a4a9410de20a0a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 20:11:06 +0300 Subject: [PATCH 003/241] jenkins2 --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index ce013625..63fa236c 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -hello +hello22 From 136c8ead589f78b6a59d2a89a7285550404814e8 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 20:39:05 +0300 Subject: [PATCH 004/241] jenkins12 --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index 63fa236c..a68cc78b 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -hello22 +hello21312 From 74fb182dc486fe5bc1f5fd2f76e32345f841d6f7 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 20:48:48 +0300 Subject: [PATCH 005/241] jenkins1122 --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index a68cc78b..e7f3776d 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -hello21312 +hello1212 From ef4e989caa6849dacc9502265eab5d0b31c90f5f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 20:53:35 +0300 Subject: [PATCH 006/241] jenkins1111212 --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index e7f3776d..3c902c8d 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -hello1212 +hello121211212121 From 9b59e57e1db64631bef42bfc60d7bb3089e652d7 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 21:03:38 +0300 Subject: [PATCH 007/241] jenk --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index 3c902c8d..31fc20fb 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -hello121211212121 +he From ef8a7358effa089da75214d213bf41be588239e9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 21:05:11 +0300 Subject: [PATCH 008/241] jenk1 --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index 31fc20fb..3c86b35c 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -he +he22 From 3dbc758791dc131ebe0d0e414081662469dc9174 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 29 May 2024 21:08:55 +0300 Subject: [PATCH 009/241] jenk211 --- jenkis_try/try.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkis_try/try.py b/jenkis_try/try.py index 3c86b35c..2971aa06 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -he22 +he2112 From 8a45a1ccee8937e9da377eb1833cabb71744f5f9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 17:51:43 +0300 Subject: [PATCH 010/241] build_dockerfile --- build_Jenkinsfile | 17 +++++++++++++++++ jenkis_try/try.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 build_Jenkinsfile diff --git a/build_Jenkinsfile b/build_Jenkinsfile new file mode 100644 index 00000000..4acd0fa2 --- /dev/null +++ b/build_Jenkinsfile @@ -0,0 +1,17 @@ +pipeline{ + + agent any + stages { + + stage('Build docker image'){ + steps { + sh''' + + ''' + } + + } + +} + +} diff --git a/jenkis_try/try.py b/jenkis_try/try.py index 2971aa06..ca79f4b1 100644 --- a/jenkis_try/try.py +++ b/jenkis_try/try.py @@ -1 +1 @@ -he2112 +he21122 From 7f4cf48fb4f287b151031434e4d91500bc8f3e70 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:17:43 +0300 Subject: [PATCH 011/241] change file --- build.Jenkinsfile | 13 +++++++++++++ build_Jenkinsfile | 17 ----------------- 2 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 build.Jenkinsfile delete mode 100644 build_Jenkinsfile diff --git a/build.Jenkinsfile b/build.Jenkinsfile new file mode 100644 index 00000000..240b9ca6 --- /dev/null +++ b/build.Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent any + stages { + stage('Build docker image') { + steps { + sh ''' + echo "hello world" + ''' + + } + } + } +} \ No newline at end of file diff --git a/build_Jenkinsfile b/build_Jenkinsfile deleted file mode 100644 index 4acd0fa2..00000000 --- a/build_Jenkinsfile +++ /dev/null @@ -1,17 +0,0 @@ -pipeline{ - - agent any - stages { - - stage('Build docker image'){ - steps { - sh''' - - ''' - } - - } - -} - -} From 8312f445360083ef4f2fc784e7abd4e62cea5b7e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:19:24 +0300 Subject: [PATCH 012/241] change file2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 240b9ca6..f820e7f5 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -4,7 +4,7 @@ pipeline { stage('Build docker image') { steps { sh ''' - echo "hello world" + echo "hello world2" ''' } From 28ebfa7e3149142c00194337a81722e2dc108b35 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:20:14 +0300 Subject: [PATCH 013/241] change files --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index f820e7f5..5e980c3e 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -4,7 +4,7 @@ pipeline { stage('Build docker image') { steps { sh ''' - echo "hello world2" + echo "hello world tt" ''' } From 374169d43dcc0084369797c8c20267becd70bafe Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:22:45 +0300 Subject: [PATCH 014/241] hh --- hh.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 hh.txt diff --git a/hh.txt b/hh.txt new file mode 100644 index 00000000..0107e44b --- /dev/null +++ b/hh.txt @@ -0,0 +1 @@ +sa \ No newline at end of file From 5b1b24b64aefd5c573725964a72a4e19c8322630 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:31:23 +0300 Subject: [PATCH 015/241] hh2 --- Dockerfile | 8 ++++++++ hh.txt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..690d924b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.10.12-slim-bullseye +WORKDIR /app +COPY requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python3","polybot/bot.py"] \ No newline at end of file diff --git a/hh.txt b/hh.txt index 0107e44b..0f3410a0 100644 --- a/hh.txt +++ b/hh.txt @@ -1 +1 @@ -sa \ No newline at end of file +sa22 \ No newline at end of file From 90dffb317b81a9198c3053973e0cb188bcd83cea Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:41:19 +0300 Subject: [PATCH 016/241] hh2 --- build.Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 5e980c3e..736c0df1 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -4,7 +4,10 @@ pipeline { stage('Build docker image') { steps { sh ''' - echo "hello world tt" + cd polybot + docker build -t polybot:${BUILD_NUMBER} . + docker push docker push beny14/polybot:${BUILD_NUMBER} + ''' } From c37ff86ee072a3bcc693077227636adbf7e054bf Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:42:23 +0300 Subject: [PATCH 017/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 736c0df1..52e4ee1e 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,7 +3,7 @@ pipeline { stages { stage('Build docker image') { steps { - sh ''' + bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . docker push docker push beny14/polybot:${BUILD_NUMBER} From b0622aac75ca1b1982cfc79ba21a18fa24efad83 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:44:38 +0300 Subject: [PATCH 018/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 52e4ee1e..2e621b23 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,7 +6,7 @@ pipeline { bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . - docker push docker push beny14/polybot:${BUILD_NUMBER} + docker push docker push beny14/[polybot:${BUILD_NUMBER}] ''' From 912edfc150e5d8a2052c80244326f290990c62fe Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:45:39 +0300 Subject: [PATCH 019/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 2e621b23..14675f2a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,7 +6,7 @@ pipeline { bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . - docker push docker push beny14/[polybot:${BUILD_NUMBER}] + docker push beny14/polybot:${BUILD_NUMBER} ''' From 831e21bc8a05f2afb1381391d61256fde0e1839c Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:46:36 +0300 Subject: [PATCH 020/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 14675f2a..af4f048f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,7 +6,7 @@ pipeline { bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . - docker push beny14/polybot:${BUILD_NUMBER} + docker push beny14/repo1:${BUILD_NUMBER} ''' From ed21a1d80feb94d0ac7fde79b5723b4206139366 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:47:24 +0300 Subject: [PATCH 021/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index af4f048f..deb85819 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,7 +6,7 @@ pipeline { bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . - docker push beny14/repo1:${BUILD_NUMBER} + docker push beny14/repo1:polybot ''' From 5ae9e5e84470edd5a4f5e61b5aaca36fcba69f7b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:52:58 +0300 Subject: [PATCH 022/241] hh2 --- build.Jenkinsfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index deb85819..a5a30b8b 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,6 +6,14 @@ pipeline { bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . + REM Change directory to where Docker executable is located + cd "C:\Program Files\Docker" + + REM Run Docker with elevated privileges + docker.exe %* + + + docker push beny14/repo1:polybot ''' From 3370b28dfa80d90dc17e422a112b7f93addc48c3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 18:54:13 +0300 Subject: [PATCH 023/241] hh2 --- build.Jenkinsfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a5a30b8b..76c693e8 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,10 +6,6 @@ pipeline { bat ''' cd polybot docker build -t polybot:${BUILD_NUMBER} . - REM Change directory to where Docker executable is located - cd "C:\Program Files\Docker" - - REM Run Docker with elevated privileges docker.exe %* From 09cb389503c95e13d1088ead030ad1b805ac7ba9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:14:17 +0300 Subject: [PATCH 024/241] hh2 --- build.Jenkinsfile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 76c693e8..99914d1a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,16 +3,13 @@ pipeline { stages { stage('Build docker image') { steps { - bat ''' - cd polybot - docker build -t polybot:${BUILD_NUMBER} . - docker.exe %* - - - - docker push beny14/repo1:polybot - - ''' + bat ''' + cd polybot + docker build -t beny14/repo1:polybot-${BUILD_NUMBER} . + docker login -u beny14 + docker push beny14/repo1:polybot-${BUILD_NUMBER} + ''' +} } } From 75d4919802e23b3bb3aa1e06bf17746f7be852d0 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:15:04 +0300 Subject: [PATCH 025/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 99914d1a..8838bcd6 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -9,7 +9,7 @@ pipeline { docker login -u beny14 docker push beny14/repo1:polybot-${BUILD_NUMBER} ''' -} + } } From 2688e3d5842e1d1d418aafc3e6b1aa37926c6924 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:28:52 +0300 Subject: [PATCH 026/241] hh2 --- build.Jenkinsfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 8838bcd6..8363586e 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,14 +3,19 @@ pipeline { stages { stage('Build docker image') { steps { + withCredentials( + [usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')] + ) { bat ''' cd polybot - docker build -t beny14/repo1:polybot-${BUILD_NUMBER} . - docker login -u beny14 + docker login -u $USERNAME -p $USERPASS + docker build -t polybot:${BUILD_NUMBER} . + docker push beny14/repo1:polybot-${BUILD_NUMBER} ''' + } } } } From 38fc2349cd956e243dc881f3f0beb56de8e96fba Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:30:58 +0300 Subject: [PATCH 027/241] hh2 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 690d924b..bf8362df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.10.12-slim-bullseye -WORKDIR /app +WORKDIR /tt COPY requirements.txt RUN pip install --no-cache-dir -r requirements.txt From 706178ed64bc0442598f3675f2da943a5209ec4a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:33:11 +0300 Subject: [PATCH 028/241] hh2 --- hh.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hh.txt b/hh.txt index 0f3410a0..5422d91d 100644 --- a/hh.txt +++ b/hh.txt @@ -1 +1 @@ -sa22 \ No newline at end of file +sa22sasa \ No newline at end of file From bef053fdbcedecabd981517b5f6af3733d2b4dde Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:35:18 +0300 Subject: [PATCH 029/241] hh2 --- build.Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 8363586e..6ec8a8b7 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -7,11 +7,12 @@ pipeline { [usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')] ) { bat ''' - cd polybot - docker login -u $USERNAME -p $USERPASS - docker build -t polybot:${BUILD_NUMBER} . + @echo off + cd polybot + docker login -u %USERNAME% -p %USERPASS% + docker build -t polybot:%BUILD_NUMBER% . - docker push beny14/repo1:polybot-${BUILD_NUMBER} + docker push beny14/repo1:polybot-%BUILD_NUMBER% ''' From 90fa44108c656afc46203ef20432ed87e6f2d393 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:43:21 +0300 Subject: [PATCH 030/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 6ec8a8b7..cedf054b 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -9,7 +9,7 @@ pipeline { bat ''' @echo off cd polybot - docker login -u %USERNAME% -p %USERPASS% + docker login -u %USERNAME% -p %USERPASS% --password-stdin docker build -t polybot:%BUILD_NUMBER% . docker push beny14/repo1:polybot-%BUILD_NUMBER% From a83f9fe2f7e3ab6d1a86031496816614a6a8b54d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:45:04 +0300 Subject: [PATCH 031/241] hh2 --- polybot/Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 polybot/Dockerfile diff --git a/polybot/Dockerfile b/polybot/Dockerfile new file mode 100644 index 00000000..bf8362df --- /dev/null +++ b/polybot/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.10.12-slim-bullseye +WORKDIR /tt +COPY requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python3","polybot/bot.py"] \ No newline at end of file From 6c47977ae3d00e87edba370e5a7fe68c267fbef3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:47:29 +0300 Subject: [PATCH 032/241] hh2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index cedf054b..964fc134 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -12,7 +12,7 @@ pipeline { docker login -u %USERNAME% -p %USERPASS% --password-stdin docker build -t polybot:%BUILD_NUMBER% . - docker push beny14/repo1:polybot-%BUILD_NUMBER% + docker push beny14/repo1:polybot ''' From 6eba20933f2df80937e366221002f610befb9194 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 19:53:12 +0300 Subject: [PATCH 033/241] hh2 --- polybot/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index bf8362df..85dbab1c 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.10.12-slim-bullseye WORKDIR /tt -COPY requirements.txt +COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . From 0df2894db10722cbcedde0d5eb9325ffa0f7258a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:06:07 +0300 Subject: [PATCH 034/241] hh2 --- polybot/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 85dbab1c..ec511868 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.10.12-slim-bullseye -WORKDIR /tt +WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt From eee677f306c1654f5e3a8e4a32d73f500d09a90f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:07:21 +0300 Subject: [PATCH 035/241] hh2 --- polybot/requirements.txt | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 polybot/requirements.txt diff --git a/polybot/requirements.txt b/polybot/requirements.txt new file mode 100644 index 00000000..10d3c570 --- /dev/null +++ b/polybot/requirements.txt @@ -0,0 +1,64 @@ +anyio==4.3.0 +asgiref==3.8.1 +astroid==3.1.0 +backports.zoneinfo==0.2.1 +blinker==1.7.0 +certifi==2024.2.2 +charset-normalizer==3.3.2 +class-registry==2.1.2 +click==8.1.7 +colorama==0.4.6 +contourpy==1.1.1 +cycler==0.12.1 +dill==0.3.8 +Django==4.2.11 +django-request==1.6.3 +exceptiongroup==1.2.1 +filters==1.3.2 +Flask==3.0.2 +fonttools==4.51.0 +h11==0.14.0 +httpcore==1.0.5 +httpx==0.27.0 +idna==3.6 +img==2.5 +importlib-metadata==7.0.1 +importlib_resources==6.4.0 +isort==5.13.2 +itsdangerous==2.1.2 +Jinja2==3.1.3 +kiwisolver==1.4.5 +loguru==0.7.2 +MarkupSafe==2.1.5 +matplotlib==3.7.5 +mccabe==0.7.0 +numpy==1.24.4 +opencv-python==4.9.0.80 +packaging==24.0 +pillow==10.3.0 +platformdirs==4.2.0 +pylint==3.1.0 +pyparsing==3.1.2 +pyTelegramBotAPI==4.16.1 +python-dateutil==2.9.0.post0 +python-dotenv==1.0.1 +python-telegram-bot==21.1.1 +pytz==2024.1 +regex==2024.4.16 +requests==2.31.0 +rfc3986==1.5.0 +six==1.16.0 +sniffio==1.3.1 +sqlparse==0.5.0 +style==1.1.0 +telebot==0.0.5 +tomli==2.0.1 +tomlkit==0.12.4 +typing_extensions==4.10.0 +tzdata==2024.1 +update==0.0.1 +urllib3==2.2.1 +vboxapi==1.0 +Werkzeug==3.0.1 +win32-setctime==1.1.0 +zipp==3.17.0 From 2ac64b0e53afc76282ab87a4ce84fe75c8cb9b10 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:22:34 +0300 Subject: [PATCH 036/241] hh2 --- polybot/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index ec511868..1603ead7 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.10.12-slim-bullseye WORKDIR /app COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir -vvv -r requirements.txt COPY . . From 7f8981584fe3c0bffaa848e94f896d061e705520 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:23:21 +0300 Subject: [PATCH 037/241] hh2 --- polybot/requirements.txt | 2 -- requirements.txt | 2 -- 2 files changed, 4 deletions(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 10d3c570..39eb8aad 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -1,7 +1,6 @@ anyio==4.3.0 asgiref==3.8.1 astroid==3.1.0 -backports.zoneinfo==0.2.1 blinker==1.7.0 certifi==2024.2.2 charset-normalizer==3.3.2 @@ -60,5 +59,4 @@ update==0.0.1 urllib3==2.2.1 vboxapi==1.0 Werkzeug==3.0.1 -win32-setctime==1.1.0 zipp==3.17.0 diff --git a/requirements.txt b/requirements.txt index 10d3c570..39eb8aad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ anyio==4.3.0 asgiref==3.8.1 astroid==3.1.0 -backports.zoneinfo==0.2.1 blinker==1.7.0 certifi==2024.2.2 charset-normalizer==3.3.2 @@ -60,5 +59,4 @@ update==0.0.1 urllib3==2.2.1 vboxapi==1.0 Werkzeug==3.0.1 -win32-setctime==1.1.0 zipp==3.17.0 From 3cdc84532ced7465a7348afefac668601221f0e0 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:31:57 +0300 Subject: [PATCH 038/241] hh2 --- polybot/Dockerfile | 12 +++++++++--- requirements.txt | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 1603ead7..406ca9b9 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -1,8 +1,14 @@ +# Use the official Python slim image FROM python:3.10.12-slim-bullseye + +# Set the working directory in the container WORKDIR /app + +# Copy the requirements file into the container COPY requirements.txt . -RUN pip install --no-cache-dir -vvv -r requirements.txt -COPY . . +# Install the required Python packages +RUN pip install --no-cache-dir -r requirements.txt -CMD ["python3","polybot/bot.py"] \ No newline at end of file +# Copy the rest of the application code into the container +COPY . . \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 39eb8aad..10d3c570 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ anyio==4.3.0 asgiref==3.8.1 astroid==3.1.0 +backports.zoneinfo==0.2.1 blinker==1.7.0 certifi==2024.2.2 charset-normalizer==3.3.2 @@ -59,4 +60,5 @@ update==0.0.1 urllib3==2.2.1 vboxapi==1.0 Werkzeug==3.0.1 +win32-setctime==1.1.0 zipp==3.17.0 From 6a3943c83841ecddbe0d9bd7539255a3bfb20341 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:34:33 +0300 Subject: [PATCH 039/241] hh2 --- polybot/Dockerfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 406ca9b9..5b342585 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -7,8 +7,17 @@ WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . -# Install the required Python packages -RUN pip install --no-cache-dir -r requirements.txt +# Update system packages and install any dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Install the required Python packages with verbose output +RUN pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container -COPY . . \ No newline at end of file +COPY . . + +# Specify the command to run the application +CMD ["python3", "polybot/bot.py"] \ No newline at end of file From 6d8fc2b68a2219ad7655d7ba6070a03ae014b114 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 5 Jun 2024 20:36:54 +0300 Subject: [PATCH 040/241] hh2 --- polybot/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 5b342585..be4d93f4 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -7,9 +7,11 @@ WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . -# Update system packages and install any dependencies +# Update system packages and install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ + gcc \ + libssl-dev \ && rm -rf /var/lib/apt/lists/* # Install the required Python packages with verbose output From e7115306ba431b70bd885b5f6a36c0d5a818cd9f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:33:29 +0300 Subject: [PATCH 041/241] hh2 --- polybot/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index be4d93f4..794f1b68 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -7,6 +7,8 @@ WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . +RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt + # Update system packages and install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ From c3cda0d031d81bd02970ec19d44d75c718461049 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:39:22 +0300 Subject: [PATCH 042/241] hh2 --- polybot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/bot.py b/polybot/bot.py index 7200dba8..ee5ebd12 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -10,7 +10,7 @@ # Check if TELEGRAM_TOKEN is not none if TELEGRAM_TOKEN is None: - print("Error: TELEGRAM_TOKEN is not set in the .env file.") + print("Error : TELEGRAM_TOKEN is not set in the .env file.") exit(1) # initialize telegram-bot From 0efe3d4e337f791ad16f8a5676a67fd021addc12 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:40:30 +0300 Subject: [PATCH 043/241] hh2 --- polybot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/bot.py b/polybot/bot.py index ee5ebd12..7200dba8 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -10,7 +10,7 @@ # Check if TELEGRAM_TOKEN is not none if TELEGRAM_TOKEN is None: - print("Error : TELEGRAM_TOKEN is not set in the .env file.") + print("Error: TELEGRAM_TOKEN is not set in the .env file.") exit(1) # initialize telegram-bot From 1b7a6776965f317c2d01e37b7ee51293932f7d22 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:41:10 +0300 Subject: [PATCH 044/241] hh2 --- polybot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/bot.py b/polybot/bot.py index 7200dba8..ee5ebd12 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -10,7 +10,7 @@ # Check if TELEGRAM_TOKEN is not none if TELEGRAM_TOKEN is None: - print("Error: TELEGRAM_TOKEN is not set in the .env file.") + print("Error : TELEGRAM_TOKEN is not set in the .env file.") exit(1) # initialize telegram-bot From fd17604545d7b08b456062d6c04fe48aa3204796 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:42:47 +0300 Subject: [PATCH 045/241] hh2 --- polybot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/bot.py b/polybot/bot.py index ee5ebd12..2c8ec796 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -10,7 +10,7 @@ # Check if TELEGRAM_TOKEN is not none if TELEGRAM_TOKEN is None: - print("Error : TELEGRAM_TOKEN is not set in the .env file.") + print("Error : TELEGRAM_TOKEN is not set in the .env file.") exit(1) # initialize telegram-bot From df8dcc8446d1534d11ce74983b5692d8dfe2d570 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:47:48 +0300 Subject: [PATCH 046/241] hh2 --- polybot/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 794f1b68..be4d93f4 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -7,8 +7,6 @@ WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . -RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt - # Update system packages and install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ From 03964a6580429b5bd9fe7cae534ca2922f3bc846 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:55:03 +0300 Subject: [PATCH 047/241] hh2 --- build.Jenkinsfile | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 964fc134..81f8d169 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,15 +6,13 @@ pipeline { withCredentials( [usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')] ) { - bat ''' - @echo off - cd polybot - docker login -u %USERNAME% -p %USERPASS% --password-stdin - docker build -t polybot:%BUILD_NUMBER% . - - docker push beny14/repo1:polybot - ''' - + bat ''' + @echo off + cd polybot + echo %USERPASS% | docker login -u %USERNAME% --password-stdin + docker build -t beny14/repo1:%BUILD_NUMBER% . + docker push beny14/repo1:%BUILD_NUMBER% + ''' } } From 318de6374a0a945861581c09b131e29b86697c9d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 17:58:43 +0300 Subject: [PATCH 048/241] try changes --- polybot/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index be4d93f4..68fa8ab4 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -12,11 +12,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ gcc \ libssl-dev \ + libpq-dev \ && rm -rf /var/lib/apt/lists/* # Install the required Python packages with verbose output RUN pip install --no-cache-dir --upgrade pip \ - && pip install --no-cache-dir -r requirements.txt + && pip install --no-cache-dir -r requirements.txt --verbose # Copy the rest of the application code into the container COPY . . From e62e5196861071e4c6010cb947aab8d829c2ce1a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:01:30 +0300 Subject: [PATCH 049/241] try changes --- polybot/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 68fa8ab4..b62b0141 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -12,12 +12,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ gcc \ libssl-dev \ - libpq-dev \ && rm -rf /var/lib/apt/lists/* # Install the required Python packages with verbose output RUN pip install --no-cache-dir --upgrade pip \ - && pip install --no-cache-dir -r requirements.txt --verbose + && pip install --no-cache-dir -r requirements.txt --verbose || { echo 'pip install failed'; exit 1; } # Copy the rest of the application code into the container COPY . . From be51e57dbb36e7487448d479828c4b7e7f38c277 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:04:16 +0300 Subject: [PATCH 050/241] try changes --- build.Jenkinsfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 81f8d169..bcd6fd3e 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,15 +6,14 @@ pipeline { withCredentials( [usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')] ) { - bat ''' + script { + bat """ @echo off cd polybot echo %USERPASS% | docker login -u %USERNAME% --password-stdin docker build -t beny14/repo1:%BUILD_NUMBER% . docker push beny14/repo1:%BUILD_NUMBER% - ''' - - } + """ } } } From c85ce7809fb56be0b49fb9628ad99063c58823f9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:08:26 +0300 Subject: [PATCH 051/241] try changes --- build.Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index bcd6fd3e..efd53b24 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -5,7 +5,7 @@ pipeline { steps { withCredentials( [usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')] - ) { + ) script { bat """ @echo off @@ -17,4 +17,5 @@ pipeline { } } } -} \ No newline at end of file + } + } From 5df136a98ac3090daa9111ba199cca2c745da85b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:10:02 +0300 Subject: [PATCH 052/241] try changes --- build.Jenkinsfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index efd53b24..7cf6a256 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,9 +3,7 @@ pipeline { stages { stage('Build docker image') { steps { - withCredentials( - [usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')] - ) + withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { bat """ @echo off @@ -14,8 +12,9 @@ pipeline { docker build -t beny14/repo1:%BUILD_NUMBER% . docker push beny14/repo1:%BUILD_NUMBER% """ + } + } } } } - } - } +} \ No newline at end of file From e56b4a2cfed1ff251b5bc43c3a833e049afb0399 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:11:43 +0300 Subject: [PATCH 053/241] try changes --- polybot/img_proc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/img_proc.py b/polybot/img_proc.py index cb7005c5..df2f79a0 100644 --- a/polybot/img_proc.py +++ b/polybot/img_proc.py @@ -13,7 +13,7 @@ def load_image(self): if image is not None: return image else: - raise FileNotFoundError("Unable to load image.") + raise FileNotFoundError(" Unable to load image.") except Exception as e: print(f"Error loading image: {e}") return None From 13f65f62b84a2fd33ee8637cd7353d4a342f5eeb Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:16:52 +0300 Subject: [PATCH 054/241] try changes --- polybot/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index b62b0141..5f3d6a82 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -14,9 +14,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev \ && rm -rf /var/lib/apt/lists/* -# Install the required Python packages with verbose output -RUN pip install --no-cache-dir --upgrade pip \ - && pip install --no-cache-dir -r requirements.txt --verbose || { echo 'pip install failed'; exit 1; } +# Install the required Python packages +RUN pip install --no-cache-dir --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt --verbose # Copy the rest of the application code into the container COPY . . From 3ba1c5e147733ff8eced2ad8211fcdd33d5bfa09 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:20:20 +0300 Subject: [PATCH 055/241] try changes --- polybot/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 5f3d6a82..6ba978a5 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -16,7 +16,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Install the required Python packages RUN pip install --no-cache-dir --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt --verbose + +# Debugging step: Capture and output logs of pip install +RUN pip install --no-cache-dir -r requirements.txt --verbose > pip_install.log 2>&1 || (cat pip_install.log && exit 1) # Copy the rest of the application code into the container COPY . . From 8cbf08b6fe5a105f8d4f9708f96f3c617a5033f6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:32:39 +0300 Subject: [PATCH 056/241] try changes --- build.Jenkinsfile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 7cf6a256..c0cc725a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,20 +1,26 @@ pipeline { agent any + +enviroment{ + IMG_NAME = "polybot:${BUILD_NUMBER}" + stages { stage('Build docker image') { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { - script { + { bat """ @echo off cd polybot - echo %USERPASS% | docker login -u %USERNAME% --password-stdin - docker build -t beny14/repo1:%BUILD_NUMBER% . - docker push beny14/repo1:%BUILD_NUMBER% + docker login -u %USERNAME% -p $USERPASS% --password-stdin + docker build -t %IMG_NAME% . + docker tag %IMG_NAME% beny14/%IMG_NAME% + docker push beny14/%IMG_NAME% """ - } + } } } } +} } \ No newline at end of file From 32419d88b0c2669a0a0692980f33c05c67e2261e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:37:14 +0300 Subject: [PATCH 057/241] try changes --- build.Jenkinsfile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index c0cc725a..59b757cf 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,26 +1,34 @@ pipeline { agent any -enviroment{ - IMG_NAME = "polybot:${BUILD_NUMBER}" + environment { + IMG_NAME = "polybot:${BUILD_NUMBER}" + } stages { stage('Build docker image') { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { - { + script { bat """ @echo off cd polybot - docker login -u %USERNAME% -p $USERPASS% --password-stdin + echo Logging in to Docker... + echo %USERPASS% | docker login -u %USERNAME% --password-stdin + if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% + echo Building Docker image... docker build -t %IMG_NAME% . + if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% + echo Tagging Docker image... docker tag %IMG_NAME% beny14/%IMG_NAME% + if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% + echo Pushing Docker image... docker push beny14/%IMG_NAME% + if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% """ - + } } } } } -} } \ No newline at end of file From fccc07613415161798222bb81cbb963bcaa066cc Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:38:01 +0300 Subject: [PATCH 058/241] try changes --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 59b757cf..a41f65ac 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -13,7 +13,7 @@ pipeline { bat """ @echo off cd polybot - echo Logging in to Docker... + echo Logging in to Docker... echo %USERPASS% | docker login -u %USERNAME% --password-stdin if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% echo Building Docker image... From 670e797f6a3118b7c871838f2da0b795909864cd Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:38:38 +0300 Subject: [PATCH 059/241] try changes --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a41f65ac..59b757cf 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -13,7 +13,7 @@ pipeline { bat """ @echo off cd polybot - echo Logging in to Docker... + echo Logging in to Docker... echo %USERPASS% | docker login -u %USERNAME% --password-stdin if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% echo Building Docker image... From 8eb7e51759fcd8a147b9297ba36bd2388085a4b3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:39:04 +0300 Subject: [PATCH 060/241] try changes --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 59b757cf..a830e107 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -13,7 +13,7 @@ pipeline { bat """ @echo off cd polybot - echo Logging in to Docker... + echo Logging in to Docker... echo %USERPASS% | docker login -u %USERNAME% --password-stdin if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% echo Building Docker image... From e84b42206225df435a763eeead1c39bf60e1f997 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 18:40:07 +0300 Subject: [PATCH 061/241] try changes --- build.Jenkinsfile | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a830e107..38092022 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -10,25 +10,18 @@ pipeline { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { + // Use correct Docker login syntax bat """ @echo off cd polybot - echo Logging in to Docker... - echo %USERPASS% | docker login -u %USERNAME% --password-stdin - if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% - echo Building Docker image... + docker login -u %USERNAME% -p %USERPASS% docker build -t %IMG_NAME% . - if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% - echo Tagging Docker image... docker tag %IMG_NAME% beny14/%IMG_NAME% - if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% - echo Pushing Docker image... docker push beny14/%IMG_NAME% - if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% """ } } } } } -} \ No newline at end of file +} From 397d3a35b4315ee45c6270c54366b8353614b958 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:15:06 +0300 Subject: [PATCH 062/241] try changes --- build.Jenkinsfile | 7 +++++-- deploy.Jenkinsfile | 17 +++++++++++++++++ hh.txt | 1 - polybot/Dockerfile | 8 +------- 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 deploy.Jenkinsfile delete mode 100644 hh.txt diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 38092022..7d709e79 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -16,12 +16,15 @@ pipeline { cd polybot docker login -u %USERNAME% -p %USERPASS% docker build -t %IMG_NAME% . - docker tag %IMG_NAME% beny14/%IMG_NAME% - docker push beny14/%IMG_NAME% + docker tag %IMG_NAME% beny14/repo1:%IMG_NAME% + docker push beny14/repo1:%IMG_NAME% """ } } } } +// stage('Trigger Deploy'){ +// steps job: 'ploybotdeploy',wait:false, parameters:[ +// string(name:'beny14/repo1:%IMG_NAME%', value:"beny14/repo1:%IMG_NAME%")]} } } diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile new file mode 100644 index 00000000..9e981de9 --- /dev/null +++ b/deploy.Jenkinsfile @@ -0,0 +1,17 @@ +pipeline { + agent any + + parameters { + string(name: 'IMAGE_URL', defaultValue: '', description: '') + } + + stages { + stage('Deploy') { + steps { + sh ''' + echo "deploying to k8s cluster ..( or any other alternative)" + ''' + } + } + } +} \ No newline at end of file diff --git a/hh.txt b/hh.txt deleted file mode 100644 index 5422d91d..00000000 --- a/hh.txt +++ /dev/null @@ -1 +0,0 @@ -sa22sasa \ No newline at end of file diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 6ba978a5..d9dc56c8 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -7,18 +7,12 @@ WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . -# Update system packages and install build dependencies -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential \ - gcc \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* # Install the required Python packages RUN pip install --no-cache-dir --upgrade pip # Debugging step: Capture and output logs of pip install -RUN pip install --no-cache-dir -r requirements.txt --verbose > pip_install.log 2>&1 || (cat pip_install.log && exit 1) +RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container COPY . . From 009cec61a7a5519388d9bd6d325aa9d020e54572 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:17:38 +0300 Subject: [PATCH 063/241] try changes --- polybot/requirements.txt | 67 +++------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 39eb8aad..9e381578 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -1,62 +1,5 @@ -anyio==4.3.0 -asgiref==3.8.1 -astroid==3.1.0 -blinker==1.7.0 -certifi==2024.2.2 -charset-normalizer==3.3.2 -class-registry==2.1.2 -click==8.1.7 -colorama==0.4.6 -contourpy==1.1.1 -cycler==0.12.1 -dill==0.3.8 -Django==4.2.11 -django-request==1.6.3 -exceptiongroup==1.2.1 -filters==1.3.2 -Flask==3.0.2 -fonttools==4.51.0 -h11==0.14.0 -httpcore==1.0.5 -httpx==0.27.0 -idna==3.6 -img==2.5 -importlib-metadata==7.0.1 -importlib_resources==6.4.0 -isort==5.13.2 -itsdangerous==2.1.2 -Jinja2==3.1.3 -kiwisolver==1.4.5 -loguru==0.7.2 -MarkupSafe==2.1.5 -matplotlib==3.7.5 -mccabe==0.7.0 -numpy==1.24.4 -opencv-python==4.9.0.80 -packaging==24.0 -pillow==10.3.0 -platformdirs==4.2.0 -pylint==3.1.0 -pyparsing==3.1.2 -pyTelegramBotAPI==4.16.1 -python-dateutil==2.9.0.post0 -python-dotenv==1.0.1 -python-telegram-bot==21.1.1 -pytz==2024.1 -regex==2024.4.16 -requests==2.31.0 -rfc3986==1.5.0 -six==1.16.0 -sniffio==1.3.1 -sqlparse==0.5.0 -style==1.1.0 -telebot==0.0.5 -tomli==2.0.1 -tomlkit==0.12.4 -typing_extensions==4.10.0 -tzdata==2024.1 -update==0.0.1 -urllib3==2.2.1 -vboxapi==1.0 -Werkzeug==3.0.1 -zipp==3.17.0 +pyTelegramBotAPI>=4.12.0 +loguru>=0.7.0 +requests>=2.31.0 +flask>=2.3.2 +matplotlib>=3.7.5 \ No newline at end of file From ed707dd68f92ed4bdb8618a1b4a68ca51e21709a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:21:29 +0300 Subject: [PATCH 064/241] try changes --- build.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 7d709e79..473ed835 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -16,8 +16,8 @@ pipeline { cd polybot docker login -u %USERNAME% -p %USERPASS% docker build -t %IMG_NAME% . - docker tag %IMG_NAME% beny14/repo1:%IMG_NAME% - docker push beny14/repo1:%IMG_NAME% + docker tag %IMG_NAME% beny14/%IMG_NAME% + docker push beny14/%IMG_NAME% """ } } From a1e6fcc8edb05c890a6346fb53e6f37f6a952f75 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:43:00 +0300 Subject: [PATCH 065/241] try changes --- Dockerfile | 8 ------ build.Jenkinsfile | 6 ++-- deploy.Jenkinsfile | 2 +- requirements.txt | 69 ++++------------------------------------------ 4 files changed, 9 insertions(+), 76 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index bf8362df..00000000 --- a/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM python:3.10.12-slim-bullseye -WORKDIR /tt -COPY requirements.txt -RUN pip install --no-cache-dir -r requirements.txt - -COPY . . - -CMD ["python3","polybot/bot.py"] \ No newline at end of file diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 473ed835..ade0efb7 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,8 +23,8 @@ pipeline { } } } -// stage('Trigger Deploy'){ -// steps job: 'ploybotdeploy',wait:false, parameters:[ -// string(name:'beny14/repo1:%IMG_NAME%', value:"beny14/repo1:%IMG_NAME%")]} + stage('Trigger Deploy'){ + steps job: 'polybotdeploy',wait:false, parameters:[ + string(name:'beny14/%IMG_NAME%', value:"beny14/%IMG_NAME%")]} } } diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 9e981de9..16aa6869 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent any parameters { - string(name: 'IMAGE_URL', defaultValue: '', description: '') + string(name: 'beny14/polybot', defaultValue: 'INAGE_URL', description: 'deploy polybot') } stages { diff --git a/requirements.txt b/requirements.txt index 10d3c570..9e381578 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,64 +1,5 @@ -anyio==4.3.0 -asgiref==3.8.1 -astroid==3.1.0 -backports.zoneinfo==0.2.1 -blinker==1.7.0 -certifi==2024.2.2 -charset-normalizer==3.3.2 -class-registry==2.1.2 -click==8.1.7 -colorama==0.4.6 -contourpy==1.1.1 -cycler==0.12.1 -dill==0.3.8 -Django==4.2.11 -django-request==1.6.3 -exceptiongroup==1.2.1 -filters==1.3.2 -Flask==3.0.2 -fonttools==4.51.0 -h11==0.14.0 -httpcore==1.0.5 -httpx==0.27.0 -idna==3.6 -img==2.5 -importlib-metadata==7.0.1 -importlib_resources==6.4.0 -isort==5.13.2 -itsdangerous==2.1.2 -Jinja2==3.1.3 -kiwisolver==1.4.5 -loguru==0.7.2 -MarkupSafe==2.1.5 -matplotlib==3.7.5 -mccabe==0.7.0 -numpy==1.24.4 -opencv-python==4.9.0.80 -packaging==24.0 -pillow==10.3.0 -platformdirs==4.2.0 -pylint==3.1.0 -pyparsing==3.1.2 -pyTelegramBotAPI==4.16.1 -python-dateutil==2.9.0.post0 -python-dotenv==1.0.1 -python-telegram-bot==21.1.1 -pytz==2024.1 -regex==2024.4.16 -requests==2.31.0 -rfc3986==1.5.0 -six==1.16.0 -sniffio==1.3.1 -sqlparse==0.5.0 -style==1.1.0 -telebot==0.0.5 -tomli==2.0.1 -tomlkit==0.12.4 -typing_extensions==4.10.0 -tzdata==2024.1 -update==0.0.1 -urllib3==2.2.1 -vboxapi==1.0 -Werkzeug==3.0.1 -win32-setctime==1.1.0 -zipp==3.17.0 +pyTelegramBotAPI>=4.12.0 +loguru>=0.7.0 +requests>=2.31.0 +flask>=2.3.2 +matplotlib>=3.7.5 \ No newline at end of file From c5b09973a0232dd1f26794438eb3edd11757cdde Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:50:03 +0300 Subject: [PATCH 066/241] try changes --- build.Jenkinsfile | 20 ++++++++++++-------- deploy.Jenkinsfile | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ade0efb7..b04c1631 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -14,17 +14,21 @@ pipeline { bat """ @echo off cd polybot - docker login -u %USERNAME% -p %USERPASS% - docker build -t %IMG_NAME% . - docker tag %IMG_NAME% beny14/%IMG_NAME% - docker push beny14/%IMG_NAME% + docker login -u $USERNAME -p $USERPASS + docker build -t $IMG_NAME . + docker tag $IMG_NAME beny14/$IMG_NAME + docker push beny14/$IMG_NAME """ } } } } - stage('Trigger Deploy'){ - steps job: 'polybotdeploy',wait:false, parameters:[ - string(name:'beny14/%IMG_NAME%', value:"beny14/%IMG_NAME%")]} + stage('Trigger Deploy') { + steps { + build job: 'polybotdeploy', wait: false, parameters: [ + string(name: 'IMG_NAME', value: IMG_NAME) + ] + } + } } -} +} \ No newline at end of file diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 16aa6869..634aab1a 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent any parameters { - string(name: 'beny14/polybot', defaultValue: 'INAGE_URL', description: 'deploy polybot') + string(name: 'beny14/polybot:${BUILD_NUMBER}', defaultValue: 'INAGE_URL', description: 'deploy polybot') } stages { From 853ec1ca3174eba46ecc18f4d3b8f60344f60005 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:53:23 +0300 Subject: [PATCH 067/241] try changes --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index b04c1631..7a9f5533 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -26,7 +26,7 @@ pipeline { stage('Trigger Deploy') { steps { build job: 'polybotdeploy', wait: false, parameters: [ - string(name: 'IMG_NAME', value: IMG_NAME) + string(name: 'beny14/$IMG_NAME', value: IMG_NAME) ] } } From 44ca059aa2c60e513d5d5f5878551599d05590d8 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 19:56:04 +0300 Subject: [PATCH 068/241] try changes --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 634aab1a..54f75863 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -8,7 +8,7 @@ pipeline { stages { stage('Deploy') { steps { - sh ''' + bat ''' echo "deploying to k8s cluster ..( or any other alternative)" ''' } From 252177720429f593630de1eab18f1b59d7a77760 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 9 Jun 2024 20:23:42 +0300 Subject: [PATCH 069/241] try changes --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 7a9f5533..8dcae1a0 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -25,7 +25,7 @@ pipeline { } stage('Trigger Deploy') { steps { - build job: 'polybotdeploy', wait: false, parameters: [ + build job: 'deploy_polybot', wait: false, parameters: [ string(name: 'beny14/$IMG_NAME', value: IMG_NAME) ] } From 7fcebd99dceca0dddd923df7492a86c25098b8d3 Mon Sep 17 00:00:00 2001 From: beny1221g <64226437+beny1221g@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:27:10 +0300 Subject: [PATCH 070/241] Update build.Jenkinsfile to work with ubuntu --- build.Jenkinsfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 8dcae1a0..4665cc02 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -11,13 +11,12 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { // Use correct Docker login syntax - bat """ - @echo off + sh """ cd polybot - docker login -u $USERNAME -p $USERPASS - docker build -t $IMG_NAME . - docker tag $IMG_NAME beny14/$IMG_NAME - docker push beny14/$IMG_NAME + docker login -u ${USERNAME} -p ${USERPASS} + docker build -t ${IMG_NAME} . + docker tag ${IMG_NAME} beny14/${IMG_NAME} + docker push beny14/${IMG_NAME} """ } } @@ -31,4 +30,4 @@ pipeline { } } } -} \ No newline at end of file +} From 1735abe4c92491d12e05f9ec8962dc9b3fdcebf4 Mon Sep 17 00:00:00 2001 From: beny1221g <64226437+beny1221g@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:30:11 +0300 Subject: [PATCH 071/241] Update build.Jenkinsfile ubuntu --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 4665cc02..bacbf76b 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -13,7 +13,7 @@ pipeline { // Use correct Docker login syntax sh """ cd polybot - docker login -u ${USERNAME} -p ${USERPASS} + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${IMG_NAME} . docker tag ${IMG_NAME} beny14/${IMG_NAME} docker push beny14/${IMG_NAME} From e3dcece1ef5dab62dd7438033ef38011285950a1 Mon Sep 17 00:00:00 2001 From: beny1221g <64226437+beny1221g@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:20:28 +0300 Subject: [PATCH 072/241] Update deploy.Jenkinsfile ubuntu update --- deploy.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 54f75863..ada69994 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -8,10 +8,10 @@ pipeline { stages { stage('Deploy') { steps { - bat ''' + sh ''' echo "deploying to k8s cluster ..( or any other alternative)" ''' } } } -} \ No newline at end of file +} From 2cf2b9548c0b01677b7583326cf82ccd60e427c6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 13 Jun 2024 21:44:13 +0300 Subject: [PATCH 073/241] update dirwork --- polybot/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index d9dc56c8..738c5011 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.10.12-slim-bullseye # Set the working directory in the container -WORKDIR /app +WORKDIR /var/lib/jenkins/workspace/build_polybot # Copy the requirements file into the container COPY requirements.txt . From 51f20fd254c311c97e2adc472db24fa78c722192 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 13 Jun 2024 22:00:13 +0300 Subject: [PATCH 074/241] update work dir to app --- polybot/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 738c5011..a2d749ef 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.10.12-slim-bullseye # Set the working directory in the container -WORKDIR /var/lib/jenkins/workspace/build_polybot +WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . @@ -18,4 +18,4 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Specify the command to run the application -CMD ["python3", "polybot/bot.py"] \ No newline at end of file +CMD ["python3", "polybot/bot.py"] From 880844091241cc29742a4b9260ed321b90765416 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 13 Jun 2024 22:03:25 +0300 Subject: [PATCH 075/241] as --- polybot/ff.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 polybot/ff.txt diff --git a/polybot/ff.txt b/polybot/ff.txt new file mode 100644 index 00000000..1b9ae7c6 --- /dev/null +++ b/polybot/ff.txt @@ -0,0 +1,2 @@ +asd + From 90333be4f9a25c3c244b1494e40b9cd73d736609 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 13 Jun 2024 22:14:04 +0300 Subject: [PATCH 076/241] sa --- polybot/ff.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 polybot/ff.txt diff --git a/polybot/ff.txt b/polybot/ff.txt deleted file mode 100644 index 1b9ae7c6..00000000 --- a/polybot/ff.txt +++ /dev/null @@ -1,2 +0,0 @@ -asd - From 0d8f71aedb432644fee639dde04e9820f7e5b91b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 13 Jun 2024 22:16:19 +0300 Subject: [PATCH 077/241] sa --- polybot/ff.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 polybot/ff.txt diff --git a/polybot/ff.txt b/polybot/ff.txt new file mode 100644 index 00000000..dc43f979 --- /dev/null +++ b/polybot/ff.txt @@ -0,0 +1,2 @@ +sa + From 87db54ac9a00d752136a5fce48b4c1f0aaa703ff Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 13 Jun 2024 22:18:13 +0300 Subject: [PATCH 078/241] as --- polybot/ff.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 polybot/ff.txt diff --git a/polybot/ff.txt b/polybot/ff.txt deleted file mode 100644 index dc43f979..00000000 --- a/polybot/ff.txt +++ /dev/null @@ -1,2 +0,0 @@ -sa - From eb6427fd710d1dc28284004731aa446e388bb847 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 15 Jun 2024 19:12:34 +0300 Subject: [PATCH 079/241] sa --- sd.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 sd.txt diff --git a/sd.txt b/sd.txt new file mode 100644 index 00000000..e539a958 --- /dev/null +++ b/sd.txt @@ -0,0 +1 @@ +as From 50dd9bf09abd0d639216c50d71db21dc8c2c593c Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 16 Jun 2024 19:47:17 +0300 Subject: [PATCH 080/241] add pr-testing.jenkisfile --- pr-testing.Jenkinsfile | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pr-testing.Jenkinsfile diff --git a/pr-testing.Jenkinsfile b/pr-testing.Jenkinsfile new file mode 100644 index 00000000..15b0a0be --- /dev/null +++ b/pr-testing.Jenkinsfile @@ -0,0 +1,32 @@ + +pipeline { + + + agent any + + stages { + stage('Unittest'){ + steps{ + sh 'echo "testing"' + } + } + stage('Lint') { + steps { + sh ''' + cd polybot + pip install -r requirements.txt + python3 -m plint *.py + ''' + } + } + + stage('Functional test') { + steps { + sh 'echo "testing"' + } + } + + + + } +} From e0dc90d69f62abb2bf6642f63e762d2ac86a5c88 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 16 Jun 2024 19:49:22 +0300 Subject: [PATCH 081/241] add pr-testing.jenkisfile --- pr-testing.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr-testing.Jenkinsfile b/pr-testing.Jenkinsfile index 15b0a0be..fc77e43c 100644 --- a/pr-testing.Jenkinsfile +++ b/pr-testing.Jenkinsfile @@ -22,7 +22,7 @@ pipeline { stage('Functional test') { steps { - sh 'echo "testing"' + sh 'echo "testing "' } } From 4fbb219eaf5df75c384dfe72481b6d329dfabd0f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 16 Jun 2024 19:57:22 +0300 Subject: [PATCH 082/241] add to req --- polybot/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 9e381578..1995fc9e 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -2,4 +2,5 @@ pyTelegramBotAPI>=4.12.0 loguru>=0.7.0 requests>=2.31.0 flask>=2.3.2 -matplotlib>=3.7.5 \ No newline at end of file +matplotlib>=3.7.5 +pylint>-3.2.3 From 4b198095f027c694519ac80ff2928f1e001d4786 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 19 Jun 2024 19:30:48 +0300 Subject: [PATCH 083/241] docker file for agent added --- dockerfile.agent | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 dockerfile.agent diff --git a/dockerfile.agent b/dockerfile.agent new file mode 100644 index 00000000..56144cb6 --- /dev/null +++ b/dockerfile.agent @@ -0,0 +1,26 @@ +FROM amazonlinux:2 as installer +RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" +RUN yum update -y \ + && yum install -y unzip \ + && unzip awscliv2.zip \ + && ./aws/install --bin-dir /aws-cli-bin/ + + + +RUN mkdir /snyk && cd /snyk \ + && curl https://static.snyk.io/cli/v1.666.0/snyk-linux -o snyk \ + && chmod +x ./snyk + + + +#FROM jenkins/jnlp-agent-python +FROM jenkins/agent +COPY --from=docker /usr/local/bin/docker /usr/local/bin/ +COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/ +COPY --from=installer /aws-cli-bin/ /usr/local/bin/ +COPY --from=installer /snyk/ /usr/local/bin/ +COPY --from=installer /snyk/ /usr/bin/ +USER root +RUN apt-get update && apt-get install -y python3 python3-pip +USER jenkins + From 95c51dda6199cd1bab90fcc76b4ee8481f5d07f7 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 19 Jun 2024 19:36:58 +0300 Subject: [PATCH 084/241] docker file for agent added --- dockerfile.agent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile.agent b/dockerfile.agent index 56144cb6..a4f14f41 100644 --- a/dockerfile.agent +++ b/dockerfile.agent @@ -13,7 +13,7 @@ RUN mkdir /snyk && cd /snyk \ -#FROM jenkins/jnlp-agent-python +#FROM jenkins/jnlp-agent-python . FROM jenkins/agent COPY --from=docker /usr/local/bin/docker /usr/local/bin/ COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/ From cb313fe2ba2cce863343eaf570c319c33cd7ba1b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 19 Jun 2024 19:55:54 +0300 Subject: [PATCH 085/241] update --- dockerfile.agent => Dockerfile_agent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename dockerfile.agent => Dockerfile_agent (95%) diff --git a/dockerfile.agent b/Dockerfile_agent similarity index 95% rename from dockerfile.agent rename to Dockerfile_agent index a4f14f41..56144cb6 100644 --- a/dockerfile.agent +++ b/Dockerfile_agent @@ -13,7 +13,7 @@ RUN mkdir /snyk && cd /snyk \ -#FROM jenkins/jnlp-agent-python . +#FROM jenkins/jnlp-agent-python FROM jenkins/agent COPY --from=docker /usr/local/bin/docker /usr/local/bin/ COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/ From ba0b5b5f76d9751b5dfb659cf67958e0848f765f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 19 Jun 2024 20:00:50 +0300 Subject: [PATCH 086/241] update --- Dockerfile_agent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile_agent b/Dockerfile_agent index 56144cb6..a4f14f41 100644 --- a/Dockerfile_agent +++ b/Dockerfile_agent @@ -13,7 +13,7 @@ RUN mkdir /snyk && cd /snyk \ -#FROM jenkins/jnlp-agent-python +#FROM jenkins/jnlp-agent-python . FROM jenkins/agent COPY --from=docker /usr/local/bin/docker /usr/local/bin/ COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/ From 74587a1b471a13bdd7082f54e36eacd49f239cee Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 19:27:28 +0300 Subject: [PATCH 087/241] update 20/06/24 --- sd.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 sd.txt diff --git a/sd.txt b/sd.txt deleted file mode 100644 index e539a958..00000000 --- a/sd.txt +++ /dev/null @@ -1 +0,0 @@ -as From f919683ee62a562a99693aa87b70d8a499f6f1b9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 20:17:01 +0300 Subject: [PATCH 088/241] update 20/06/24 --- build.Jenkinsfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index bacbf76b..05277df1 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,5 +1,11 @@ pipeline { - agent any + agent { + docker { + image 'beny14/dockerfile_agent:latest' + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' + } + } + environment { IMG_NAME = "polybot:${BUILD_NUMBER}" From 08af6b5bf240f41d2abbdac9e99c0c4f7384f190 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 20:19:46 +0300 Subject: [PATCH 089/241] update 20/06/24 --- build.Jenkinsfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 05277df1..ceb88077 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,11 +1,12 @@ pipeline { - agent { - docker { - image 'beny14/dockerfile_agent:latest' - args '--user root -v /var/run/docker.sock:/var/run/docker.sock' - } - } + agent { + docker { + image 'beny1221g/dockerfile_agent:latest' + label 'my-docker-agent' + args '-v /var/lib/jenkins/workspace:/workspace' + } + } environment { IMG_NAME = "polybot:${BUILD_NUMBER}" From a0f1dfd9901c9e770a79ef233123b8aefbf60b89 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 20:28:56 +0300 Subject: [PATCH 090/241] update 20/06/24 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ceb88077..8b2c4a46 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent { docker { - image 'beny1221g/dockerfile_agent:latest' + image 'beny14/dockerfile_agent:latest' label 'my-docker-agent' args '-v /var/lib/jenkins/workspace:/workspace' } From 869484293dc623068b5a5152abd62ed97309acea Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 20:30:53 +0300 Subject: [PATCH 091/241] update 20/06/24 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 8b2c4a46..3477f393 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent { - docker { + dockerContainer { image 'beny14/dockerfile_agent:latest' label 'my-docker-agent' args '-v /var/lib/jenkins/workspace:/workspace' From 5793efc9d40bdb6f300d52603e08c63ecd12cce8 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 20:34:18 +0300 Subject: [PATCH 092/241] update 20/06/24 --- build.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3477f393..f09b3315 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,10 +1,10 @@ pipeline { agent { - dockerContainer { + docker { image 'beny14/dockerfile_agent:latest' label 'my-docker-agent' - args '-v /var/lib/jenkins/workspace:/workspace' + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } From 5c2f512abfcacd14ffd755a1c9f236f2c32382c8 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 20 Jun 2024 20:45:06 +0300 Subject: [PATCH 093/241] update 20/06/24 --- build.Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index f09b3315..daf5d20c 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,7 +3,6 @@ pipeline { agent { docker { image 'beny14/dockerfile_agent:latest' - label 'my-docker-agent' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } From a366a3d7544a7f8a0bf686d7c0430003b84c47ba Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 23 Jun 2024 20:04:50 +0300 Subject: [PATCH 094/241] add nginx and docker compose file --- docker-compose.yml | 18 ++++++++++++++++++ nginx/Dockerfile | 13 +++++++++++++ nginx/index.html | 12 ++++++++++++ nginx/nginx.conf | 17 +++++++++++++++++ polybot/Dockerfile | 2 ++ 5 files changed, 62 insertions(+) create mode 100644 docker-compose.yml create mode 100644 nginx/Dockerfile create mode 100644 nginx/index.html create mode 100644 nginx/nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..f7e1b44d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' + +services: + app: + build: + context: ./polybot + dockerfile: Dockerfile + ports: + - "5000:5000" + volumes: + - .:/app + + web: + build: + context: ./nginx + dockerfile: Dockerfile + ports: + - "8001:8001" \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 00000000..e7587308 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,13 @@ +# Use the official Nginx image as the base image +FROM nginx:alpine + +# Copy the Nginx configuration file into the container +COPY nginx.conf /etc/nginx/nginx.conf + +# Copy the static website files into the container +COPY . /usr/share/nginx/html + +# Expose the port that Nginx will run on +EXPOSE 8001 + +# Start Nginx (default command of the Nginx image) \ No newline at end of file diff --git a/nginx/index.html b/nginx/index.html new file mode 100644 index 00000000..43ac0716 --- /dev/null +++ b/nginx/index.html @@ -0,0 +1,12 @@ + + + + + + Welcome to my DarkWeb + + +

Welcome to my DarkWeb !

+

If you see this page, then we are watching you .

+ + diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..f1885dc3 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } +} diff --git a/polybot/Dockerfile b/polybot/Dockerfile index a2d749ef..294538d1 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -19,3 +19,5 @@ COPY . . # Specify the command to run the application CMD ["python3", "polybot/bot.py"] + +EXPOSE 5000 From 83240037c426f4492f67f0f609c1da338b0149f6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 23 Jun 2024 20:10:12 +0300 Subject: [PATCH 095/241] update nginx and docker compose file --- nginx/nginx.conf | 28 +++++++++++++++------------- polybot/requirements.txt | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index f1885dc3..bb02f5c3 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,17 +1,19 @@ -server { - listen 80; - server_name localhost; +http { + server { + listen 8001; + server_name localhost; - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } - error_page 404 /404.html; - location = /40x.html { - } + error_page 404 /404.html; + location = /40x.html { + } - error_page 500 502 503 504 /50x.html; - location = /50x.html { + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } } -} +} \ No newline at end of file diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 1995fc9e..07a4dd6e 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -4,3 +4,4 @@ requests>=2.31.0 flask>=2.3.2 matplotlib>=3.7.5 pylint>-3.2.3 +opencv-python==4.5.3.56 \ No newline at end of file From 5dca144b7c4cd2ea9bf3d364bdd3ff8f9e660c40 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 23 Jun 2024 20:16:13 +0300 Subject: [PATCH 096/241] update nginx and docker compose file --- polybot/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 07a4dd6e..79d9a6ef 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -3,5 +3,5 @@ loguru>=0.7.0 requests>=2.31.0 flask>=2.3.2 matplotlib>=3.7.5 -pylint>-3.2.3 -opencv-python==4.5.3.56 \ No newline at end of file +pylint>=3.2.3 +opencv-python>=4.5.3.56 \ No newline at end of file From a3efac099b493ec3c10387080ac43b75f748f49c Mon Sep 17 00:00:00 2001 From: beny1221g <64226437+beny1221g@users.noreply.github.com> Date: Sun, 23 Jun 2024 20:25:51 +0300 Subject: [PATCH 097/241] Update requirements.txt --- requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9e381578..ddcfafc3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,6 @@ pyTelegramBotAPI>=4.12.0 loguru>=0.7.0 requests>=2.31.0 flask>=2.3.2 -matplotlib>=3.7.5 \ No newline at end of file +matplotlib>=3.7.5 +pylint>=3.2.3 +opencv-python>=4.5.3.56 From b6166e69b262a27fb3a767641aa6aea64cfc924f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 26 Jun 2024 20:44:05 +0300 Subject: [PATCH 098/241] update --- docker-compose.yml | 6 ++++-- nginx/Dockerfile | 2 +- nginx/nginx.conf | 24 +++++++++++++----------- polybot/Dockerfile | 10 +++++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f7e1b44d..1cf1f589 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,10 +9,12 @@ services: - "5000:5000" volumes: - .:/app - web: build: context: ./nginx dockerfile: Dockerfile ports: - - "8001:8001" \ No newline at end of file + - "8002:80" + + + diff --git a/nginx/Dockerfile b/nginx/Dockerfile index e7587308..57e7ed82 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -8,6 +8,6 @@ COPY nginx.conf /etc/nginx/nginx.conf COPY . /usr/share/nginx/html # Expose the port that Nginx will run on -EXPOSE 8001 +EXPOSE 8002 # Start Nginx (default command of the Nginx image) \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index bb02f5c3..8703a7c2 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,19 +1,21 @@ +events { + worker_connections 1024; # Adjust this number based on your requirements +} + http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + server { - listen 8001; + listen 8002; server_name localhost; location / { - root /usr/share/nginx/html; - index index.html index.htm; - } - - error_page 404 /404.html; - location = /40x.html { + root /usr/share/nginx/html; + index index.html; } - error_page 500 502 503 504 /50x.html; - location = /50x.html { - } + # Additional location blocks and configurations can be added here } -} \ No newline at end of file +} + diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 294538d1..4ee7b2e0 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -4,14 +4,18 @@ FROM python:3.10.12-slim-bullseye # Set the working directory in the container WORKDIR /app +# Install required system packages +RUN apt-get update && apt-get install -y \ + libglib2.0-0 \ + libgl1-mesa-glx \ + libglib2.0-0 \ + && rm -rf /var/lib/apt/lists/* + # Copy the requirements file into the container COPY requirements.txt . - # Install the required Python packages RUN pip install --no-cache-dir --upgrade pip - -# Debugging step: Capture and output logs of pip install RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container From b8e786975750eecce0d737ac6325664f6118af93 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 20:21:51 +0300 Subject: [PATCH 099/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 56 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index daf5d20c..fd4858be 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,4 +1,15 @@ pipeline { + // Add pipeline options + options { + buildDiscarder(logRotator(daysToKeepStr: '30')) + disableConcurrentBuilds() + timestamps() + } + + // Define environment variables + environment { + IMG_NAME = "polybot:${BUILD_NUMBER}" + } agent { docker { @@ -7,12 +18,8 @@ pipeline { } } - environment { - IMG_NAME = "polybot:${BUILD_NUMBER}" - } - stages { - stage('Build docker image') { + stage('Build') { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { @@ -28,12 +35,41 @@ pipeline { } } } - stage('Trigger Deploy') { + + stage('Test') { steps { - build job: 'deploy_polybot', wait: false, parameters: [ - string(name: 'beny14/$IMG_NAME', value: IMG_NAME) - ] + script { + sh 'docker run --rm $IMG_NAME pylint polybot' + sh 'docker run --rm $IMG_NAME pytest' + } } } } -} + + post { + always { + // Clean up old containers but not the new one + script { + // Fetch the container ID of the currently running container + def containerId = sh(script: "docker ps -q -f ancestor=${IMG_NAME}", returnStdout: true).trim() + + // Remove all stopped containers with the same image except the current one + sh """ + for id in \$(docker ps -a -q -f ancestor=${IMG_NAME}); do + if [ "\$id" != "${containerId}" ]; then + docker rm -f \$id || true + fi + done + """ + } + + // Clean up built Docker images from disk + script { + sh 'docker rmi $IMG_NAME || true' + } + + // Clean build artifacts from Jenkins server + cleanWs() + } + } +} \ No newline at end of file From a393b9c884ad5a12ce5fc2764c291b1645a4ca0e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 20:25:56 +0300 Subject: [PATCH 100/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index fd4858be..202fc582 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -14,7 +14,7 @@ pipeline { agent { docker { image 'beny14/dockerfile_agent:latest' - args '--user root -v /var/run/docker.sock:/var/run/docker.sock' + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } @@ -39,7 +39,9 @@ pipeline { stage('Test') { steps { script { - sh 'docker run --rm $IMG_NAME pylint polybot' + // Run pylint with PYTHONPATH set + sh 'docker run --rm -e PYTHONPATH=/app $IMG_NAME pylint polybot' + // Run pytest sh 'docker run --rm $IMG_NAME pytest' } } From fe87efeb8263dbb89eef643804e10c3c8d7b38be Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 20:41:05 +0300 Subject: [PATCH 101/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 202fc582..0db2dbd9 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -40,7 +40,7 @@ pipeline { steps { script { // Run pylint with PYTHONPATH set - sh 'docker run --rm -e PYTHONPATH=/app $IMG_NAME pylint polybot' + sh 'docker run --rm -e PYTHONPATH=/polybot $IMG_NAME pylint polybot' // Run pytest sh 'docker run --rm $IMG_NAME pytest' } From d525c94a7d9e9dfed0195028b536fcd3928d4e7e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 20:49:32 +0300 Subject: [PATCH 102/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 0db2dbd9..73c40e8a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -40,9 +40,10 @@ pipeline { steps { script { // Run pylint with PYTHONPATH set - sh 'docker run --rm -e PYTHONPATH=/polybot $IMG_NAME pylint polybot' - // Run pytest - sh 'docker run --rm $IMG_NAME pytest' + sh ''' + python3 -m plint *.py + ''' + } } } From 19e3da070465681e748bb39dc2ec6b5e63d9b3dc Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 20:55:10 +0300 Subject: [PATCH 103/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 73c40e8a..d63e2a9e 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -41,7 +41,7 @@ pipeline { script { // Run pylint with PYTHONPATH set sh ''' - python3 -m plint *.py + python3 -m pylint *.py ''' } From 5b99b170cf62bf28e098159c0c9fb13de79f7661 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 20:57:56 +0300 Subject: [PATCH 104/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index d63e2a9e..9624fca1 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -41,6 +41,8 @@ pipeline { script { // Run pylint with PYTHONPATH set sh ''' + cd polybot + pip install -r requirements.txt python3 -m pylint *.py ''' From e316de1c0d64ebb14bf94c1a6f6ac812fe7be4b6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 21:02:53 +0300 Subject: [PATCH 105/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 21 +++++++++++---------- pr-testing.Jenkinsfile | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 9624fca1..29b4d417 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,14 +1,13 @@ pipeline { - // Add pipeline options options { buildDiscarder(logRotator(daysToKeepStr: '30')) disableConcurrentBuilds() timestamps() } - // Define environment variables environment { IMG_NAME = "polybot:${BUILD_NUMBER}" + DOCKER_REPO = "beny14/polybot" } agent { @@ -27,9 +26,10 @@ pipeline { sh """ cd polybot echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t ${IMG_NAME} . - docker tag ${IMG_NAME} beny14/${IMG_NAME} - docker push beny14/${IMG_NAME} + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${DOCKER_REPO}:latest """ } } @@ -45,7 +45,6 @@ pipeline { pip install -r requirements.txt python3 -m pylint *.py ''' - } } } @@ -56,11 +55,11 @@ pipeline { // Clean up old containers but not the new one script { // Fetch the container ID of the currently running container - def containerId = sh(script: "docker ps -q -f ancestor=${IMG_NAME}", returnStdout: true).trim() + def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() // Remove all stopped containers with the same image except the current one sh """ - for id in \$(docker ps -a -q -f ancestor=${IMG_NAME}); do + for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then docker rm -f \$id || true fi @@ -68,9 +67,11 @@ pipeline { """ } - // Clean up built Docker images from disk + // Clean up old Docker images but keep the new one script { - sh 'docker rmi $IMG_NAME || true' + sh """ + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi || true + """ } // Clean build artifacts from Jenkins server diff --git a/pr-testing.Jenkinsfile b/pr-testing.Jenkinsfile index fc77e43c..9c78e48a 100644 --- a/pr-testing.Jenkinsfile +++ b/pr-testing.Jenkinsfile @@ -15,7 +15,7 @@ pipeline { sh ''' cd polybot pip install -r requirements.txt - python3 -m plint *.py + python3 -m pylint *.py ''' } } From b7312fbf7bd53706a9d68247bf915b8b126a924d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 21:05:58 +0300 Subject: [PATCH 106/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 29b4d417..0b4b190d 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -39,11 +39,14 @@ pipeline { stage('Test') { steps { script { - // Run pylint with PYTHONPATH set + // Run pylint in a virtual environment sh ''' cd polybot + python3 -m venv venv + . venv/bin/activate pip install -r requirements.txt python3 -m pylint *.py + deactivate ''' } } @@ -70,7 +73,7 @@ pipeline { // Clean up old Docker images but keep the new one script { sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi || true + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ } @@ -78,4 +81,4 @@ pipeline { cleanWs() } } -} \ No newline at end of file +} From 3f077821c9b505cd34e062ac11e65b6176ea6489 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 21:14:46 +0300 Subject: [PATCH 107/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 9 +++++---- polybot/Dockerfile | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 0b4b190d..9ee41bd8 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -26,10 +26,11 @@ pipeline { sh """ cd polybot echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${DOCKER_REPO}:latest + + docker build -t beny14/${IMG_NAME} . + docker tag beny14/${IMG_NAME} beny14/${IMG_NAME} + docker push beny14/${IMG_NAME} + docker push beny14/${IMG_NAME} """ } } diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 4ee7b2e0..b7f2d8aa 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ libglib2.0-0 \ + python3-venv \ && rm -rf /var/lib/apt/lists/* # Copy the requirements file into the container From d6a1c43a1d1a21ba7cdd708ba50e7ddc4db61750 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 29 Jun 2024 21:56:04 +0300 Subject: [PATCH 108/241] update build.Jenkinsfile with step 6 --- polybot/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polybot/Dockerfile b/polybot/Dockerfile index b7f2d8aa..2714f025 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -16,13 +16,13 @@ RUN apt-get update && apt-get install -y \ COPY requirements.txt . # Install the required Python packages -RUN pip install --no-cache-dir --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt +RUN sudo pip install --no-cache-dir --upgrade pip +RUN sudo pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container COPY . . - +RUN cd polybot # Specify the command to run the application -CMD ["python3", "polybot/bot.py"] +CMD ["python3", "bot.py"] EXPOSE 5000 From 4842a17109c1d67fa7a0958e5a22493f1ca142f5 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 30 Jun 2024 17:38:34 +0300 Subject: [PATCH 109/241] update build.Jenkinsfile with step 6 --- build.Jenkinsfile | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 9ee41bd8..e230287d 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,6 +1,6 @@ pipeline { options { - buildDiscarder(logRotator(daysToKeepStr: '30')) + buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() } @@ -22,15 +22,14 @@ pipeline { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { - // Use correct Docker login syntax sh """ cd polybot echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t beny14/${IMG_NAME} . - docker tag beny14/${IMG_NAME} beny14/${IMG_NAME} - docker push beny14/${IMG_NAME} - docker push beny14/${IMG_NAME} + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${DOCKER_REPO}:latest """ } } @@ -40,7 +39,6 @@ pipeline { stage('Test') { steps { script { - // Run pylint in a virtual environment sh ''' cd polybot python3 -m venv venv @@ -56,12 +54,9 @@ pipeline { post { always { - // Clean up old containers but not the new one script { - // Fetch the container ID of the currently running container def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() - // Remove all stopped containers with the same image except the current one sh """ for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then @@ -71,15 +66,13 @@ pipeline { """ } - // Clean up old Docker images but keep the new one script { sh """ docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ } - // Clean build artifacts from Jenkins server cleanWs() } } -} +} \ No newline at end of file From 43b614e5f55c8bf0869c07246c922bf9d24a9622 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 30 Jun 2024 20:33:34 +0300 Subject: [PATCH 110/241] update build.Jenkinsfile with step 6 --- .gitignore | 3 ++- polybot/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2dc53ca3..6b6a2251 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ __pycache__/ # Distribution / packaging .Python -build/ +bu develop-eggs/ dist/ downloads/ @@ -25,6 +25,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +jenkis_try # PyInstaller # Usually these files are written by a python script from a template diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 2714f025..b75fc809 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -16,8 +16,8 @@ RUN apt-get update && apt-get install -y \ COPY requirements.txt . # Install the required Python packages -RUN sudo pip install --no-cache-dir --upgrade pip -RUN sudo pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container COPY . . From 5db13578b3fa343a8cb88ed4b56d2015892085f2 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 18:39:44 +0300 Subject: [PATCH 111/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index e230287d..8dfe7186 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -10,12 +10,12 @@ pipeline { DOCKER_REPO = "beny14/polybot" } - agent { - docker { - image 'beny14/dockerfile_agent:latest' - args '--user root -v /var/run/docker.sock:/var/run/docker.sock' - } - } +// agent { +// docker { +// image 'beny14/dockerfile_agent:latest' +// args '--user root -v /var/run/docker.sock:/var/run/docker.sock' +// } +// } stages { stage('Build') { From 8c282b2160d454f2d155f3597ebef1fd1782c8d0 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 18:41:42 +0300 Subject: [PATCH 112/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 8dfe7186..e230287d 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -10,12 +10,12 @@ pipeline { DOCKER_REPO = "beny14/polybot" } -// agent { -// docker { -// image 'beny14/dockerfile_agent:latest' -// args '--user root -v /var/run/docker.sock:/var/run/docker.sock' -// } -// } + agent { + docker { + image 'beny14/dockerfile_agent:latest' + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' + } + } stages { stage('Build') { From 68bcbfee8a886a8f08a8d07a89843591b259427f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 18:54:33 +0300 Subject: [PATCH 113/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 7 +++---- requirements.txt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index e230287d..454d3c04 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,9 +23,8 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { sh """ - cd polybot - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} @@ -40,11 +39,11 @@ pipeline { steps { script { sh ''' - cd polybot + python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - python3 -m pylint *.py + python3 -m pylint polybot/*.py deactivate ''' } diff --git a/requirements.txt b/requirements.txt index ddcfafc3..79d9a6ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ requests>=2.31.0 flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 -opencv-python>=4.5.3.56 +opencv-python>=4.5.3.56 \ No newline at end of file From f101ed7a15efd538573e418734c832495502483b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 19:28:02 +0300 Subject: [PATCH 114/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 3 +-- jenkis_try/try.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 jenkis_try/try.py diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 454d3c04..e97ae3bf 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,12 +23,11 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { sh """ - + cd polybot echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${DOCKER_REPO}:latest """ } } diff --git a/jenkis_try/try.py b/jenkis_try/try.py deleted file mode 100644 index ca79f4b1..00000000 --- a/jenkis_try/try.py +++ /dev/null @@ -1 +0,0 @@ -he21122 From 4c3a31304de016a8d1e7c97e06afb053c04d6c94 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 19:36:38 +0300 Subject: [PATCH 115/241] update build.Jenkinsfile with step 6 , 2 --- Dockerfile | 28 ++++++++++++++++++++++++++++ build.Jenkinsfile | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b75fc809 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Use the official Python slim image +FROM python:3.10.12-slim-bullseye + +# Set the working directory in the container +WORKDIR /app + +# Install required system packages +RUN apt-get update && apt-get install -y \ + libglib2.0-0 \ + libgl1-mesa-glx \ + libglib2.0-0 \ + python3-venv \ + && rm -rf /var/lib/apt/lists/* + +# Copy the requirements file into the container +COPY requirements.txt . + +# Install the required Python packages +RUN pip install --no-cache-dir --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code into the container +COPY . . +RUN cd polybot +# Specify the command to run the application +CMD ["python3", "bot.py"] + +EXPOSE 5000 diff --git a/build.Jenkinsfile b/build.Jenkinsfile index e97ae3bf..4cc373ef 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,7 +23,7 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { sh """ - cd polybot + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest From 0dc19cdc7b6194bd2ef6dec73e1dd374a483628d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 19:44:01 +0300 Subject: [PATCH 116/241] update build.Jenkinsfile with step 6 , 2 --- Dockerfile | 20 +++++++++++--------- build.Jenkinsfile | 2 -- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index b75fc809..0bda9473 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -# Use the official Python slim image +# Use an official Python runtime as a parent image FROM python:3.10.12-slim-bullseye # Set the working directory in the container WORKDIR /app -# Install required system packages +# Install dependencies RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ @@ -12,17 +12,19 @@ RUN apt-get update && apt-get install -y \ python3-venv \ && rm -rf /var/lib/apt/lists/* -# Copy the requirements file into the container +# Copy the requirements file and install Python dependencies COPY requirements.txt . - -# Install the required Python packages RUN pip install --no-cache-dir --upgrade pip RUN pip install --no-cache-dir -r requirements.txt -# Copy the rest of the application code into the container +# Copy the rest of the application code COPY . . -RUN cd polybot -# Specify the command to run the application + +# Set the working directory to the polybot directory +WORKDIR /app/polybot + +# Run the bot when the container launches CMD ["python3", "bot.py"] -EXPOSE 5000 +# Expose port 5000 +EXPOSE 5000 \ No newline at end of file diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 4cc373ef..ad87ce5d 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,7 +23,6 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest @@ -38,7 +37,6 @@ pipeline { steps { script { sh ''' - python3 -m venv venv . venv/bin/activate pip install -r requirements.txt From ff5056f92add410213cec1c820b2315c92b7a6d3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 19:49:35 +0300 Subject: [PATCH 117/241] update build.Jenkinsfile with step 6 , 2 --- Dockerfile | 5 +++-- build.Jenkinsfile | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0bda9473..946256cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,6 @@ WORKDIR /app RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ - libglib2.0-0 \ python3-venv \ && rm -rf /var/lib/apt/lists/* @@ -27,4 +26,6 @@ WORKDIR /app/polybot CMD ["python3", "bot.py"] # Expose port 5000 -EXPOSE 5000 \ No newline at end of file +EXPOSE 5000 + +#CMD "python3 -m polybot.bot" diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ad87ce5d..6cc8f6f7 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -36,13 +36,15 @@ pipeline { stage('Test') { steps { script { - sh ''' - python3 -m venv venv - . venv/bin/activate - pip install -r requirements.txt - python3 -m pylint polybot/*.py - deactivate - ''' + docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { + sh ''' + python3 -m venv venv + . venv/bin/activate + pip install -r requirements.txt + python3 -m pylint polybot/*.py + deactivate + ''' + } } } } From c3d1f6d3f02ffb9dcff47cafaf5bee8c638537f4 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 20:16:16 +0300 Subject: [PATCH 118/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 5 ++--- polybot/bot.py | 23 +++++++++++++++-------- polybot/requirements.txt | 3 ++- requirements.txt | 3 ++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 6cc8f6f7..c4fd0b7a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,6 +1,6 @@ pipeline { options { - buildDiscarder(logRotator(daysToKeepStr: '14')) + buildDiscarder(logRotator(daysToKeepStr: '3')) disableConcurrentBuilds() timestamps() } @@ -48,7 +48,7 @@ pipeline { } } } - } + post { always { @@ -63,7 +63,6 @@ pipeline { done """ } - script { sh """ docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true diff --git a/polybot/bot.py b/polybot/bot.py index 2c8ec796..92a4049c 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -7,7 +7,6 @@ # load environment variables load_dotenv() TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN') - # Check if TELEGRAM_TOKEN is not none if TELEGRAM_TOKEN is None: print("Error : TELEGRAM_TOKEN is not set in the .env file.") @@ -19,6 +18,7 @@ # Dictionary to store images temporarily user_images = {} + # handler for the /start command @bot.message_handler(commands=['start']) def handle_start(message): @@ -27,13 +27,14 @@ def handle_start(message): "- Rotate: turning the image upside down.\n" "- Salt and Pepper: Adds random bright and dark pixels to an image.\n" "- Segment: Divides an image into parts based on color.\n" - "- Grayscale: Converts the image to grayscale.\n" + "- Grayscale: Converts the image to grayscale.\n" "- Sharpen: Enhances the edges and details in the image.\n" - "- Emboss: Creates a raised effect by highlighting the edges.\n" + "- Emboss: Creates a raised effect by highlighting the edges.\n" "- Invert Colors: Inverts the colors of the image.\n" "- Oil Painting: Applies an oil painting-like effect to the image.\n" "- Cartoonize: Creates a cartoon-like version of the image.\n") + # handler for receiving photos @bot.message_handler(content_types=['photo']) def handle_image(message): @@ -84,18 +85,23 @@ def handle_image(message): # this is the first img print("This is the first image for concatenation") user_images[message.chat.id]['concat_pending'] = image_path - bot.reply_to(message, "First image saved successfully! Now please send the second image to concatenate with.") + bot.reply_to(message, + "First image saved successfully! Now please send the second image to concatenate with.") else: # this is the first img print("This is the first image received") user_images[message.chat.id] = {'concat_pending': image_path} - bot.reply_to(message, "First image saved successfully! To apply the concatenation filter, please send another image or choose a filter from the list at the top of the page to apply a filter.") + bot.reply_to(message, + "First image saved successfully! To apply the concatenation filter, please send another image or choose a filter from the list at the top of the page to apply a filter.") except Exception as e: print(f"Error handling image: {e}") bot.reply_to(message, f"Error handling image: {e}") + # handler for filter selection -@bot.message_handler(func=lambda message: message.text.lower() in ['blur', 'rotate', 'salt and pepper', 'segment','grayscale','sharpen','emboss','invert colors','oil painting','cartoonize']) +@bot.message_handler( + func=lambda message: message.text.lower() in ['blur', 'rotate', 'salt and pepper', 'segment', 'grayscale', + 'sharpen', 'emboss', 'invert colors', 'oil painting', 'cartoonize']) def handle_filter(message): try: # Check if the user has previously sent an image @@ -136,7 +142,8 @@ def handle_filter(message): # check if the filter was applied successfully if processed_image is not None: # save and send the processed image - processed_image_path = img_processor.save_image(processed_image, suffix=f'_{filter_name.replace(" ", "_")}') + processed_image_path = img_processor.save_image(processed_image, + suffix=f'_{filter_name.replace(" ", "_")}') with open(processed_image_path, 'rb') as photo_file: bot.send_photo(message.chat.id, photo_file) else: @@ -150,4 +157,4 @@ def handle_filter(message): bot.reply_to(message, f"Error processing image: {e}") -bot.polling() \ No newline at end of file +bot.polling() diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 79d9a6ef..a011db94 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -4,4 +4,5 @@ requests>=2.31.0 flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 -opencv-python>=4.5.3.56 \ No newline at end of file +opencv-python>=4.5.3.56 +telebot>=0.0.4 diff --git a/requirements.txt b/requirements.txt index 79d9a6ef..a011db94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ requests>=2.31.0 flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 -opencv-python>=4.5.3.56 \ No newline at end of file +opencv-python>=4.5.3.56 +telebot>=0.0.4 From d229cac9c6b97394ecbefb04d9c19e895ad306b3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 20:37:49 +0300 Subject: [PATCH 119/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index c4fd0b7a..f5feb8bb 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -72,4 +72,5 @@ pipeline { cleanWs() } } + } \ No newline at end of file From 157566f2ca3acaea91b1fad034690faf485975b5 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 20:41:00 +0300 Subject: [PATCH 120/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index f5feb8bb..513809e6 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,10 +23,10 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:${BUILD_NUMBER} + echo \${USERPASS} | docker login -u \${USERNAME} --password-stdin + docker build -t \${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag \${DOCKER_REPO}:${BUILD_NUMBER} \${DOCKER_REPO}:latest + docker push \${DOCKER_REPO}:${BUILD_NUMBER} """ } } @@ -36,10 +36,10 @@ pipeline { stage('Test') { steps { script { - docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { + docker.image("\${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' python3 -m venv venv - . venv/bin/activate + source venv/bin/activate pip install -r requirements.txt python3 -m pylint polybot/*.py deactivate @@ -49,28 +49,29 @@ pipeline { } } + } post { always { script { - def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() + def containerId = sh(script: "docker ps -q -f ancestor=\${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() sh """ - for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do + for id in \$(docker ps -a -q -f ancestor=\${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then docker rm -f \$id || true fi done """ } + script { sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '\${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ } cleanWs() } } - } \ No newline at end of file From afc141f5f0935d851bf00f5141aa6ab2c25dd206 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 20:57:18 +0300 Subject: [PATCH 121/241] update build.Jenkinsfile with step 6 , 2 --- polybot/requirements.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index a011db94..f0633561 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -5,4 +5,4 @@ flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 opencv-python>=4.5.3.56 -telebot>=0.0.4 +telebot==0.0.4 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a011db94..f0633561 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 opencv-python>=4.5.3.56 -telebot>=0.0.4 +telebot==0.0.4 \ No newline at end of file From b725f4cc1b47bcd97383868d02a01143563c76a0 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 21:07:31 +0300 Subject: [PATCH 122/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 513809e6..03cfb27b 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,6 +1,6 @@ pipeline { options { - buildDiscarder(logRotator(daysToKeepStr: '3')) + buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() } @@ -23,10 +23,10 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { sh """ - echo \${USERPASS} | docker login -u \${USERNAME} --password-stdin - docker build -t \${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag \${DOCKER_REPO}:${BUILD_NUMBER} \${DOCKER_REPO}:latest - docker push \${DOCKER_REPO}:${BUILD_NUMBER} + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} """ } } @@ -36,10 +36,10 @@ pipeline { stage('Test') { steps { script { - docker.image("\${DOCKER_REPO}:${BUILD_NUMBER}").inside { + docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' python3 -m venv venv - source venv/bin/activate + . venv/bin/activate pip install -r requirements.txt python3 -m pylint polybot/*.py deactivate @@ -49,25 +49,23 @@ pipeline { } } - } post { always { script { - def containerId = sh(script: "docker ps -q -f ancestor=\${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() + def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() sh """ - for id in \$(docker ps -a -q -f ancestor=\${DOCKER_REPO}:${BUILD_NUMBER}); do + for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then docker rm -f \$id || true fi done """ } - script { sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '\${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ } From 8b3f4e7917cb3c9199de16d355ee4f40a167f02a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 21:09:47 +0300 Subject: [PATCH 123/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 03cfb27b..7fb14b14 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -48,7 +48,7 @@ pipeline { } } } - + } // End of stages block post { always { From 245d738dd6fda917cd022ccc98c619bbf39039b6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 21:19:54 +0300 Subject: [PATCH 124/241] update build.Jenkinsfile with step 6 , 2 --- polybot/bot.py | 63 +++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/polybot/bot.py b/polybot/bot.py index 92a4049c..35a66600 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -1,15 +1,16 @@ +import os import telebot import cv2 -from polybot.img_proc import Img from dotenv import load_dotenv -import os +from polybot.img_proc import Img # load environment variables load_dotenv() + +# Check if TELEGRAM_TOKEN is set in the .env file TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN') -# Check if TELEGRAM_TOKEN is not none -if TELEGRAM_TOKEN is None: - print("Error : TELEGRAM_TOKEN is not set in the .env file.") +if not TELEGRAM_TOKEN: + print("Error: TELEGRAM_TOKEN is not set in the .env file.") exit(1) # initialize telegram-bot @@ -18,22 +19,20 @@ # Dictionary to store images temporarily user_images = {} - # handler for the /start command @bot.message_handler(commands=['start']) def handle_start(message): - bot.send_message(message.chat.id, "Hello!\n\n Send me an image then choose a filter , options:\n" - "- Blur: Apply a blur to the image to reduce noise and detail.\n" - "- Rotate: turning the image upside down.\n" - "- Salt and Pepper: Adds random bright and dark pixels to an image.\n" - "- Segment: Divides an image into parts based on color.\n" - "- Grayscale: Converts the image to grayscale.\n" - "- Sharpen: Enhances the edges and details in the image.\n" - "- Emboss: Creates a raised effect by highlighting the edges.\n" - "- Invert Colors: Inverts the colors of the image.\n" - "- Oil Painting: Applies an oil painting-like effect to the image.\n" - "- Cartoonize: Creates a cartoon-like version of the image.\n") - + bot.send_message(message.chat.id, "Hello!\n\nSend me an image and choose a filter:\n" + "- Blur: Reduce noise and detail.\n" + "- Rotate: Turn the image upside down.\n" + "- Salt and Pepper: Add random bright and dark pixels.\n" + "- Segment: Divide the image based on color.\n" + "- Grayscale: Convert to grayscale.\n" + "- Sharpen: Enhance edges and details.\n" + "- Emboss: Create a raised effect.\n" + "- Invert Colors: Invert the image colors.\n" + "- Oil Painting: Apply an oil painting-like effect.\n" + "- Cartoonize: Create a cartoon-like version.\n") # handler for receiving photos @bot.message_handler(content_types=['photo']) @@ -52,26 +51,26 @@ def handle_image(message): with open(image_path, 'wb') as new_file: new_file.write(downloaded_file) - # check if this is the first img or the second img for concat + # check if this is the first image or the second image for concatenation if message.chat.id in user_images: print("User already has an image in memory") if 'concat_pending' in user_images[message.chat.id]: print("This is the second image for concatenation") - # this is the second image for concat + # this is the second image for concatenation second_image_path = image_path first_image_path = user_images[message.chat.id]['concat_pending'] - del user_images[message.chat.id]['concat_pending'] # remove the pending to free it to next pending + del user_images[message.chat.id]['concat_pending'] # load the images + img_processor = Img(first_image_path) first_image_data = cv2.imread(first_image_path) second_image_data = cv2.imread(second_image_path) - # concat the imges - img_processor = Img(first_image_path) + # concatenate the images concatenated_image = img_processor.concat(second_image_data) if concatenated_image is not None: print("Concatenation successful") - # save and send the concat img + # save and send the concatenated image processed_image_path = img_processor.save_image(concatenated_image, suffix='_concatenated') with open(processed_image_path, 'rb') as photo_file: bot.send_photo(message.chat.id, photo_file) @@ -82,22 +81,19 @@ def handle_image(message): # clear user history del user_images[message.chat.id] else: - # this is the first img + # this is the first image print("This is the first image for concatenation") user_images[message.chat.id]['concat_pending'] = image_path - bot.reply_to(message, - "First image saved successfully! Now please send the second image to concatenate with.") + bot.reply_to(message, "First image saved successfully! Now please send the second image to concatenate with.") else: - # this is the first img + # this is the first image print("This is the first image received") user_images[message.chat.id] = {'concat_pending': image_path} - bot.reply_to(message, - "First image saved successfully! To apply the concatenation filter, please send another image or choose a filter from the list at the top of the page to apply a filter.") + bot.reply_to(message, "First image saved successfully! To apply the concatenation filter, please send another image or choose a filter from the list at the top of the page to apply a filter.") except Exception as e: print(f"Error handling image: {e}") bot.reply_to(message, f"Error handling image: {e}") - # handler for filter selection @bot.message_handler( func=lambda message: message.text.lower() in ['blur', 'rotate', 'salt and pepper', 'segment', 'grayscale', @@ -142,8 +138,7 @@ def handle_filter(message): # check if the filter was applied successfully if processed_image is not None: # save and send the processed image - processed_image_path = img_processor.save_image(processed_image, - suffix=f'_{filter_name.replace(" ", "_")}') + processed_image_path = img_processor.save_image(processed_image, suffix=f'_{filter_name.replace(" ", "_")}') with open(processed_image_path, 'rb') as photo_file: bot.send_photo(message.chat.id, photo_file) else: @@ -156,5 +151,5 @@ def handle_filter(message): except Exception as e: bot.reply_to(message, f"Error processing image: {e}") - +# Start polling bot.polling() From df786425727f248d2cb66ceaa60cbcc635cd17aa Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 21:25:47 +0300 Subject: [PATCH 125/241] update build.Jenkinsfile with step 6 , 2 --- polybot/bot.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/polybot/bot.py b/polybot/bot.py index 35a66600..b16526a1 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -22,17 +22,18 @@ # handler for the /start command @bot.message_handler(commands=['start']) def handle_start(message): - bot.send_message(message.chat.id, "Hello!\n\nSend me an image and choose a filter:\n" - "- Blur: Reduce noise and detail.\n" - "- Rotate: Turn the image upside down.\n" - "- Salt and Pepper: Add random bright and dark pixels.\n" - "- Segment: Divide the image based on color.\n" - "- Grayscale: Convert to grayscale.\n" - "- Sharpen: Enhance edges and details.\n" - "- Emboss: Create a raised effect.\n" - "- Invert Colors: Invert the image colors.\n" - "- Oil Painting: Apply an oil painting-like effect.\n" - "- Cartoonize: Create a cartoon-like version.\n") + bot.send_message(message.chat.id, + "Hello!\n\nSend me an image and choose a filter:\n" + "- Blur: Reduce noise and detail.\n" + "- Rotate: Turn the image upside down.\n" + "- Salt and Pepper: Add random bright and dark pixels.\n" + "- Segment: Divide the image based on color.\n" + "- Grayscale: Convert to grayscale.\n" + "- Sharpen: Enhance edges and details.\n" + "- Emboss: Create a raised effect.\n" + "- Invert Colors: Invert the image colors.\n" + "- Oil Painting: Apply an oil painting-like effect.\n" + "- Cartoonize: Create a cartoon-like version.\n") # handler for receiving photos @bot.message_handler(content_types=['photo']) From 2a515ea7cc09fc8ddb0a9f9a904a5662a63f2432 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 1 Jul 2024 22:28:43 +0300 Subject: [PATCH 126/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 7fb14b14..f54de1aa 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -41,6 +41,8 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt + pylint --disable=C0301 polybot/*.py + pylint --disable=C0114 polybot/*.py python3 -m pylint polybot/*.py deactivate ''' From 31d2b6f6409b66a10c495335bde5dcd00df35d8a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 3 Jul 2024 19:31:38 +0300 Subject: [PATCH 127/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index f54de1aa..d585f469 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -43,6 +43,11 @@ pipeline { pip install -r requirements.txt pylint --disable=C0301 polybot/*.py pylint --disable=C0114 polybot/*.py + pylint --disable=E1101 polybot/*.py + pylint --disable=C0116 polybot/*.py + pylint --disable=C0103 polybot/*.py + pylint --disable=W0718 polybot/*.py + pylint --disable=E0401 polybot/*.py python3 -m pylint polybot/*.py deactivate ''' From d533249d05739c1015eafdb5bd71a03bac1fa2f2 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 3 Jul 2024 19:37:23 +0300 Subject: [PATCH 128/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index d585f469..09abf98f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -48,6 +48,7 @@ pipeline { pylint --disable=C0103 polybot/*.py pylint --disable=W0718 polybot/*.py pylint --disable=E0401 polybot/*.py + pylint --disable=W0613 polybot/*.py python3 -m pylint polybot/*.py deactivate ''' From 69943adee992f1ca91cf552cfdd14847e921d338 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 3 Jul 2024 19:49:44 +0300 Subject: [PATCH 129/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 09abf98f..4a35e7b8 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -41,14 +41,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=C0301 polybot/*.py - pylint --disable=C0114 polybot/*.py - pylint --disable=E1101 polybot/*.py - pylint --disable=C0116 polybot/*.py - pylint --disable=C0103 polybot/*.py - pylint --disable=W0718 polybot/*.py - pylint --disable=E0401 polybot/*.py - pylint --disable=W0613 polybot/*.py + pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613 polybot/*.py python3 -m pylint polybot/*.py deactivate ''' From c1607840dcbb1d943f97d3c1111927aa46a803ae Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 3 Jul 2024 19:59:46 +0300 Subject: [PATCH 130/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 4a35e7b8..30bf2dff 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -41,7 +41,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613 polybot/*.py + pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py python3 -m pylint polybot/*.py deactivate ''' From c7780d30a5b66548e9e711ffa0927d14c38de401 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 3 Jul 2024 20:10:19 +0300 Subject: [PATCH 131/241] update build.Jenkinsfile with step 6 , 2 --- build.Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 30bf2dff..01cfd085 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -42,7 +42,6 @@ pipeline { . venv/bin/activate pip install -r requirements.txt pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py - python3 -m pylint polybot/*.py deactivate ''' } From 4c9ff808355e9a904243c1924acebefd684d6425 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 20:09:55 +0300 Subject: [PATCH 132/241] update build.Jenkinsfile add snyk --- build.Jenkinsfile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 01cfd085..a7d778a1 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -8,6 +8,7 @@ pipeline { environment { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" + SNYK_TOKEN = credentials('SNYK_TOKEN') // Use the credential you created } agent { @@ -33,6 +34,19 @@ pipeline { } } + stage('Snyk Scan') { + steps { + withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { + script { + sh ''' + snyk auth ${SNYK_TOKEN} + snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} + ''' + } + } + } + } + stage('Test') { steps { script { @@ -48,7 +62,7 @@ pipeline { } } } - } // End of stages block + } post { always { @@ -72,4 +86,4 @@ pipeline { cleanWs() } } -} \ No newline at end of file +} From 3d358b72048db94dddcbac0a964e3a2d0b8f0ffc Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 20:14:00 +0300 Subject: [PATCH 133/241] update build.Jenkinsfile add snyk --- build.Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a7d778a1..7957ff9c 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -8,7 +8,6 @@ pipeline { environment { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" - SNYK_TOKEN = credentials('SNYK_TOKEN') // Use the credential you created } agent { From ed8414f6567ddf6e08d09af4e0d32512d7507c1f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 20:41:01 +0300 Subject: [PATCH 134/241] update build.Jenkinsfile add snyk --- build.Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 7957ff9c..ce641c01 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -8,6 +8,7 @@ pipeline { environment { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" + SNYK_TOKEN = credentials('SNYK_TOKEN') } agent { @@ -37,10 +38,10 @@ pipeline { steps { withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { script { - sh ''' + sh """ snyk auth ${SNYK_TOKEN} snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} - ''' + """ } } } From 8e93ef9d6064ce1e6b044a22ab88ffb7beb21f9b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 20:48:03 +0300 Subject: [PATCH 135/241] update build.Jenkinsfile add snyk --- build.Jenkinsfile | 57 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ce641c01..7c451b80 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -23,12 +23,16 @@ pipeline { steps { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { - sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:${BUILD_NUMBER} - """ + try { + sh """ + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} + """ + } catch (Exception e) { + error "Build failed: ${e.getMessage()}" + } } } } @@ -38,10 +42,14 @@ pipeline { steps { withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { script { - sh """ - snyk auth ${SNYK_TOKEN} - snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} - """ + try { + sh """ + snyk auth ${SNYK_TOKEN} + snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} + """ + } catch (Exception e) { + error "Snyk scan failed: ${e.getMessage()}" + } } } } @@ -50,14 +58,18 @@ pipeline { stage('Test') { steps { script { - docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { - sh ''' - python3 -m venv venv - . venv/bin/activate - pip install -r requirements.txt - pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py - deactivate - ''' + try { + docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { + sh ''' + python3 -m venv venv + . venv/bin/activate + pip install -r requirements.txt + pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py + deactivate + ''' + } + } catch (Exception e) { + error "Test failed: ${e.getMessage()}" } } } @@ -86,4 +98,13 @@ pipeline { cleanWs() } } + + post { + failure { + script { + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' + echo "Error occurred: ${errorMessage}" + } + } + } } From ef3e98b431e67b8e5730161f689dd16d8316a80e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 20:51:12 +0300 Subject: [PATCH 136/241] update build.Jenkinsfile add snyk --- build.Jenkinsfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 7c451b80..54669b34 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -97,9 +97,7 @@ pipeline { cleanWs() } - } - post { failure { script { def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' From c7d5ad3a851eb1347d7ed3ef86755f85ae65ef38 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 21:04:21 +0300 Subject: [PATCH 137/241] update build.Jenkinsfile add snyk --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 54669b34..ed01cb7a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -45,7 +45,7 @@ pipeline { try { sh """ snyk auth ${SNYK_TOKEN} - snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} + snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" """ } catch (Exception e) { error "Snyk scan failed: ${e.getMessage()}" From 7d69e4686999474d357d4857c5bc1879c5a4f337 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 21:21:57 +0300 Subject: [PATCH 138/241] update build.Jenkinsfile add snyk --- .snyk | 10 ++++++++++ build.Jenkinsfile | 2 +- deploy.Jenkinsfile | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .snyk diff --git a/.snyk b/.snyk new file mode 100644 index 00000000..4f140e35 --- /dev/null +++ b/.snyk @@ -0,0 +1,10 @@ +version: v1.15.0 +ignore: + "SNYK-ID-EXAMPLE": + - "*": + reason: "Reason for ignoring this vulnerability" + expires: "2024-12-31T12:00:00Z" + "ANOTHER-SNYK-ID": + - "*": + reason: "Reason for ignoring this vulnerability" + expires: "2024-12-31T12:00:00Z" \ No newline at end of file diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ed01cb7a..3904abc4 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -45,7 +45,7 @@ pipeline { try { sh """ snyk auth ${SNYK_TOKEN} - snyk test --docker ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" """ } catch (Exception e) { error "Snyk scan failed: ${e.getMessage()}" diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index ada69994..3382f811 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stage('Deploy') { steps { sh ''' - echo "deploying to k8s cluster ..( or any other alternative)" + echo "docker push... " ''' } } From 3d67e0d59b46e7470e050de1ccce0ad5533bfaa0 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 21:52:31 +0300 Subject: [PATCH 139/241] update build.Jenkinsfile add snyk --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 946256cb..f53712fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ python3-venv \ + snyk\ && rm -rf /var/lib/apt/lists/* # Copy the requirements file and install Python dependencies From d52b5a0050eef690552cebe8995bdd8889eede0a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 21:56:08 +0300 Subject: [PATCH 140/241] update build.Jenkinsfile add snyk --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f53712fc..4f56ecbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use an official Python runtime as a parent image -FROM python:3.10.12-slim-bullseye +FROM python:3.13.0b2-slim # Set the working directory in the container WORKDIR /app @@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ python3-venv \ - snyk\ + snyk \ && rm -rf /var/lib/apt/lists/* # Copy the requirements file and install Python dependencies From a8ce31c30a2852f7ea92723531f13597d7a783e4 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 22:04:35 +0300 Subject: [PATCH 141/241] update build.Jenkinsfile add snyk --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4f56ecbf..9cf5fad4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,10 @@ RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ python3-venv \ - snyk \ && rm -rf /var/lib/apt/lists/* +RUN npm install -g snyk + # Copy the requirements file and install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip From 63b67ab290db055b6e50ea1351698fe47fc28966 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 22:06:48 +0300 Subject: [PATCH 142/241] update build.Jenkinsfile add snyk --- Dockerfile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9cf5fad4..71fbd282 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,21 @@ # Use an official Python runtime as a parent image FROM python:3.13.0b2-slim -# Set the working directory in the container -WORKDIR /app - -# Install dependencies +# Install system dependencies RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ python3-venv \ && rm -rf /var/lib/apt/lists/* +# Install Node.js and npm (if not already included in base image) +# Example if you decide to use Node.js and npm +# RUN apt-get install -y nodejs npm + +# Set the working directory in the container +WORKDIR /app + +# Install snyk globally using npm RUN npm install -g snyk # Copy the requirements file and install Python dependencies @@ -27,7 +32,5 @@ WORKDIR /app/polybot # Run the bot when the container launches CMD ["python3", "bot.py"] -# Expose port 5000 +# Expose port 5000 (if necessary) EXPOSE 5000 - -#CMD "python3 -m polybot.bot" From 17966551962c6d3b68d2efff5ba274fe3c07b822 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 22:12:46 +0300 Subject: [PATCH 143/241] update build.Jenkinsfile add snyk --- Dockerfile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 71fbd282..988eeba7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,17 @@ # Use an official Python runtime as a parent image FROM python:3.13.0b2-slim -# Install system dependencies +# Set the working directory in the container +WORKDIR /app + +# Install dependencies RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libgl1-mesa-glx \ python3-venv \ + npm \ && rm -rf /var/lib/apt/lists/* -# Install Node.js and npm (if not already included in base image) -# Example if you decide to use Node.js and npm -# RUN apt-get install -y nodejs npm - -# Set the working directory in the container -WORKDIR /app - -# Install snyk globally using npm RUN npm install -g snyk # Copy the requirements file and install Python dependencies @@ -32,5 +28,7 @@ WORKDIR /app/polybot # Run the bot when the container launches CMD ["python3", "bot.py"] -# Expose port 5000 (if necessary) +# Expose port 5000 EXPOSE 5000 + +#CMD "python3 -m polybot.bot" From 827ebce31ef71b0c2d66d0a9af3e01419c0940d6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 22:49:00 +0300 Subject: [PATCH 144/241] update build.Jenkinsfile add snyk --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 988eeba7..f07ef606 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,14 @@ RUN apt-get update && apt-get install -y \ libgl1-mesa-glx \ python3-venv \ npm \ + autoremove \ && rm -rf /var/lib/apt/lists/* RUN npm install -g snyk +# Install zlib with security updates (if available) +RUN apt-get update && apt-get install -y --only-upgrade zlib1g + # Copy the requirements file and install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip From 54e66054e59d55f65ccb36c9ed8526b281ff4a4f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 22:50:41 +0300 Subject: [PATCH 145/241] update build.Jenkinsfile add snyk --- Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f07ef606..58510b3c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,12 +5,13 @@ FROM python:3.13.0b2-slim WORKDIR /app # Install dependencies -RUN apt-get update && apt-get install -y \ - libglib2.0-0 \ - libgl1-mesa-glx \ - python3-venv \ - npm \ - autoremove \ +RUN apt-get update \ + && apt-get install -y \ + libglib2.0-0 \ + libgl1-mesa-glx \ + python3-venv \ + npm \ + && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* RUN npm install -g snyk From 12fc7b6d3afb348e642f0bd40e3617eb495c24cc Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 23:08:18 +0300 Subject: [PATCH 146/241] update build.Jenkinsfile add snyk --- Dockerfile | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 58510b3c..9b5c84aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,25 +4,25 @@ FROM python:3.13.0b2-slim # Set the working directory in the container WORKDIR /app -# Install dependencies +# Install system dependencies RUN apt-get update \ - && apt-get install -y \ + && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ - python3-venv \ npm \ + zlib1g-dev \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* +# Install Snyk globally using npm RUN npm install -g snyk -# Install zlib with security updates (if available) -RUN apt-get update && apt-get install -y --only-upgrade zlib1g - -# Copy the requirements file and install Python dependencies +# Upgrade pip and install Python dependencies COPY requirements.txt . -RUN pip install --no-cache-dir --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt +RUN python -m pip install --upgrade pip \ + && python -m pip install --no-cache-dir -r requirements.txt \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* # Copy the rest of the application code COPY . . @@ -30,10 +30,8 @@ COPY . . # Set the working directory to the polybot directory WORKDIR /app/polybot -# Run the bot when the container launches -CMD ["python3", "bot.py"] - # Expose port 5000 EXPOSE 5000 -#CMD "python3 -m polybot.bot" +# Command to run the bot when the container launches +CMD ["python3", "bot.py"] From e1b0e911bcac69948ba5e31a5240684966360471 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Thu, 4 Jul 2024 23:17:42 +0300 Subject: [PATCH 147/241] update build.Jenkinsfile add snyk --- Dockerfile | 4 +++- polybot/Dockerfile | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b5c84aa..831662bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,15 @@ FROM python:3.13.0b2-slim # Set the working directory in the container WORKDIR /app -# Install system dependencies +# Install system dependencies and build tools RUN apt-get update \ && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ npm \ zlib1g-dev \ + build-essential \ + python3-dev \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* diff --git a/polybot/Dockerfile b/polybot/Dockerfile index b75fc809..831662bd 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -1,28 +1,39 @@ -# Use the official Python slim image -FROM python:3.10.12-slim-bullseye +# Use an official Python runtime as a parent image +FROM python:3.13.0b2-slim # Set the working directory in the container WORKDIR /app -# Install required system packages -RUN apt-get update && apt-get install -y \ - libglib2.0-0 \ - libgl1-mesa-glx \ - libglib2.0-0 \ - python3-venv \ +# Install system dependencies and build tools +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libglib2.0-0 \ + libgl1-mesa-glx \ + npm \ + zlib1g-dev \ + build-essential \ + python3-dev \ + && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* -# Copy the requirements file into the container -COPY requirements.txt . +# Install Snyk globally using npm +RUN npm install -g snyk -# Install the required Python packages -RUN pip install --no-cache-dir --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt +# Upgrade pip and install Python dependencies +COPY requirements.txt . +RUN python -m pip install --upgrade pip \ + && python -m pip install --no-cache-dir -r requirements.txt \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* -# Copy the rest of the application code into the container +# Copy the rest of the application code COPY . . -RUN cd polybot -# Specify the command to run the application -CMD ["python3", "bot.py"] +# Set the working directory to the polybot directory +WORKDIR /app/polybot + +# Expose port 5000 EXPOSE 5000 + +# Command to run the bot when the container launches +CMD ["python3", "bot.py"] From 239f1279e3c1ed8c244cb675f53e44f98c97a223 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 10:40:11 +0300 Subject: [PATCH 148/241] update build.Jenkinsfile add back to last SUCCESS and add snyk --- Dockerfile | 79 +++++++++++++++++++++++--------- build.Jenkinsfile | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 831662bd..df18d57f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,22 @@ + # Use an official Python runtime as a parent image -FROM python:3.13.0b2-slim +FROM python:3.10.12-slim-bullseye # Set the working directory in the container WORKDIR /app -# Install system dependencies and build tools -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - libglib2.0-0 \ - libgl1-mesa-glx \ - npm \ - zlib1g-dev \ - build-essential \ - python3-dev \ - && apt-get autoremove -y \ +# Install dependencies +RUN apt-get update && apt-get install -y \ + libglib2.0-0 \ + libgl1-mesa-glx \ + python3-venv \ + snyk \ && rm -rf /var/lib/apt/lists/* -# Install Snyk globally using npm -RUN npm install -g snyk - -# Upgrade pip and install Python dependencies +# Copy the requirements file and install Python dependencies COPY requirements.txt . -RUN python -m pip install --upgrade pip \ - && python -m pip install --no-cache-dir -r requirements.txt \ - && apt-get autoremove -y \ - && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code COPY . . @@ -32,8 +24,53 @@ COPY . . # Set the working directory to the polybot directory WORKDIR /app/polybot +# Run the bot when the container launches +CMD ["python3", "bot.py"] + # Expose port 5000 EXPOSE 5000 -# Command to run the bot when the container launches -CMD ["python3", "bot.py"] +#CMD "python3 -m polybot.bot" + + + +# +## Use an official Python runtime as a parent image +#FROM python:3.13.0b2-slim +# +## Set the working directory in the container +#WORKDIR /app +# +## Install system dependencies and build tools +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libglib2.0-0 \ +# libgl1-mesa-glx \ +# npm \ +# zlib1g-dev \ +# build-essential \ +# python3-dev \ +# && apt-get autoremove -y \ +# && rm -rf /var/lib/apt/lists/* +# +## Install Snyk globally using npm +#RUN npm install -g snyk +# +## Upgrade pip and install Python dependencies +#COPY requirements.txt . +#RUN python -m pip install --upgrade pip \ +# && python -m pip install --no-cache-dir -r requirements.txt \ +# && apt-get autoremove -y \ +# && rm -rf /var/lib/apt/lists/* +# +## Copy the rest of the application code +#COPY . . +# +## Set the working directory to the polybot directory +#WORKDIR /app/polybot +# +## Expose port 5000 +#EXPOSE 5000 +# +## Command to run the bot when the container launches +#CMD ["python3", "bot.py"] diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3904abc4..bf1ba471 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -106,3 +106,115 @@ pipeline { } } } + + + + +// pipeline { +// options { +// buildDiscarder(logRotator(daysToKeepStr: '14')) +// disableConcurrentBuilds() +// timestamps() +// } +// +// environment { +// IMG_NAME = "polybot:${BUILD_NUMBER}" +// DOCKER_REPO = "beny14/polybot" +// SNYK_TOKEN = credentials('SNYK_TOKEN') +// } +// +// agent { +// docker { +// image 'beny14/dockerfile_agent:latest' +// args '--user root -v /var/run/docker.sock:/var/run/docker.sock' +// } +// } +// +// stages { +// stage('Build') { +// steps { +// withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { +// script { +// try { +// sh """ +// echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin +// docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . +// docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest +// docker push ${DOCKER_REPO}:${BUILD_NUMBER} +// """ +// } catch (Exception e) { +// error "Build failed: ${e.getMessage()}" +// } +// } +// } +// } +// } +// +// stage('Snyk Scan') { +// steps { +// withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { +// script { +// try { +// sh """ +// snyk auth ${SNYK_TOKEN} +// snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" +// """ +// } catch (Exception e) { +// error "Snyk scan failed: ${e.getMessage()}" +// } +// } +// } +// } +// } +// +// stage('Test') { +// steps { +// script { +// try { +// docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { +// sh ''' +// python3 -m venv venv +// . venv/bin/activate +// pip install -r requirements.txt +// pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py +// deactivate +// ''' +// } +// } catch (Exception e) { +// error "Test failed: ${e.getMessage()}" +// } +// } +// } +// } +// } +// +// post { +// always { +// script { +// def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() +// +// sh """ +// for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do +// if [ "\$id" != "${containerId}" ]; then +// docker rm -f \$id || true +// fi +// done +// """ +// } +// script { +// sh """ +// docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true +// """ +// } +// +// cleanWs() +// } +// +// failure { +// script { +// def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' +// echo "Error occurred: ${errorMessage}" +// } +// } +// } +// } From 3d575b86dce5bf8b5cd26215e4f38f357a381fa4 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 10:44:31 +0300 Subject: [PATCH 149/241] update build.Jenkinsfile add back to last SUCCESS and add snyk --- Dockerfile | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index df18d57f..dba1f090 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ - # Use an official Python runtime as a parent image FROM python:3.10.12-slim-bullseye @@ -6,17 +5,22 @@ FROM python:3.10.12-slim-bullseye WORKDIR /app # Install dependencies -RUN apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ - python3-venv \ - snyk \ + curl \ + && apt-get clean \ && rm -rf /var/lib/apt/lists/* +# Install Snyk +RUN curl -Lo snyk https://github.com/snyk/snyk/releases/latest/download/snyk-linux \ + && chmod +x snyk \ + && mv snyk /usr/local/bin/ + # Copy the requirements file and install Python dependencies COPY requirements.txt . -RUN pip install --no-cache-dir --upgrade pip -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code COPY . . @@ -24,11 +28,12 @@ COPY . . # Set the working directory to the polybot directory WORKDIR /app/polybot +# Expose port 5000 +EXPOSE 5000 + # Run the bot when the container launches CMD ["python3", "bot.py"] -# Expose port 5000 -EXPOSE 5000 #CMD "python3 -m polybot.bot" From 7425791263312a3dcedee0019cd129207e6f2c97 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 11:08:19 +0300 Subject: [PATCH 150/241] update build.Jenkinsfile update work with snyk --- Dockerfile | 48 +------------------ build.Jenkinsfile | 114 +--------------------------------------------- 2 files changed, 2 insertions(+), 160 deletions(-) diff --git a/Dockerfile b/Dockerfile index dba1f090..9784422e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use an official Python runtime as a parent image -FROM python:3.10.12-slim-bullseye +FROM python:3.8-slim # Set the working directory in the container WORKDIR /app @@ -33,49 +33,3 @@ EXPOSE 5000 # Run the bot when the container launches CMD ["python3", "bot.py"] - - -#CMD "python3 -m polybot.bot" - - - -# -## Use an official Python runtime as a parent image -#FROM python:3.13.0b2-slim -# -## Set the working directory in the container -#WORKDIR /app -# -## Install system dependencies and build tools -#RUN apt-get update \ -# && apt-get install -y --no-install-recommends \ -# libglib2.0-0 \ -# libgl1-mesa-glx \ -# npm \ -# zlib1g-dev \ -# build-essential \ -# python3-dev \ -# && apt-get autoremove -y \ -# && rm -rf /var/lib/apt/lists/* -# -## Install Snyk globally using npm -#RUN npm install -g snyk -# -## Upgrade pip and install Python dependencies -#COPY requirements.txt . -#RUN python -m pip install --upgrade pip \ -# && python -m pip install --no-cache-dir -r requirements.txt \ -# && apt-get autoremove -y \ -# && rm -rf /var/lib/apt/lists/* -# -## Copy the rest of the application code -#COPY . . -# -## Set the working directory to the polybot directory -#WORKDIR /app/polybot -# -## Expose port 5000 -#EXPOSE 5000 -# -## Command to run the bot when the container launches -#CMD ["python3", "bot.py"] diff --git a/build.Jenkinsfile b/build.Jenkinsfile index bf1ba471..6bb9c9d2 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -48,7 +48,7 @@ pipeline { snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" """ } catch (Exception e) { - error "Snyk scan failed: ${e.getMessage()}" + echo "Snyk scan failed: ${e.getMessage()}" } } } @@ -106,115 +106,3 @@ pipeline { } } } - - - - -// pipeline { -// options { -// buildDiscarder(logRotator(daysToKeepStr: '14')) -// disableConcurrentBuilds() -// timestamps() -// } -// -// environment { -// IMG_NAME = "polybot:${BUILD_NUMBER}" -// DOCKER_REPO = "beny14/polybot" -// SNYK_TOKEN = credentials('SNYK_TOKEN') -// } -// -// agent { -// docker { -// image 'beny14/dockerfile_agent:latest' -// args '--user root -v /var/run/docker.sock:/var/run/docker.sock' -// } -// } -// -// stages { -// stage('Build') { -// steps { -// withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { -// script { -// try { -// sh """ -// echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin -// docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . -// docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest -// docker push ${DOCKER_REPO}:${BUILD_NUMBER} -// """ -// } catch (Exception e) { -// error "Build failed: ${e.getMessage()}" -// } -// } -// } -// } -// } -// -// stage('Snyk Scan') { -// steps { -// withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { -// script { -// try { -// sh """ -// snyk auth ${SNYK_TOKEN} -// snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" -// """ -// } catch (Exception e) { -// error "Snyk scan failed: ${e.getMessage()}" -// } -// } -// } -// } -// } -// -// stage('Test') { -// steps { -// script { -// try { -// docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { -// sh ''' -// python3 -m venv venv -// . venv/bin/activate -// pip install -r requirements.txt -// pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py -// deactivate -// ''' -// } -// } catch (Exception e) { -// error "Test failed: ${e.getMessage()}" -// } -// } -// } -// } -// } -// -// post { -// always { -// script { -// def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() -// -// sh """ -// for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do -// if [ "\$id" != "${containerId}" ]; then -// docker rm -f \$id || true -// fi -// done -// """ -// } -// script { -// sh """ -// docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true -// """ -// } -// -// cleanWs() -// } -// -// failure { -// script { -// def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' -// echo "Error occurred: ${errorMessage}" -// } -// } -// } -// } From 99d78008e35a7ab0a55f17a631392d83151171bd Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 11:47:21 +0300 Subject: [PATCH 151/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 6bb9c9d2..6824e50f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -45,7 +45,8 @@ pipeline { try { sh """ snyk auth ${SNYK_TOKEN} - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" + snyk config set disableSuggestions=true + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" """ } catch (Exception e) { echo "Snyk scan failed: ${e.getMessage()}" @@ -64,7 +65,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py deactivate ''' } From f2d85c6b63a73111595d2e8cf08f6f999bed0c1e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 11:57:55 +0300 Subject: [PATCH 152/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 6824e50f..a50ef50a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -46,7 +46,7 @@ pipeline { sh """ snyk auth ${SNYK_TOKEN} snyk config set disableSuggestions=true - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "snyk container test ${DOCKER_REPO}:${BUILD_NUMBER}" """ } catch (Exception e) { echo "Snyk scan failed: ${e.getMessage()}" From c7b3d9523247b7a1138bc3da60e6aa0801e28840 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 12:14:06 +0300 Subject: [PATCH 153/241] update build.Jenkinsfile update work with snyk --- Dockerfile | 1 + build.Jenkinsfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9784422e..39493888 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ curl \ + python-dotenv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a50ef50a..c51632ea 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -46,7 +46,7 @@ pipeline { sh """ snyk auth ${SNYK_TOKEN} snyk config set disableSuggestions=true - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "snyk container test ${DOCKER_REPO}:${BUILD_NUMBER}" + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed " """ } catch (Exception e) { echo "Snyk scan failed: ${e.getMessage()}" From e4097dd162497b14036d7a2174ec28dde1f0d353 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 12:19:43 +0300 Subject: [PATCH 154/241] update build.Jenkinsfile update work with snyk --- polybot/requirements.txt | 3 ++- requirements.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index f0633561..5257c359 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -5,4 +5,5 @@ flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 opencv-python>=4.5.3.56 -telebot==0.0.4 \ No newline at end of file +telebot==0.0.4 +python-dotenv>=0.19.2 diff --git a/requirements.txt b/requirements.txt index f0633561..5257c359 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ flask>=2.3.2 matplotlib>=3.7.5 pylint>=3.2.3 opencv-python>=4.5.3.56 -telebot==0.0.4 \ No newline at end of file +telebot==0.0.4 +python-dotenv>=0.19.2 From 56a3086a1ccf32a0d21ccf8e3bfe59631de98fb7 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Fri, 5 Jul 2024 12:25:24 +0300 Subject: [PATCH 155/241] update build.Jenkinsfile update work with snyk --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 39493888..9784422e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ curl \ - python-dotenv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* From 55bffe182000c339743361466bcfd52d21ea6888 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 7 Jul 2024 19:46:39 +0300 Subject: [PATCH 156/241] update build.Jenkinsfile update work with snyk --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9784422e..73a8be89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ curl \ + python-dotenv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -32,4 +33,4 @@ WORKDIR /app/polybot EXPOSE 5000 # Run the bot when the container launches -CMD ["python3", "bot.py"] +CMD ["python3", "bot.py"] \ No newline at end of file From 03ec8c351463b012f8c80da04c1e615c56d8253f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 7 Jul 2024 19:47:24 +0300 Subject: [PATCH 157/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index c51632ea..3904abc4 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -45,11 +45,10 @@ pipeline { try { sh """ snyk auth ${SNYK_TOKEN} - snyk config set disableSuggestions=true - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed " + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" """ } catch (Exception e) { - echo "Snyk scan failed: ${e.getMessage()}" + error "Snyk scan failed: ${e.getMessage()}" } } } @@ -65,7 +64,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py + pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py deactivate ''' } From 7ccae48e830a4c66c3589c02291190bfb7c53fe6 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 7 Jul 2024 20:17:00 +0300 Subject: [PATCH 158/241] update build.Jenkinsfile update work with snyk --- Dockerfile | 3 +-- build.Jenkinsfile | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 73a8be89..9784422e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libgl1-mesa-glx \ curl \ - python-dotenv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -33,4 +32,4 @@ WORKDIR /app/polybot EXPOSE 5000 # Run the bot when the container launches -CMD ["python3", "bot.py"] \ No newline at end of file +CMD ["python3", "bot.py"] diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3904abc4..e18f83e0 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -45,7 +45,9 @@ pipeline { try { sh """ snyk auth ${SNYK_TOKEN} - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} --file=Dockerfile || echo "Snyk scan failed" + snyk config set disableSuggestions=true + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" + """ } catch (Exception e) { error "Snyk scan failed: ${e.getMessage()}" From e3617ba495130afe32d66d0d3f155ce6ce257c57 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 9 Jul 2024 18:44:05 +0300 Subject: [PATCH 159/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index e18f83e0..4d596d9f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -66,7 +66,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py deactivate ''' } From 90904f1baba65b3c79ab7c30f350ce0eeee8247e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 9 Jul 2024 19:08:00 +0300 Subject: [PATCH 160/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 32 ++++++++++++++++++++++++++++++-- polybot/requirements.txt | 2 ++ requirements.txt | 2 ++ tests/test_sample.py | 8 ++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/test_sample.py diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 4d596d9f..550b6eb6 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -46,8 +46,7 @@ pipeline { sh """ snyk auth ${SNYK_TOKEN} snyk config set disableSuggestions=true - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" - + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" """ } catch (Exception e) { error "Snyk scan failed: ${e.getMessage()}" @@ -57,6 +56,27 @@ pipeline { } } + stage('Unit Test') { + steps { + script { + docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { + sh """ + python3 -m venv venv + . venv/bin/activate + pip install -r requirements.txt + python3 -m pytest --junitxml results.xml tests/*.py + deactivate + """ + } + } + } + post { + always { + junit allowEmptyResults: true, testResults: 'results.xml' + } + } + } + stage('Test') { steps { script { @@ -75,6 +95,14 @@ pipeline { } } } + post { + always { + script { + archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true + recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pyLint(name: 'Pylint', pattern: '**/pylint.log')] + } + } + } } } diff --git a/polybot/requirements.txt b/polybot/requirements.txt index 5257c359..d7bb5fdc 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -7,3 +7,5 @@ pylint>=3.2.3 opencv-python>=4.5.3.56 telebot==0.0.4 python-dotenv>=0.19.2 +pytest +unittest2 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5257c359..bb2a617e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,5 @@ pylint>=3.2.3 opencv-python>=4.5.3.56 telebot==0.0.4 python-dotenv>=0.19.2 +pytest +unittest2 diff --git a/tests/test_sample.py b/tests/test_sample.py new file mode 100644 index 00000000..a0bbfe47 --- /dev/null +++ b/tests/test_sample.py @@ -0,0 +1,8 @@ +import unittest + +class TestSample(unittest.TestCase): + def test_example(self): + self.assertEqual(1, 1) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From ffc4648a9a1fdbaacac9d2c4c3613e7920f9b749 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 9 Jul 2024 19:41:16 +0300 Subject: [PATCH 161/241] update build.Jenkinsfile update work with snyk --- polybot/requirements.txt | 4 ++-- requirements.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polybot/requirements.txt b/polybot/requirements.txt index d7bb5fdc..4b13bb11 100644 --- a/polybot/requirements.txt +++ b/polybot/requirements.txt @@ -7,5 +7,5 @@ pylint>=3.2.3 opencv-python>=4.5.3.56 telebot==0.0.4 python-dotenv>=0.19.2 -pytest -unittest2 \ No newline at end of file +pytest>=6.2.4 +unittest2>=1.1.0 diff --git a/requirements.txt b/requirements.txt index bb2a617e..4b13bb11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,5 +7,5 @@ pylint>=3.2.3 opencv-python>=4.5.3.56 telebot==0.0.4 python-dotenv>=0.19.2 -pytest -unittest2 +pytest>=6.2.4 +unittest2>=1.1.0 From ccc1922c69163ecc0a64ff1530bc3ecd808e4001 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 9 Jul 2024 20:06:20 +0300 Subject: [PATCH 162/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 550b6eb6..a6891b1f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -86,7 +86,9 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true + ls -alh + cat pylint.log deactivate ''' } @@ -98,8 +100,12 @@ pipeline { post { always { script { - archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pyLint(name: 'Pylint', pattern: '**/pylint.log')] + try { + archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true + recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pyLint(name: 'Pylint', pattern: 'pylint.log')] + } catch (Exception e) { + echo "Archiving or recording issues failed: ${e.getMessage()}" + } } } } From ea38d4d070a7c34b37a210c3579ff5538b2c6a41 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 19:28:47 +0300 Subject: [PATCH 163/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a6891b1f..3174e83f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -102,7 +102,9 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pyLint(name: 'Pylint', pattern: 'pylint.log')] + // Record issues using a general method if available, or simply echo the log + echo "Pylint log content:" + sh 'cat pylint.log' } catch (Exception e) { echo "Archiving or recording issues failed: ${e.getMessage()}" } @@ -141,4 +143,4 @@ pipeline { } } } -} +} \ No newline at end of file From 09eae5e95eee602bf8b987ae96410a55c2ef8df8 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 19:49:27 +0300 Subject: [PATCH 164/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3174e83f..bb4771fe 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -64,7 +64,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - python3 -m pytest --junitxml results.xml tests/*.py + python3 -m pytest --junitxml results.xml polybot/*.py deactivate """ } From 453cb04fd2e15b58640da43e819f507ecd29be3e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 20:04:52 +0300 Subject: [PATCH 165/241] update build.Jenkinsfile update work with snyk --- .gitignore | 2 +- build.Jenkinsfile | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 6b6a2251..be27e698 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ share/python-wheels/ *.egg MANIFEST jenkis_try - +.env # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. diff --git a/build.Jenkinsfile b/build.Jenkinsfile index bb4771fe..154096a0 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -38,23 +38,23 @@ pipeline { } } - stage('Snyk Scan') { - steps { - withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { - script { - try { - sh """ - snyk auth ${SNYK_TOKEN} - snyk config set disableSuggestions=true - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" - """ - } catch (Exception e) { - error "Snyk scan failed: ${e.getMessage()}" - } - } - } - } - } +// stage('Snyk Scan') { +// steps { +// withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { +// script { +// try { +// sh """ +// snyk auth ${SNYK_TOKEN} +// snyk config set disableSuggestions=true +// snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" +// """ +// } catch (Exception e) { +// error "Snyk scan failed: ${e.getMessage()}" +// } +// } +// } +// } +// } stage('Unit Test') { steps { From 60ba55f8ef74d21809d52bb77fcb758e980a5407 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 20:18:41 +0300 Subject: [PATCH 166/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 154096a0..9f110ccd 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,9 +6,9 @@ pipeline { } environment { - IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') + TELEGRAM_TOKEN = credentials('telegram_bot_token') } agent { @@ -56,6 +56,18 @@ pipeline { // } // } + stage('Prepare Environment') { + steps { + withCredentials([string(credentialsId: 'TELEGRAM_TOKEN', variable: 'TELEGRAM_TOKEN')]) { + script { + sh """ + echo "TELEGRAM_TOKEN=${TELEGRAM_TOKEN}" > .env + """ + } + } + } + } + stage('Unit Test') { steps { script { @@ -64,7 +76,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - python3 -m pytest --junitxml results.xml polybot/*.py + python3 -m unittest discover -s tests -p "*.py" > unittest-results.xml || true deactivate """ } @@ -72,7 +84,7 @@ pipeline { } post { always { - junit allowEmptyResults: true, testResults: 'results.xml' + junit allowEmptyResults: true, testResults: 'unittest-results.xml' } } } @@ -80,20 +92,16 @@ pipeline { stage('Test') { steps { script { - try { - docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { - sh ''' - python3 -m venv venv - . venv/bin/activate - pip install -r requirements.txt - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true - ls -alh - cat pylint.log - deactivate - ''' - } - } catch (Exception e) { - error "Test failed: ${e.getMessage()}" + docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { + sh ''' + python3 -m venv venv + . venv/bin/activate + pip install -r requirements.txt + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true + ls -alh + cat pylint.log + deactivate + ''' } } } @@ -102,9 +110,7 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - // Record issues using a general method if available, or simply echo the log - echo "Pylint log content:" - sh 'cat pylint.log' + recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pylint(name: 'Pylint', pattern: 'pylint.log')] } catch (Exception e) { echo "Archiving or recording issues failed: ${e.getMessage()}" } @@ -143,4 +149,4 @@ pipeline { } } } -} \ No newline at end of file +} From 84fda6520cdf8e0bd551a4c08e70b02807c6549a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 20:24:59 +0300 Subject: [PATCH 167/241] update build.Jenkinsfile update work with snyk --- build.Jenkinsfile | 49 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 9f110ccd..a69f8c27 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') - TELEGRAM_TOKEN = credentials('telegram_bot_token') + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') // Updated to match your Jenkins credentials ID } agent { @@ -38,32 +38,31 @@ pipeline { } } -// stage('Snyk Scan') { -// steps { -// withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { -// script { -// try { -// sh """ -// snyk auth ${SNYK_TOKEN} -// snyk config set disableSuggestions=true -// snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" -// """ -// } catch (Exception e) { -// error "Snyk scan failed: ${e.getMessage()}" -// } -// } -// } -// } -// } + // Commented out the Snyk Scan stage for now + // stage('Snyk Scan') { + // steps { + // withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { + // script { + // try { + // sh """ + // snyk auth ${SNYK_TOKEN} + // snyk config set disableSuggestions=true + // snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" + // """ + // } catch (Exception e) { + // error "Snyk scan failed: ${e.getMessage()}" + // } + // } + // } + // } + // } stage('Prepare Environment') { steps { - withCredentials([string(credentialsId: 'TELEGRAM_TOKEN', variable: 'TELEGRAM_TOKEN')]) { - script { - sh """ - echo "TELEGRAM_TOKEN=${TELEGRAM_TOKEN}" > .env - """ - } + script { + sh """ + echo "TELEGRAM_TOKEN=${TELEGRAM_TOKEN}" > .env + """ } } } @@ -149,4 +148,4 @@ pipeline { } } } -} +} \ No newline at end of file From 0f05c7327d90e89dec6441313a772fe140dd5c2d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 20:25:46 +0300 Subject: [PATCH 168/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a69f8c27..20ada580 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -111,7 +111,7 @@ pipeline { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pylint(name: 'Pylint', pattern: 'pylint.log')] } catch (Exception e) { - echo "Archiving or recording issues failed: ${e.getMessage()}" + echo "Archiving or recording issues failed : ${e.getMessage()}" } } } From e720872805705449c7835febca3700548e866fa8 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 20:33:29 +0300 Subject: [PATCH 169/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 20ada580..32d96de1 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -59,10 +59,12 @@ pipeline { stage('Prepare Environment') { steps { - script { - sh """ - echo "TELEGRAM_TOKEN=${TELEGRAM_TOKEN}" > .env - """ + withCredentials([string(credentialsId: 'TELEGRAM_TOKEN', variable: 'TELEGRAM_TOKEN')]) { + script { + sh """ + echo "TELEGRAM_TOKEN=${TELEGRAM_TOKEN}" > .env + """ + } } } } @@ -109,9 +111,9 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pylint(name: 'Pylint', pattern: 'pylint.log')] + recordIssues enabledForFailure: true, aggregatingResults: true, tools: [python(pattern: 'pylint.log', name: 'Pylint')] } catch (Exception e) { - echo "Archiving or recording issues failed : ${e.getMessage()}" + echo "Archiving or recording issues failed: ${e.getMessage()}" } } } @@ -148,4 +150,4 @@ pipeline { } } } -} \ No newline at end of file +} From b1240c77243c5dd7cf15ef59b7de17e295a90412 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 20:52:28 +0300 Subject: [PATCH 170/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 32d96de1..c1fdc3c2 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -111,7 +111,7 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - recordIssues enabledForFailure: true, aggregatingResults: true, tools: [python(pattern: 'pylint.log', name: 'Pylint')] + recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pylint(pattern: 'pylint.log')] } catch (Exception e) { echo "Archiving or recording issues failed: ${e.getMessage()}" } From 99ba57e0fa784cbcdc87ccc04593e2b09a9ebfc2 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 21:02:14 +0300 Subject: [PATCH 171/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index c1fdc3c2..3a8b885c 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') - TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') // Updated to match your Jenkins credentials ID + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } agent { @@ -38,25 +38,6 @@ pipeline { } } - // Commented out the Snyk Scan stage for now - // stage('Snyk Scan') { - // steps { - // withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { - // script { - // try { - // sh """ - // snyk auth ${SNYK_TOKEN} - // snyk config set disableSuggestions=true - // snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" - // """ - // } catch (Exception e) { - // error "Snyk scan failed: ${e.getMessage()}" - // } - // } - // } - // } - // } - stage('Prepare Environment') { steps { withCredentials([string(credentialsId: 'TELEGRAM_TOKEN', variable: 'TELEGRAM_TOKEN')]) { @@ -111,7 +92,7 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - recordIssues enabledForFailure: true, aggregatingResults: true, tools: [pylint(pattern: 'pylint.log')] + recordIssues tools: [pylint(pattern: 'pylint.log')] } catch (Exception e) { echo "Archiving or recording issues failed: ${e.getMessage()}" } From 14d12b998467dc339e0e5a66536ee4ef316a551a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 21:14:50 +0300 Subject: [PATCH 172/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3a8b885c..50fd4771 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -79,7 +79,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 tests/*.py > pylint.log || true ls -alh cat pylint.log deactivate From 330810900a8bb4f6022a770f7e1fe24db02a72ef Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 10 Jul 2024 21:25:34 +0300 Subject: [PATCH 173/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 52 +++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 50fd4771..3174e83f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -6,9 +6,9 @@ pipeline { } environment { + IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') - TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } agent { @@ -38,13 +38,19 @@ pipeline { } } - stage('Prepare Environment') { + stage('Snyk Scan') { steps { - withCredentials([string(credentialsId: 'TELEGRAM_TOKEN', variable: 'TELEGRAM_TOKEN')]) { + withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { script { - sh """ - echo "TELEGRAM_TOKEN=${TELEGRAM_TOKEN}" > .env - """ + try { + sh """ + snyk auth ${SNYK_TOKEN} + snyk config set disableSuggestions=true + snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" + """ + } catch (Exception e) { + error "Snyk scan failed: ${e.getMessage()}" + } } } } @@ -58,7 +64,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - python3 -m unittest discover -s tests -p "*.py" > unittest-results.xml || true + python3 -m pytest --junitxml results.xml tests/*.py deactivate """ } @@ -66,7 +72,7 @@ pipeline { } post { always { - junit allowEmptyResults: true, testResults: 'unittest-results.xml' + junit allowEmptyResults: true, testResults: 'results.xml' } } } @@ -74,16 +80,20 @@ pipeline { stage('Test') { steps { script { - docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { - sh ''' - python3 -m venv venv - . venv/bin/activate - pip install -r requirements.txt - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 tests/*.py > pylint.log || true - ls -alh - cat pylint.log - deactivate - ''' + try { + docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { + sh ''' + python3 -m venv venv + . venv/bin/activate + pip install -r requirements.txt + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true + ls -alh + cat pylint.log + deactivate + ''' + } + } catch (Exception e) { + error "Test failed: ${e.getMessage()}" } } } @@ -92,7 +102,9 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - recordIssues tools: [pylint(pattern: 'pylint.log')] + // Record issues using a general method if available, or simply echo the log + echo "Pylint log content:" + sh 'cat pylint.log' } catch (Exception e) { echo "Archiving or recording issues failed: ${e.getMessage()}" } @@ -131,4 +143,4 @@ pipeline { } } } -} +} \ No newline at end of file From 590469fe86abc4bc68a57576bb9b410ff08481e2 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 14:42:45 +0300 Subject: [PATCH 174/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3174e83f..bb4771fe 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -64,7 +64,7 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - python3 -m pytest --junitxml results.xml tests/*.py + python3 -m pytest --junitxml results.xml polybot/*.py deactivate """ } From ae49023a828c706da8bbe2872501ac7b7488adac Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 15:16:14 +0300 Subject: [PATCH 175/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index bb4771fe..2625b9ef 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -15,6 +15,7 @@ pipeline { docker { image 'beny14/dockerfile_agent:latest' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } } From 31f74d6ad6e4eef419e087b86b2201c7659e1b3b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 15:16:45 +0300 Subject: [PATCH 176/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 2625b9ef..24fb9fb4 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -39,23 +39,23 @@ pipeline { } } - stage('Snyk Scan') { - steps { - withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { - script { - try { - sh """ - snyk auth ${SNYK_TOKEN} - snyk config set disableSuggestions=true - snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" - """ - } catch (Exception e) { - error "Snyk scan failed: ${e.getMessage()}" - } - } - } - } - } +// stage('Snyk Scan') { +// steps { +// withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { +// script { +// try { +// sh """ +// snyk auth ${SNYK_TOKEN} +// snyk config set disableSuggestions=true +// snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" +// """ +// } catch (Exception e) { +// error "Snyk scan failed: ${e.getMessage()}" +// } +// } +// } +// } +// } stage('Unit Test') { steps { From 27dd25cd7ecefb4ae7e5f23719c0b15406fe6f91 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 15:19:55 +0300 Subject: [PATCH 177/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 24fb9fb4..15b698f9 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -9,13 +9,13 @@ pipeline { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } agent { docker { image 'beny14/dockerfile_agent:latest' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' - TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } } @@ -103,7 +103,6 @@ pipeline { script { try { archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - // Record issues using a general method if available, or simply echo the log echo "Pylint log content:" sh 'cat pylint.log' } catch (Exception e) { @@ -144,4 +143,4 @@ pipeline { } } } -} \ No newline at end of file +} From ac898d083604defaf5bd6b480ffcf7857aad21a3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 15:25:36 +0300 Subject: [PATCH 178/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 15b698f9..d070699f 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -138,7 +138,7 @@ pipeline { failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed ' echo "Error occurred: ${errorMessage}" } } From a62de37aebfb6d426d848f4f727c101f9a75e86d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 15:55:52 +0300 Subject: [PATCH 179/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index d070699f..0693d90d 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -65,7 +65,8 @@ pipeline { python3 -m venv venv . venv/bin/activate pip install -r requirements.txt - python3 -m pytest --junitxml results.xml polybot/*.py + pip install pytest-xdist + python3 -m pytest -n auto --junitxml results.xml polybot/*.py deactivate """ } @@ -138,7 +139,7 @@ pipeline { failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed ' + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' echo "Error occurred: ${errorMessage}" } } From a35bce092f413f02186310b32ebf86a69c60a5bd Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 18:11:53 +0300 Subject: [PATCH 180/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 0693d90d..fa97b6b4 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,6 +3,7 @@ pipeline { buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() + timeout(time: 120, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { @@ -25,12 +26,14 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { try { + echo "Starting Docker build" sh """ echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} """ + echo "Docker build and push completed" } catch (Exception e) { error "Build failed: ${e.getMessage()}" } @@ -39,37 +42,23 @@ pipeline { } } -// stage('Snyk Scan') { -// steps { -// withCredentials([string(credentialsId: 'SNYK_TOKEN', variable: 'SNYK_TOKEN')]) { -// script { -// try { -// sh """ -// snyk auth ${SNYK_TOKEN} -// snyk config set disableSuggestions=true -// snyk container test ${DOCKER_REPO}:${BUILD_NUMBER} || echo "Snyk scan failed" -// """ -// } catch (Exception e) { -// error "Snyk scan failed: ${e.getMessage()}" -// } -// } -// } -// } -// } - stage('Unit Test') { steps { script { + echo "Starting Unit Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh """ python3 -m venv venv . venv/bin/activate + pip install --upgrade pip pip install -r requirements.txt - pip install pytest-xdist - python3 -m pytest -n auto --junitxml results.xml polybot/*.py + pip install pytest-xdist pytest-timeout + # Run pytest with verbosity and timeout for each test + python3 -m pytest -n 4 --timeout=300 --junitxml results.xml polybot/*.py deactivate """ } + echo "Unit Tests completed" } } post { @@ -83,6 +72,7 @@ pipeline { steps { script { try { + echo "Starting Lint Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' python3 -m venv venv @@ -94,6 +84,7 @@ pipeline { deactivate ''' } + echo "Lint Tests completed" } catch (Exception e) { error "Test failed: ${e.getMessage()}" } @@ -118,6 +109,7 @@ pipeline { post { always { script { + echo "Cleaning up Docker containers and images" def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() sh """ @@ -127,14 +119,12 @@ pipeline { fi done """ - } - script { sh """ docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ + cleanWs() + echo "Cleanup completed" } - - cleanWs() } failure { From 703a4679b2a2a76db4f458dae67eb45151d065a9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 18:21:10 +0300 Subject: [PATCH 181/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index fa97b6b4..eaddb4cf 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -54,7 +54,7 @@ pipeline { pip install -r requirements.txt pip install pytest-xdist pytest-timeout # Run pytest with verbosity and timeout for each test - python3 -m pytest -n 4 --timeout=300 --junitxml results.xml polybot/*.py + python3 -m pytest -n 4 --timeout=60 --junitxml results.xml polybot/*.py deactivate """ } From 9605b486e68808aaaf0ef8c2bf79772d73012703 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 18:36:44 +0300 Subject: [PATCH 182/241] update build.Jenkinsfile update work with unitest and token in .env --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index eaddb4cf..9f115e11 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -54,7 +54,7 @@ pipeline { pip install -r requirements.txt pip install pytest-xdist pytest-timeout # Run pytest with verbosity and timeout for each test - python3 -m pytest -n 4 --timeout=60 --junitxml results.xml polybot/*.py + python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py deactivate """ } From 51a15f69f1bac98ee91ae45d3fb7c5e3d02cae59 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 20:37:06 +0300 Subject: [PATCH 183/241] update build.Jenkinsfile update to work with nexus --- build.Jenkinsfile | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 9f115e11..920914b3 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,12 +3,13 @@ pipeline { buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() - timeout(time: 120, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { IMG_NAME = "polybot:${BUILD_NUMBER}" - DOCKER_REPO = "beny14/polybot" + DOCKER_REPO = "your-nexus-repo-url/polybot" // Update with your Nexus Docker repository URL + NEXUS_USER = credentials('nexus_user') + NEXUS_PASS = credentials('nexus_pass') SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } @@ -23,20 +24,18 @@ pipeline { stages { stage('Build') { steps { - withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { - script { - try { - echo "Starting Docker build" - sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:${BUILD_NUMBER} - """ - echo "Docker build and push completed" - } catch (Exception e) { - error "Build failed: ${e.getMessage()}" - } + script { + try { + echo "Logging into Nexus Docker repository with user: ${NEXUS_USER_USR}" + sh """ + echo ${NEXUS_USER_PSW} | docker login -u ${NEXUS_USER_USR} --password-stdin ${DOCKER_REPO} + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${DOCKER_REPO}:latest + """ + } catch (Exception e) { + error "Build failed: ${e.getMessage()}" } } } @@ -45,20 +44,17 @@ pipeline { stage('Unit Test') { steps { script { - echo "Starting Unit Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh """ python3 -m venv venv . venv/bin/activate pip install --upgrade pip pip install -r requirements.txt - pip install pytest-xdist pytest-timeout - # Run pytest with verbosity and timeout for each test - python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py + pip install pytest-xdist + python3 -m pytest -n auto --junitxml results.xml polybot/*.py deactivate """ } - echo "Unit Tests completed" } } post { @@ -72,7 +68,6 @@ pipeline { steps { script { try { - echo "Starting Lint Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' python3 -m venv venv @@ -84,7 +79,6 @@ pipeline { deactivate ''' } - echo "Lint Tests completed" } catch (Exception e) { error "Test failed: ${e.getMessage()}" } @@ -109,7 +103,6 @@ pipeline { post { always { script { - echo "Cleaning up Docker containers and images" def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() sh """ @@ -119,12 +112,14 @@ pipeline { fi done """ + } + script { sh """ docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ - cleanWs() - echo "Cleanup completed" } + + cleanWs() } failure { From 857f6ac4ed4c914e7ed071725dd7cc1a6c91055b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 20:40:21 +0300 Subject: [PATCH 184/241] update build.Jenkinsfile update to work with nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 920914b3..af067c31 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -7,7 +7,7 @@ pipeline { environment { IMG_NAME = "polybot:${BUILD_NUMBER}" - DOCKER_REPO = "your-nexus-repo-url/polybot" // Update with your Nexus Docker repository URL + DOCKER_REPO = "http://192.168.1.75:8081/#browse/browse:docker-hosted" // Update with your Nexus Docker repository URL NEXUS_USER = credentials('nexus_user') NEXUS_PASS = credentials('nexus_pass') SNYK_TOKEN = credentials('SNYK_TOKEN') From 1bf40cf6c163eef1773e495510a147cbcf5ae618 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 20:42:42 +0300 Subject: [PATCH 185/241] update build.Jenkinsfile update to work with nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index af067c31..be2e80db 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -7,7 +7,7 @@ pipeline { environment { IMG_NAME = "polybot:${BUILD_NUMBER}" - DOCKER_REPO = "http://192.168.1.75:8081/#browse/browse:docker-hosted" // Update with your Nexus Docker repository URL + DOCKER_REPO = "http://192.168.1.75:8081/repository/docker-hosted/" // Update with your Nexus Docker repository URL NEXUS_USER = credentials('nexus_user') NEXUS_PASS = credentials('nexus_pass') SNYK_TOKEN = credentials('SNYK_TOKEN') From 1d8c72b9040f187014dcee7a7c085ad2aa82fd24 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 20:44:49 +0300 Subject: [PATCH 186/241] update build.Jenkinsfile update to work with nexus --- build.Jenkinsfile | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index be2e80db..6270196a 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -103,23 +103,30 @@ pipeline { post { always { script { - def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() + try { + def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() - sh """ - for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do - if [ "\$id" != "${containerId}" ]; then - docker rm -f \$id || true - fi - done - """ - } - script { - sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true - """ - } + sh """ + for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do + if [ "\$id" != "${containerId}" ]; then + docker rm -f \$id || true + fi + done + """ + } catch (Exception e) { + error "Error cleaning up containers: ${e.getMessage()}" + } - cleanWs() + try { + sh """ + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true + """ + } catch (Exception e) { + error "Error cleaning up images: ${e.getMessage()}" + } + + cleanWs() + } } failure { From 4a3d2f1eeb901bb2579a794a96205aa1eca2a0e0 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 20:53:14 +0300 Subject: [PATCH 187/241] update build.Jenkinsfile update to work with nexus --- build.Jenkinsfile | 80 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 6270196a..8e948df8 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,15 +3,16 @@ pipeline { buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() + timeout(time: 120, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { IMG_NAME = "polybot:${BUILD_NUMBER}" - DOCKER_REPO = "http://192.168.1.75:8081/repository/docker-hosted/" // Update with your Nexus Docker repository URL - NEXUS_USER = credentials('nexus_user') - NEXUS_PASS = credentials('nexus_pass') + DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') + NEXUS_CREDENTIAL = credentials('nexus_credentials_id') // Replace with your Nexus credentials ID + NEXUS_REPO_URL = "http://localhost:8081/repository/docker-repo/" // Replace with your Nexus repository URL } agent { @@ -22,20 +23,22 @@ pipeline { } stages { - stage('Build') { + stage('Build and Push Docker Image') { steps { script { - try { - echo "Logging into Nexus Docker repository with user: ${NEXUS_USER_USR}" - sh """ - echo ${NEXUS_USER_PSW} | docker login -u ${NEXUS_USER_USR} --password-stdin ${DOCKER_REPO} - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${DOCKER_REPO}:latest - """ - } catch (Exception e) { - error "Build failed: ${e.getMessage()}" + withCredentials([usernamePassword(credentialsId: "${NEXUS_CREDENTIAL}", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { + try { + echo "Starting Docker build" + sh """ + echo ${NEXUS_PASS} | docker login -u ${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} + """ + echo "Docker build and push completed" + } catch (Exception e) { + error "Build failed: ${e.getMessage()}" + } } } } @@ -44,17 +47,20 @@ pipeline { stage('Unit Test') { steps { script { + echo "Starting Unit Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh """ python3 -m venv venv . venv/bin/activate pip install --upgrade pip pip install -r requirements.txt - pip install pytest-xdist - python3 -m pytest -n auto --junitxml results.xml polybot/*.py + pip install pytest-xdist pytest-timeout + # Run pytest with verbosity and timeout for each test + python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py deactivate """ } + echo "Unit Tests completed" } } post { @@ -64,10 +70,11 @@ pipeline { } } - stage('Test') { + stage('Lint Test') { steps { script { try { + echo "Starting Lint Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' python3 -m venv venv @@ -79,8 +86,9 @@ pipeline { deactivate ''' } + echo "Lint Tests completed" } catch (Exception e) { - error "Test failed: ${e.getMessage()}" + error "Lint Tests failed: ${e.getMessage()}" } } } @@ -103,29 +111,21 @@ pipeline { post { always { script { - try { - def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() - - sh """ - for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do - if [ "\$id" != "${containerId}" ]; then - docker rm -f \$id || true - fi - done - """ - } catch (Exception e) { - error "Error cleaning up containers: ${e.getMessage()}" - } - - try { - sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true - """ - } catch (Exception e) { - error "Error cleaning up images: ${e.getMessage()}" - } + echo "Cleaning up Docker containers and images" + def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() + sh """ + for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do + if [ "\$id" != "${containerId}" ]; then + docker rm -f \$id || true + fi + done + """ + sh """ + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true + """ cleanWs() + echo "Cleanup completed" } } From eff65095b795949d9a8e0b9204f8bd68b0095001 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 21:00:18 +0300 Subject: [PATCH 188/241] update build.Jenkinsfile update to work with nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 8e948df8..e17fe775 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -131,7 +131,7 @@ pipeline { failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed ' echo "Error occurred: ${errorMessage}" } } From ed936d2e15877ba30c9220197c3a8263c701cd72 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 13 Jul 2024 21:04:00 +0300 Subject: [PATCH 189/241] update build.Jenkinsfile update --- build.Jenkinsfile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index e17fe775..9f115e11 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -11,8 +11,6 @@ pipeline { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') - NEXUS_CREDENTIAL = credentials('nexus_credentials_id') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://localhost:8081/repository/docker-repo/" // Replace with your Nexus repository URL } agent { @@ -23,17 +21,17 @@ pipeline { } stages { - stage('Build and Push Docker Image') { + stage('Build') { steps { - script { - withCredentials([usernamePassword(credentialsId: "${NEXUS_CREDENTIAL}", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { + withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + script { try { echo "Starting Docker build" sh """ - echo ${NEXUS_PASS} | docker login -u ${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} """ echo "Docker build and push completed" } catch (Exception e) { @@ -70,7 +68,7 @@ pipeline { } } - stage('Lint Test') { + stage('Test') { steps { script { try { @@ -88,7 +86,7 @@ pipeline { } echo "Lint Tests completed" } catch (Exception e) { - error "Lint Tests failed: ${e.getMessage()}" + error "Test failed: ${e.getMessage()}" } } } @@ -131,7 +129,7 @@ pipeline { failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed ' + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' echo "Error occurred: ${errorMessage}" } } From 6e5ace9b125cf885472ff2b25d7fe33ee6425ece Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 20:03:20 +0300 Subject: [PATCH 190/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 35 +++++++++++++++++++++++++++++++---- deploy.Jenkinsfile | 29 ++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 9f115e11..c35ae72b 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -11,6 +11,8 @@ pipeline { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') + NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID + NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL } agent { @@ -21,17 +23,42 @@ pipeline { } stages { - stage('Build') { + stage('Check and Start Nexus') { steps { - withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { - script { + script { + def nexusStatus = sh(script: 'docker ps -q -f name=nexus', returnStdout: true).trim() + if (nexusStatus == "") { + echo "Nexus container is not running, checking if it exists..." + def nexusExists = sh(script: 'docker ps -a -q -f name=nexus', returnStdout: true).trim() + if (nexusExists != "") { + echo "Stopping and removing existing Nexus container" + sh 'docker stop nexus && docker rm nexus' + } + echo "Starting Nexus container" + sh 'docker run -d -p 8081:8081 --name nexus -v /path/to/nexus-data:/nexus-data sonatype/nexus3' + } else { + echo "Nexus container is already running" + } + } + } + } + + stage('Build and Push Docker Image') { + steps { + script { + withCredentials([usernamePassword(credentialsId: "nexus_credentials_id", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { try { echo "Starting Docker build" sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin + echo ${NEXUS_PASS} | docker login -u ${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${DOCKER_REPO}:latest + docker push ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${NEXUS_REPO_URL}${DOCKER_REPO}:latest """ echo "Docker build and push completed" } catch (Exception e) { diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 3382f811..45758d98 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -2,15 +2,34 @@ pipeline { agent any parameters { - string(name: 'beny14/polybot:${BUILD_NUMBER}', defaultValue: 'INAGE_URL', description: 'deploy polybot') + string(name: 'DOCKER_IMAGE', defaultValue: 'beny14/polybot:latest', description: 'Docker Image to build and push') + } + + environment { + DOCKER_REPO = "beny14/polybot" + NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID + NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL } stages { - stage('Deploy') { + stage('Build and Push Docker Image to Nexus') { steps { - sh ''' - echo "docker push... " - ''' + script { + withCredentials([usernamePassword(credentialsId: "nexus_credentials_id", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { + try { + echo "Starting Docker build and push to Nexus" + sh """ + echo ${NEXUS_PASS} | docker login -u ${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} + docker pull ${DOCKER_IMAGE} + docker tag ${DOCKER_IMAGE} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:latest + """ + echo "Docker build and push to Nexus completed" + } catch (Exception e) { + error "Build and push to Nexus failed: ${e.getMessage()}" + } + } + } } } } From db9ef46a442e7f0af5d28360bfcf63a1a9e887a1 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 20:05:22 +0300 Subject: [PATCH 191/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 45758d98..8f8dafcb 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { DOCKER_REPO = "beny14/polybot" NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL } stages { From 87b9a370d1ca06ee886397d2ce55f752af0bf405 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 20:09:40 +0300 Subject: [PATCH 192/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index c35ae72b..e1604d95 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -46,7 +46,7 @@ pipeline { stage('Build and Push Docker Image') { steps { script { - withCredentials([usernamePassword(credentialsId: "nexus_credentials_id", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { + withCredentials([usernamePassword(credentialsId: "nexus_user", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { try { echo "Starting Docker build" sh """ From e8bc0cf6b39b23d96e0eb2e8fca9f8315a9f85ab Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 20:10:02 +0300 Subject: [PATCH 193/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index e1604d95..ba53639c 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -12,7 +12,7 @@ pipeline { SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL } agent { From 5b0ef37fea44b1fbb42d6047112819c5dc77d957 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 20:41:53 +0300 Subject: [PATCH 194/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ba53639c..cad6bae4 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -12,7 +12,7 @@ pipeline { SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:5000/repository/docker-repo/" // Replace with your Nexus repository URL } agent { From c0d48dc18772d853fb2800c1b154fb95a727c7d9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 21:07:26 +0300 Subject: [PATCH 195/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 21 +++++++++++---------- deploy.Jenkinsfile | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index cad6bae4..77ccc6b1 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -9,10 +9,8 @@ pipeline { environment { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" - SNYK_TOKEN = credentials('SNYK_TOKEN') - TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:5000/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:5000/repository/docker-repo/" // Replace with your Nexus repository URL } agent { @@ -50,7 +48,7 @@ pipeline { try { echo "Starting Docker build" sh """ - echo ${NEXUS_PASS} | docker login -u ${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} + echo \${NEXUS_PASS} | docker login -u \${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} @@ -62,7 +60,7 @@ pipeline { """ echo "Docker build and push completed" } catch (Exception e) { - error "Build failed: ${e.getMessage()}" + error "Build failed: \${e.getMessage()}" } } } @@ -80,7 +78,6 @@ pipeline { pip install --upgrade pip pip install -r requirements.txt pip install pytest-xdist pytest-timeout - # Run pytest with verbosity and timeout for each test python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py deactivate """ @@ -95,7 +92,7 @@ pipeline { } } - stage('Test') { + stage('Lint Tests') { steps { script { try { @@ -113,7 +110,7 @@ pipeline { } echo "Lint Tests completed" } catch (Exception e) { - error "Test failed: ${e.getMessage()}" + error "Lint tests failed: \${e.getMessage()}" } } } @@ -125,7 +122,7 @@ pipeline { echo "Pylint log content:" sh 'cat pylint.log' } catch (Exception e) { - echo "Archiving or recording issues failed: ${e.getMessage()}" + echo "Archiving or recording issues failed: \${e.getMessage()}" } } } @@ -156,9 +153,13 @@ pipeline { failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description + +: 'Build failed' echo "Error occurred: ${errorMessage}" } } } } + + diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 8f8dafcb..7e145adb 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -8,7 +8,7 @@ pipeline { environment { DOCKER_REPO = "beny14/polybot" NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:5000/repository/docker-repo/" // Replace with your Nexus repository URL } stages { From 5c3d0bf69bff8408932656bf0854cf6b71ef1881 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 21:28:41 +0300 Subject: [PATCH 196/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 77ccc6b1..a8c84f37 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,14 +3,14 @@ pipeline { buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() - timeout(time: 120, unit: 'MINUTES') // Set a global timeout for the pipeline + timeout(time: 45, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:5000/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL } agent { From 9b5ec0c217913250e70d6284ad14ea0d3e5dd05a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 21:30:44 +0300 Subject: [PATCH 197/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index a8c84f37..b285ac61 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -10,7 +10,7 @@ pipeline { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8081/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:8001/repository/docker-repo/" // Replace with your Nexus repository URL } agent { From e28c9d507c143ad4a011c4f0da2b3a0a013ef978 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 21:31:08 +0300 Subject: [PATCH 198/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index b285ac61..bdbba7c7 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -3,7 +3,7 @@ pipeline { buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() - timeout(time: 45, unit: 'MINUTES') // Set a global timeout for the pipeline + timeout(time: 45, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { From 332c1bdcc47bb569831d942cdcbd05bdc9ab259b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Mon, 15 Jul 2024 22:25:49 +0300 Subject: [PATCH 199/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index bdbba7c7..80ecf6c3 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -10,7 +10,7 @@ pipeline { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8001/repository/docker-repo/" // Replace with your Nexus repository URL + NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" // Replace with your Nexus repository URL } agent { From c303c33c762d6d4e6229f9bf673436977ce457be Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 16 Jul 2024 17:23:03 +0300 Subject: [PATCH 200/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 71 +++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 80ecf6c3..dbfc4efa 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,16 +1,19 @@ +// NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID +// NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" // Replace with your Nexus repository URL + pipeline { options { buildDiscarder(logRotator(daysToKeepStr: '14')) disableConcurrentBuilds() timestamps() - timeout(time: 45, unit: 'MINUTES') // Set a global timeout for the pipeline + timeout(time: 40, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { IMG_NAME = "polybot:${BUILD_NUMBER}" DOCKER_REPO = "beny14/polybot" - NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" // Replace with your Nexus repository URL + SNYK_TOKEN = credentials('SNYK_TOKEN') + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } agent { @@ -21,46 +24,21 @@ pipeline { } stages { - stage('Check and Start Nexus') { - steps { - script { - def nexusStatus = sh(script: 'docker ps -q -f name=nexus', returnStdout: true).trim() - if (nexusStatus == "") { - echo "Nexus container is not running, checking if it exists..." - def nexusExists = sh(script: 'docker ps -a -q -f name=nexus', returnStdout: true).trim() - if (nexusExists != "") { - echo "Stopping and removing existing Nexus container" - sh 'docker stop nexus && docker rm nexus' - } - echo "Starting Nexus container" - sh 'docker run -d -p 8081:8081 --name nexus -v /path/to/nexus-data:/nexus-data sonatype/nexus3' - } else { - echo "Nexus container is already running" - } - } - } - } - - stage('Build and Push Docker Image') { + stage('Build') { steps { - script { - withCredentials([usernamePassword(credentialsId: "nexus_user", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { + withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + script { try { echo "Starting Docker build" sh """ - echo \${NEXUS_PASS} | docker login -u \${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${NEXUS_REPO_URL}${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${DOCKER_REPO}:latest - docker push ${NEXUS_REPO_URL}${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${NEXUS_REPO_URL}${DOCKER_REPO}:latest """ echo "Docker build and push completed" } catch (Exception e) { - error "Build failed: \${e.getMessage()}" + error "Build failed: ${e.getMessage()}" } } } @@ -78,6 +56,7 @@ pipeline { pip install --upgrade pip pip install -r requirements.txt pip install pytest-xdist pytest-timeout + # Run pytest with verbosity and timeout for each test python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py deactivate """ @@ -92,7 +71,7 @@ pipeline { } } - stage('Lint Tests') { + stage('Test') { steps { script { try { @@ -110,7 +89,7 @@ pipeline { } echo "Lint Tests completed" } catch (Exception e) { - error "Lint tests failed: \${e.getMessage()}" + error "Test failed: ${e.getMessage()}" } } } @@ -122,12 +101,24 @@ pipeline { echo "Pylint log content:" sh 'cat pylint.log' } catch (Exception e) { - echo "Archiving or recording issues failed: \${e.getMessage()}" + echo "Archiving or recording issues failed: ${e.getMessage()}" } } } } } + stage('Push to Nexus') { + steps { + withCredentials([usernamePassword(credentialsId: 'nexus_user', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD')]) { + script { + sh "docker login -u ${NEXUS_USERNAME} -p ${NEXUS_PASSWORD} http://localhost:8001/repository/polybot/" + sh "docker tag ${IMG_NAME} localhost:8002/repository/docker-repo/${IMG_NAME}" + sh "docker push localhost:8002/repository/docker-repo/${IMG_NAME}" + } + } + } + } + } } post { @@ -153,13 +144,9 @@ pipeline { failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description - -: 'Build failed' + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' echo "Error occurred: ${errorMessage}" } } } -} - - +} \ No newline at end of file From 623e3b3cfcb740187f770e010167debf856fcaf5 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 16 Jul 2024 17:26:12 +0300 Subject: [PATCH 201/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index dbfc4efa..0755207e 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,6 +1,3 @@ -// NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID -// NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" // Replace with your Nexus repository URL - pipeline { options { buildDiscarder(logRotator(daysToKeepStr: '14')) @@ -14,6 +11,8 @@ pipeline { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') + NEXUS_URL = "http://192.168.1.75:8001" + NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" } agent { @@ -35,6 +34,7 @@ pipeline { docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${DOCKER_REPO}:latest """ echo "Docker build and push completed" } catch (Exception e) { @@ -107,18 +107,26 @@ pipeline { } } } + stage('Push to Nexus') { - steps { - withCredentials([usernamePassword(credentialsId: 'nexus_user', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD')]) { - script { - sh "docker login -u ${NEXUS_USERNAME} -p ${NEXUS_PASSWORD} http://localhost:8001/repository/polybot/" - sh "docker tag ${IMG_NAME} localhost:8002/repository/docker-repo/${IMG_NAME}" - sh "docker push localhost:8002/repository/docker-repo/${IMG_NAME}" + steps { + withCredentials([usernamePassword(credentialsId: 'nexus_user', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD')]) { + script { + try { + echo "Pushing Docker image to Nexus" + sh """ + echo ${NEXUS_PASSWORD} | docker login -u ${NEXUS_USERNAME} --password-stdin ${NEXUS_URL} + docker tag ${IMG_NAME} ${NEXUS_REPO_URL}${IMG_NAME} + docker push ${NEXUS_REPO_URL}${IMG_NAME} + """ + echo "Docker image pushed to Nexus" + } catch (Exception e) { + error "Push to Nexus failed: ${e.getMessage()}" + } } } } } - } } post { @@ -149,4 +157,4 @@ pipeline { } } } -} \ No newline at end of file +} From c669da6628897bfd6e277eeabd2670693870d66d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Tue, 16 Jul 2024 17:33:54 +0300 Subject: [PATCH 202/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 0755207e..81bdf8bc 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -11,7 +11,7 @@ pipeline { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') - NEXUS_URL = "http://192.168.1.75:8001" + NEXUS_URL = "http://192.168.1.75:8002" NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" } From 9a680d5e839407196af5215c79929e5ed9450e93 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 19:35:13 +0300 Subject: [PATCH 203/241] update build.Jenkinsfile update nexus --- build.Jenkinsfile | 22 +--------------------- deploy.Jenkinsfile | 16 ++++------------ 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 81bdf8bc..af97bda5 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -11,8 +11,6 @@ pipeline { DOCKER_REPO = "beny14/polybot" SNYK_TOKEN = credentials('SNYK_TOKEN') TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') - NEXUS_URL = "http://192.168.1.75:8002" - NEXUS_REPO_URL = "http://192.168.1.75:8002/repository/docker-repo/" } agent { @@ -108,25 +106,7 @@ pipeline { } } - stage('Push to Nexus') { - steps { - withCredentials([usernamePassword(credentialsId: 'nexus_user', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD')]) { - script { - try { - echo "Pushing Docker image to Nexus" - sh """ - echo ${NEXUS_PASSWORD} | docker login -u ${NEXUS_USERNAME} --password-stdin ${NEXUS_URL} - docker tag ${IMG_NAME} ${NEXUS_REPO_URL}${IMG_NAME} - docker push ${NEXUS_REPO_URL}${IMG_NAME} - """ - echo "Docker image pushed to Nexus" - } catch (Exception e) { - error "Push to Nexus failed: ${e.getMessage()}" - } - } - } - } - } + } post { diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 7e145adb..a790694f 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -5,12 +5,6 @@ pipeline { string(name: 'DOCKER_IMAGE', defaultValue: 'beny14/polybot:latest', description: 'Docker Image to build and push') } - environment { - DOCKER_REPO = "beny14/polybot" - NEXUS_CREDENTIAL = credentials('nexus_user') // Replace with your Nexus credentials ID - NEXUS_REPO_URL = "http://192.168.1.75:5000/repository/docker-repo/" // Replace with your Nexus repository URL - } - stages { stage('Build and Push Docker Image to Nexus') { steps { @@ -19,12 +13,10 @@ pipeline { try { echo "Starting Docker build and push to Nexus" sh """ - echo ${NEXUS_PASS} | docker login -u ${NEXUS_USER} --password-stdin ${NEXUS_REPO_URL} - docker pull ${DOCKER_IMAGE} - docker tag ${DOCKER_IMAGE} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:latest + echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin + docker push localhost:8083/${params.DOCKER_IMAGE} """ - echo "Docker build and push to Nexus completed" + echo "Docker push to Nexus completed" } catch (Exception e) { error "Build and push to Nexus failed: ${e.getMessage()}" } @@ -33,4 +25,4 @@ pipeline { } } } -} +} \ No newline at end of file From 4bc63dba92275032538c54cca962c9ad754d560d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 19:49:25 +0300 Subject: [PATCH 204/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index a790694f..1304ba53 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -6,12 +6,12 @@ pipeline { } stages { - stage('Build and Push Docker Image to Nexus') { + stage('Push Docker Image to Nexus') { steps { script { withCredentials([usernamePassword(credentialsId: "nexus_credentials_id", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { try { - echo "Starting Docker build and push to Nexus" + echo "Starting Docker push to Nexus" sh """ echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin docker push localhost:8083/${params.DOCKER_IMAGE} From 98ad495ec459e233091abdf807b63b11a347a92e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 20:07:35 +0300 Subject: [PATCH 205/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 1304ba53..3d8cda9c 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stage('Push Docker Image to Nexus') { steps { script { - withCredentials([usernamePassword(credentialsId: "nexus_credentials_id", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { + withCredentials([usernamePassword(credentialsId: "nexus_user", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { try { echo "Starting Docker push to Nexus" sh """ From 451df811e9256eeff7362b8c6d16d8a904deb80f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 20:22:56 +0300 Subject: [PATCH 206/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 3d8cda9c..8fccaafa 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent any parameters { - string(name: 'DOCKER_IMAGE', defaultValue: 'beny14/polybot:latest', description: 'Docker Image to build and push') + string(name: 'IMAGE_TAG', defaultValue: 'latest', description: 'Tag to be applied to the Docker image') } stages { @@ -11,10 +11,12 @@ pipeline { script { withCredentials([usernamePassword(credentialsId: "nexus_user", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { try { - echo "Starting Docker push to Nexus" + def dockerImage = "beny14/polybot" + def taggedImage = "${dockerImage}:${params.IMAGE_TAG}" + echo "Starting Docker push to Nexus with tag ${params.IMAGE_TAG}" sh """ echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin - docker push localhost:8083/${params.DOCKER_IMAGE} + docker push localhost:8083/${taggedImage} """ echo "Docker push to Nexus completed" } catch (Exception e) { @@ -25,4 +27,4 @@ pipeline { } } } -} \ No newline at end of file +} From 763b82e31c45510bd397419096741a1855bd2db7 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 20:30:26 +0300 Subject: [PATCH 207/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 8fccaafa..a08e92f6 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -16,6 +16,7 @@ pipeline { echo "Starting Docker push to Nexus with tag ${params.IMAGE_TAG}" sh """ echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin + docker tag ${dockerImage}:${params.IMAGE_TAG} localhost:8083/${taggedImage} docker push localhost:8083/${taggedImage} """ echo "Docker push to Nexus completed" From ac6afd7e61cfa588a89fa479195b7bb594c59956 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 20:57:06 +0300 Subject: [PATCH 208/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index a08e92f6..f249c4c3 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -2,28 +2,22 @@ pipeline { agent any parameters { - string(name: 'IMAGE_TAG', defaultValue: 'latest', description: 'Tag to be applied to the Docker image') + string(name: 'IMAGE_NAME', defaultValue: 'beny14/polybot', description: 'Name of the Docker image') + string(name: 'BUILD_NUMBER', defaultValue: '', description: 'Build number of the Docker image to deploy') } stages { - stage('Push Docker Image to Nexus') { + stage('Build and Push Docker Image to Nexus') { steps { script { - withCredentials([usernamePassword(credentialsId: "nexus_user", usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASS')]) { - try { - def dockerImage = "beny14/polybot" - def taggedImage = "${dockerImage}:${params.IMAGE_TAG}" - echo "Starting Docker push to Nexus with tag ${params.IMAGE_TAG}" - sh """ - echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin - docker tag ${dockerImage}:${params.IMAGE_TAG} localhost:8083/${taggedImage} - docker push localhost:8083/${taggedImage} - """ - echo "Docker push to Nexus completed" - } catch (Exception e) { - error "Build and push to Nexus failed: ${e.getMessage()}" - } - } + def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" + echo "Starting build and push of Docker image ${dockerImage}" + sh """ + docker build -t ${dockerImage} . + echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin + docker push localhost:8083/${dockerImage} + """ + echo "Docker push to Nexus completed" } } } From 520c8d46db614652f3fbfcfc1ff494244a0c4198 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 21:35:15 +0300 Subject: [PATCH 209/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index f249c4c3..1d31fecc 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -14,7 +14,7 @@ pipeline { echo "Starting build and push of Docker image ${dockerImage}" sh """ docker build -t ${dockerImage} . - echo $NEXUS_PASS | docker login localhost:8083 -u $NEXUS_USER --password-stdin + docker login localhost:8083 docker push localhost:8083/${dockerImage} """ echo "Docker push to Nexus completed" From d4be1dc7eae0e6e54dd40d1b70997fefcaa2341b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 22:12:50 +0300 Subject: [PATCH 210/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 1d31fecc..1376ac76 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -13,8 +13,8 @@ pipeline { def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" echo "Starting build and push of Docker image ${dockerImage}" sh """ - docker build -t ${dockerImage} . docker login localhost:8083 + docker tag dockerImage localhost:8083/dockerImage docker push localhost:8083/${dockerImage} """ echo "Docker push to Nexus completed" From 16f454bb1dad24dcbdc0b3f1e16747ea737bbe9d Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Wed, 17 Jul 2024 22:34:44 +0300 Subject: [PATCH 211/241] update build.Jenkinsfile update nexus --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 1376ac76..f6a2128a 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -14,7 +14,7 @@ pipeline { echo "Starting build and push of Docker image ${dockerImage}" sh """ docker login localhost:8083 - docker tag dockerImage localhost:8083/dockerImage + docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ echo "Docker push to Nexus completed" From c7827903a6e9bebea6d707b8a2c97e595bad133f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 13:22:04 +0300 Subject: [PATCH 212/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index af97bda5..71970143 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,3 +1,5 @@ +@Library('shared-lib') _ + pipeline { options { buildDiscarder(logRotator(daysToKeepStr: '14')) @@ -33,7 +35,9 @@ pipeline { docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest docker push ${DOCKER_REPO}:${BUILD_NUMBER} docker push ${DOCKER_REPO}:latest + """ + hello() echo "Docker build and push completed" } catch (Exception e) { error "Build failed: ${e.getMessage()}" @@ -69,7 +73,7 @@ pipeline { } } - stage('Test') { + stage('Lint Test') { steps { script { try { @@ -105,8 +109,6 @@ pipeline { } } } - - } post { From aa669ea2aac6fccc96ab3ac6daf92cab13ad643e Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 13:27:19 +0300 Subject: [PATCH 213/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 71970143..196787bf 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -37,7 +37,7 @@ pipeline { docker push ${DOCKER_REPO}:latest """ - hello() + foo() echo "Docker build and push completed" } catch (Exception e) { error "Build failed: ${e.getMessage()}" From 1a9d11541c55ed4b692f8ca58d10b40c617b18f9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 14:27:39 +0300 Subject: [PATCH 214/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 1 + docker-compose.yml | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index f6a2128a..bbf4359c 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -21,5 +21,6 @@ pipeline { } } } + } } diff --git a/docker-compose.yml b/docker-compose.yml index 1cf1f589..0264dc8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: app: build: @@ -9,12 +7,13 @@ services: - "5000:5000" volumes: - .:/app + command: python -m polybot.bot + web: build: context: ./nginx dockerfile: Dockerfile ports: - - "8002:80" - + - "8002:8002" From a19ea4b09965ccd38d8a337f1ecf8d3e785979c4 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 15:59:54 +0300 Subject: [PATCH 215/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 16 ++++++++++++++++ docker-compose.yml | 4 +--- polybot/Dockerfile | 18 +++++++++--------- polybot/bot.py | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index bbf4359c..3afd78bd 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -23,4 +23,20 @@ pipeline { } } + stages { + stage('run docker-compose , polybot and nginx') { + steps { + script { + sh """ + cd / + cd /project_poly + git pull https://github.com/beny1221g/ImageProcessingService.git + docker-compose up + """ + echo "containers run successfully" + } + } + } + + } } diff --git a/docker-compose.yml b/docker-compose.yml index 0264dc8d..b1d07a64 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: - "5000:5000" volumes: - .:/app - command: python -m polybot.bot + command: python3 -m bot.py web: build: @@ -15,5 +15,3 @@ services: dockerfile: Dockerfile ports: - "8002:8002" - - diff --git a/polybot/Dockerfile b/polybot/Dockerfile index 831662bd..1b41f0e1 100644 --- a/polybot/Dockerfile +++ b/polybot/Dockerfile @@ -1,9 +1,3 @@ -# Use an official Python runtime as a parent image -FROM python:3.13.0b2-slim - -# Set the working directory in the container -WORKDIR /app - # Install system dependencies and build tools RUN apt-get update \ && apt-get install -y --no-install-recommends \ @@ -26,14 +20,20 @@ RUN python -m pip install --upgrade pip \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* +COPY .env .env + # Copy the rest of the application code COPY . . -# Set the working directory to the polybot directory -WORKDIR /app/polybot + +# Ensure the directory structure is correct +RUN ls -la /app + +# Set the working directory to /app +WORKDIR /app # Expose port 5000 EXPOSE 5000 # Command to run the bot when the container launches -CMD ["python3", "bot.py"] +CMD ["python3", "-m", "polybot.bot"] diff --git a/polybot/bot.py b/polybot/bot.py index b16526a1..cdd65ce3 100644 --- a/polybot/bot.py +++ b/polybot/bot.py @@ -2,7 +2,7 @@ import telebot import cv2 from dotenv import load_dotenv -from polybot.img_proc import Img +from img_proc import Img # load environment variables load_dotenv() From 088334d120fe91f7c98202d04570b67227122988 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 16:01:56 +0300 Subject: [PATCH 216/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 3afd78bd..d25351c1 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -17,7 +17,7 @@ pipeline { docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ - echo "Docker push to Nexus completed" + echo "Docker push to Nexus completed " } } } From 9163e2e2e6616d328e5363cd2cfc7a56427889e9 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 16:51:37 +0300 Subject: [PATCH 217/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 2 +- deploy.Jenkinsfile | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 196787bf..6f231eb4 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -37,6 +37,7 @@ pipeline { docker push ${DOCKER_REPO}:latest """ + //here my shared lib usage foo() echo "Docker build and push completed" } catch (Exception e) { @@ -82,7 +83,6 @@ pipeline { sh ''' python3 -m venv venv . venv/bin/activate - pip install -r requirements.txt pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true ls -alh cat pylint.log diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index d25351c1..288d4abd 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -10,33 +10,31 @@ pipeline { stage('Build and Push Docker Image to Nexus') { steps { script { - def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" + def buildNumber = params.BUILD_NUMBER ? params.BUILD_NUMBER : 'latest' + def dockerImage = "${params.IMAGE_NAME}:${buildNumber}" echo "Starting build and push of Docker image ${dockerImage}" sh """ docker login localhost:8083 docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ - echo "Docker push to Nexus completed " + echo "Docker push to Nexus completed successfully" } } } - } - stages { - stage('run docker-compose , polybot and nginx') { + stage('Run Docker Compose') { steps { script { + echo "Running Docker Compose for polybot and nginx" sh """ - cd / - cd /project_poly - git pull https://github.com/beny1221g/ImageProcessingService.git - docker-compose up + cd /project_poly + git pull https://github.com/beny1221g/ImageProcessingService.git + docker-compose up -d """ - echo "containers run successfully" + echo "Containers started successfully" } } } - } } From de092d28724c29421c2a4608a193b321cdb6d964 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 17:03:05 +0300 Subject: [PATCH 218/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 288d4abd..f7d2d343 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -29,6 +29,7 @@ pipeline { echo "Running Docker Compose for polybot and nginx" sh """ cd /project_poly + git config --global --add safe.directory /project_poly git pull https://github.com/beny1221g/ImageProcessingService.git docker-compose up -d """ From 56ca24cef0f4ede658ae4a895b35a4d8c8b220c3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 17:17:14 +0300 Subject: [PATCH 219/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index f7d2d343..461b7ccb 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -23,17 +23,34 @@ pipeline { } } - stage('Run Docker Compose') { + stage('Update Project and Restart Services') { steps { script { - echo "Running Docker Compose for polybot and nginx" + echo "Updating project and restarting Docker services" + + // Ensure proper permissions + sh """ + chown -R jenkins:jenkins /project_poly + """ + + // Pull the latest changes from the Git repository sh """ cd /project_poly git config --global --add safe.directory /project_poly git pull https://github.com/beny1221g/ImageProcessingService.git + """ + + // Stop and remove existing containers + sh """ + docker-compose down + """ + + // Start updated containers + sh """ docker-compose up -d """ - echo "Containers started successfully" + + echo "Project updated and containers restarted successfully" } } } From 1af80518ff9b0a7d68769bed31a3756b80f9295b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 17:27:07 +0300 Subject: [PATCH 220/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 461b7ccb..7cd70143 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -30,7 +30,7 @@ pipeline { // Ensure proper permissions sh """ - chown -R jenkins:jenkins /project_poly + sudo chmod -R 775 /project_poly """ // Pull the latest changes from the Git repository From 4dbfe8868b48acd701d074372ce0425f7fdaf66c Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 17:42:29 +0300 Subject: [PATCH 221/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 7cd70143..9f52bdfe 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -35,7 +35,9 @@ pipeline { // Pull the latest changes from the Git repository sh """ + cd /project_poly + git branch -m master main git config --global --add safe.directory /project_poly git pull https://github.com/beny1221g/ImageProcessingService.git """ From 62853e7fe8e2535440c0b67f88c133dc63f9e259 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 17:52:08 +0300 Subject: [PATCH 222/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 9f52bdfe..b7ddfeba 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -33,11 +33,32 @@ pipeline { sudo chmod -R 775 /project_poly """ - // Pull the latest changes from the Git repository + // Check and switch to the main branch if necessary sh """ - cd /project_poly - git branch -m master main + git fetch + current_branch=\$(git branch --show-current) + if [ "\$current_branch" != "main" ]; then + if git show-ref --quiet refs/heads/main; then + echo "Switching to the 'main' branch." + git checkout main + else + if git show-ref --quiet refs/heads/master; then + echo "Renaming 'master' branch to 'main' and switching to it." + git branch -m master main + git checkout main + else + echo "'main' branch does not exist and 'master' branch is not found to rename." + exit 1 + fi + fi + else + echo "You are already on the 'main' branch." + fi + """ + + // Pull the latest changes from the Git repository + sh """ git config --global --add safe.directory /project_poly git pull https://github.com/beny1221g/ImageProcessingService.git """ From 7030c3c2a02544970cb19cf504f7061713c8674f Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 18:06:50 +0300 Subject: [PATCH 223/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index b7ddfeba..a198dea9 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -35,6 +35,8 @@ pipeline { // Check and switch to the main branch if necessary sh """ + pwd + cd / cd /project_poly git fetch current_branch=\$(git branch --show-current) From e195993a4d0ab7c74f7abce60b62909fa492ce56 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 18:22:05 +0300 Subject: [PATCH 224/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index a198dea9..b2f2b1c8 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -35,9 +35,7 @@ pipeline { // Check and switch to the main branch if necessary sh """ - pwd - cd / - cd /project_poly + cd /deploy_polybot git fetch current_branch=\$(git branch --show-current) if [ "\$current_branch" != "main" ]; then From 5d335cb6926e33ec86f9f1a51cbe32ec377fe34a Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 18:26:55 +0300 Subject: [PATCH 225/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index b2f2b1c8..1af39010 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -35,7 +35,7 @@ pipeline { // Check and switch to the main branch if necessary sh """ - cd /deploy_polybot + cd /polybot git fetch current_branch=\$(git branch --show-current) if [ "\$current_branch" != "main" ]; then From 24b3def2f027e637c7ca097602c08ac0196ce180 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 18:37:10 +0300 Subject: [PATCH 226/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 67 +++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 1af39010..2d2fad98 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -7,21 +7,28 @@ pipeline { } stages { - stage('Build and Push Docker Image to Nexus') { - steps { - script { - def buildNumber = params.BUILD_NUMBER ? params.BUILD_NUMBER : 'latest' - def dockerImage = "${params.IMAGE_NAME}:${buildNumber}" - echo "Starting build and push of Docker image ${dockerImage}" - sh """ - docker login localhost:8083 - docker tag ${dockerImage} localhost:8083/${dockerImage} - docker push localhost:8083/${dockerImage} - """ - echo "Docker push to Nexus completed successfully" - } - } - } +// stage('Build and Push Docker Image to Nexus') { +// steps { +// script { +// def buildNumber = params.BUILD_NUMBER ? params.BUILD_NUMBER : 'latest' +// def dockerImage = "${params.IMAGE_NAME}:${buildNumber}" +// echo "Starting build and push of Docker image ${dockerImage}" +// +// // Debugging: List contents of the temporary directory +// sh """ +// echo "Listing contents of the workspace before build:" +// ls -la /var/lib/jenkins/workspace/deploy_polybot +// """ +// +// sh """ +// docker login localhost:8083 +// docker tag ${dockerImage} localhost:8083/${dockerImage} +// docker push localhost:8083/${dockerImage} +// """ +// echo "Docker push to Nexus completed successfully" +// } +// } +// } stage('Update Project and Restart Services') { steps { @@ -33,32 +40,18 @@ pipeline { sudo chmod -R 775 /project_poly """ - // Check and switch to the main branch if necessary + // Debugging: List contents of the project directory sh """ - cd /polybot - git fetch - current_branch=\$(git branch --show-current) - if [ "\$current_branch" != "main" ]; then - if git show-ref --quiet refs/heads/main; then - echo "Switching to the 'main' branch." - git checkout main - else - if git show-ref --quiet refs/heads/master; then - echo "Renaming 'master' branch to 'main' and switching to it." - git branch -m master main - git checkout main - else - echo "'main' branch does not exist and 'master' branch is not found to rename." - exit 1 - fi - fi - else - echo "You are already on the 'main' branch." - fi + ls + + echo "Listing contents of the project directory before git pull:" + ls -la /project_poly """ // Pull the latest changes from the Git repository sh """ + cd /project_poly + git branch -m master main git config --global --add safe.directory /project_poly git pull https://github.com/beny1221g/ImageProcessingService.git """ @@ -78,4 +71,4 @@ pipeline { } } } -} +} \ No newline at end of file From 6be8123133b5c1a9a112bb5e1716be124b0914ec Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 18:44:36 +0300 Subject: [PATCH 227/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 66 ++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 2d2fad98..b3ec6c7e 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -7,28 +7,21 @@ pipeline { } stages { -// stage('Build and Push Docker Image to Nexus') { -// steps { -// script { -// def buildNumber = params.BUILD_NUMBER ? params.BUILD_NUMBER : 'latest' -// def dockerImage = "${params.IMAGE_NAME}:${buildNumber}" -// echo "Starting build and push of Docker image ${dockerImage}" -// -// // Debugging: List contents of the temporary directory -// sh """ -// echo "Listing contents of the workspace before build:" -// ls -la /var/lib/jenkins/workspace/deploy_polybot -// """ -// -// sh """ -// docker login localhost:8083 -// docker tag ${dockerImage} localhost:8083/${dockerImage} -// docker push localhost:8083/${dockerImage} -// """ -// echo "Docker push to Nexus completed successfully" -// } -// } -// } + stage('Build and Push Docker Image to Nexus') { + steps { + script { + def buildNumber = params.BUILD_NUMBER ? params.BUILD_NUMBER : 'latest' + def dockerImage = "${params.IMAGE_NAME}:${buildNumber}" + echo "Starting build and push of Docker image ${dockerImage}" + sh """ + docker login localhost:8083 + docker tag ${dockerImage} localhost:8083/${dockerImage} + docker push localhost:8083/${dockerImage} + """ + echo "Docker push to Nexus completed successfully" + } + } + } stage('Update Project and Restart Services') { steps { @@ -40,18 +33,33 @@ pipeline { sudo chmod -R 775 /project_poly """ - // Debugging: List contents of the project directory + // Check and switch to the main branch if necessary sh """ ls - - echo "Listing contents of the project directory before git pull:" - ls -la /project_poly + ls /polybot + ls /nginx + current_branch=\$(git branch --show-current) + if [ "\$current_branch" != "main" ]; then + if git show-ref --quiet refs/heads/main; then + echo "Switching to the 'main' branch." + git checkout main + else + if git show-ref --quiet refs/heads/master; then + echo "Renaming 'master' branch to 'main' and switching to it." + git branch -m master main + git checkout main + else + echo "'main' branch does not exist and 'master' branch is not found to rename." + exit 1 + fi + fi + else + echo "You are already on the 'main' branch." + fi """ // Pull the latest changes from the Git repository sh """ - cd /project_poly - git branch -m master main git config --global --add safe.directory /project_poly git pull https://github.com/beny1221g/ImageProcessingService.git """ @@ -71,4 +79,4 @@ pipeline { } } } -} \ No newline at end of file +} From 719ea1bbff0c76771054fadaf7746afa2b5fecea Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 19:25:35 +0300 Subject: [PATCH 228/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index b3ec6c7e..c4fcd5e3 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -35,9 +35,7 @@ pipeline { // Check and switch to the main branch if necessary sh """ - ls - ls /polybot - ls /nginx + current_branch=\$(git branch --show-current) if [ "\$current_branch" != "main" ]; then if git show-ref --quiet refs/heads/main; then From 2b793c42d883df69769d8af1daea7f17503fcb54 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 19:37:20 +0300 Subject: [PATCH 229/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index c4fcd5e3..ad7b6b6e 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -35,7 +35,7 @@ pipeline { // Check and switch to the main branch if necessary sh """ - + cd /project_poly current_branch=\$(git branch --show-current) if [ "\$current_branch" != "main" ]; then if git show-ref --quiet refs/heads/main; then @@ -46,6 +46,8 @@ pipeline { echo "Renaming 'master' branch to 'main' and switching to it." git branch -m master main git checkout main + git push origin main + git push origin --delete master else echo "'main' branch does not exist and 'master' branch is not found to rename." exit 1 From d6efd275259f76414fdf967e5be6c2c3d0db2cde Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 19:40:45 +0300 Subject: [PATCH 230/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index ad7b6b6e..175d325b 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -64,13 +64,11 @@ pipeline { git pull https://github.com/beny1221g/ImageProcessingService.git """ - // Stop and remove existing containers + // Debugging information sh """ + docker-compose config docker-compose down - """ - - // Start updated containers - sh """ + docker-compose build docker-compose up -d """ From ae51a4c9525bfdcec005208a9e55ba9baf24a2e7 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 20:25:25 +0300 Subject: [PATCH 231/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 52 ---------------------------------------------- nginx/Dockerfile | 2 +- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 175d325b..b3658d4d 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -23,58 +23,6 @@ pipeline { } } - stage('Update Project and Restart Services') { - steps { - script { - echo "Updating project and restarting Docker services" - - // Ensure proper permissions - sh """ - sudo chmod -R 775 /project_poly - """ - // Check and switch to the main branch if necessary - sh """ - cd /project_poly - current_branch=\$(git branch --show-current) - if [ "\$current_branch" != "main" ]; then - if git show-ref --quiet refs/heads/main; then - echo "Switching to the 'main' branch." - git checkout main - else - if git show-ref --quiet refs/heads/master; then - echo "Renaming 'master' branch to 'main' and switching to it." - git branch -m master main - git checkout main - git push origin main - git push origin --delete master - else - echo "'main' branch does not exist and 'master' branch is not found to rename." - exit 1 - fi - fi - else - echo "You are already on the 'main' branch." - fi - """ - - // Pull the latest changes from the Git repository - sh """ - git config --global --add safe.directory /project_poly - git pull https://github.com/beny1221g/ImageProcessingService.git - """ - - // Debugging information - sh """ - docker-compose config - docker-compose down - docker-compose build - docker-compose up -d - """ - - echo "Project updated and containers restarted successfully" - } - } - } } } diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 57e7ed82..d45c5719 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,5 +1,5 @@ # Use the official Nginx image as the base image -FROM nginx:alpine +FROM nginx:stable-perl # Copy the Nginx configuration file into the container COPY nginx.conf /etc/nginx/nginx.conf From 41f83dd83c1ac481764b159918bf68c7205d377b Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 20:36:15 +0300 Subject: [PATCH 232/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 105 ++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 6f231eb4..3bc186e2 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,24 +1,24 @@ -@Library('shared-lib') _ +@Library('shared-lib') _ // Import the shared library named 'shared-lib' to use its functions pipeline { options { - buildDiscarder(logRotator(daysToKeepStr: '14')) - disableConcurrentBuilds() - timestamps() - timeout(time: 40, unit: 'MINUTES') // Set a global timeout for the pipeline + buildDiscarder(logRotator(daysToKeepStr: '14')) // Retain build logs for 14 days before discarding them + disableConcurrentBuilds() // Prevent multiple instances of this pipeline from running simultaneously + timestamps() // Add timestamps to the build logs for tracking + timeout(time: 40, unit: 'MINUTES') // Set a global timeout of 40 minutes for the entire pipeline } environment { - IMG_NAME = "polybot:${BUILD_NUMBER}" - DOCKER_REPO = "beny14/polybot" - SNYK_TOKEN = credentials('SNYK_TOKEN') - TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') + IMG_NAME = "polybot:${BUILD_NUMBER}" // Define the Docker image name with the build number + DOCKER_REPO = "beny14/polybot" // Define the Docker repository name + SNYK_TOKEN = credentials('SNYK_TOKEN') // Retrieve Snyk token from Jenkins credentials store + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') // Retrieve Telegram bot token from Jenkins credentials store } agent { docker { - image 'beny14/dockerfile_agent:latest' - args '--user root -v /var/run/docker.sock:/var/run/docker.sock' + image 'beny14/dockerfile_agent:latest' // Use the Docker image 'beny14/dockerfile_agent:latest' for the build agent + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' // Pass Docker-in-Docker setup arguments for the agent } } @@ -28,20 +28,18 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { try { - echo "Starting Docker build" + echo "Starting Docker build" // Log message indicating the start of the Docker build process sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest - docker push ${DOCKER_REPO}:${BUILD_NUMBER} - docker push ${DOCKER_REPO}:latest - + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin // Log in to Docker registry using credentials + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . // Build Docker image with the tag of build number + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest // Tag the Docker image as 'latest' + docker push ${DOCKER_REPO}:${BUILD_NUMBER} // Push the Docker image tagged with the build number to the repository + docker push ${DOCKER_REPO}:latest // Push the Docker image tagged 'latest' to the repository """ - //here my shared lib usage - foo() - echo "Docker build and push completed" + foo() // Call a function named 'foo' from the shared library + echo "Docker build and push completed" // Log message indicating the completion of the Docker build and push } catch (Exception e) { - error "Build failed: ${e.getMessage()}" + error "Build failed: ${e.getMessage()}" // Log error message if the build fails } } } @@ -51,25 +49,24 @@ pipeline { stage('Unit Test') { steps { script { - echo "Starting Unit Tests" + echo "Starting Unit Tests" // Log message indicating the start of unit tests docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh """ - python3 -m venv venv - . venv/bin/activate - pip install --upgrade pip - pip install -r requirements.txt - pip install pytest-xdist pytest-timeout - # Run pytest with verbosity and timeout for each test - python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py - deactivate + python3 -m venv venv // Create a Python virtual environment + . venv/bin/activate // Activate the virtual environment + pip install --upgrade pip // Upgrade pip to the latest version + pip install -r requirements.txt // Install project dependencies from requirements.txt + pip install pytest-xdist pytest-timeout // Install pytest plugins for parallel test execution and timeout + python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py // Run unit tests with concurrency and timeout, saving results to XML + deactivate // Deactivate the virtual environment """ } - echo "Unit Tests completed" + echo "Unit Tests completed" // Log message indicating the completion of unit tests } } post { always { - junit allowEmptyResults: true, testResults: 'results.xml' + junit allowEmptyResults: true, testResults: 'results.xml' // Archive unit test results for Jenkins, allowing empty results } } } @@ -78,20 +75,20 @@ pipeline { steps { script { try { - echo "Starting Lint Tests" + echo "Starting Lint Tests" // Log message indicating the start of lint tests docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' - python3 -m venv venv - . venv/bin/activate - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true - ls -alh - cat pylint.log - deactivate + python3 -m venv venv // Create a Python virtual environment + . venv/bin/activate // Activate the virtual environment + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true // Run lint checks and save output to pylint.log, allowing the command to succeed even with linting issues + ls -alh // List files to verify presence + cat pylint.log // Display the content of the pylint log file + deactivate // Deactivate the virtual environment ''' } - echo "Lint Tests completed" + echo "Lint Tests completed" // Log message indicating the completion of lint tests } catch (Exception e) { - error "Test failed: ${e.getMessage()}" + error "Test failed: ${e.getMessage()}" // Log error message if lint tests fail } } } @@ -99,11 +96,11 @@ pipeline { always { script { try { - archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true - echo "Pylint log content:" - sh 'cat pylint.log' + archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true // Archive the pylint log file, allowing empty archive if the file is missing + echo "Pylint log content:" // Log message before displaying pylint log content + sh 'cat pylint.log' // Display the pylint log content } catch (Exception e) { - echo "Archiving or recording issues failed: ${e.getMessage()}" + echo "Archiving or recording issues failed: ${e.getMessage()}" // Log error if archiving or displaying the log fails } } } @@ -114,28 +111,28 @@ pipeline { post { always { script { - echo "Cleaning up Docker containers and images" - def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() + echo "Cleaning up Docker containers and images" // Log message indicating the start of Docker cleanup + def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() // Get the container ID for the current build image sh """ for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then - docker rm -f \$id || true + docker rm -f \$id || true // Remove old containers except the current build container fi done """ sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true // Remove old Docker images except 'latest' and the current build image """ - cleanWs() - echo "Cleanup completed" + cleanWs() // Clean the Jenkins workspace directory + echo "Cleanup completed" // Log message indicating the completion of cleanup } } failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' - echo "Error occurred: ${errorMessage}" + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' // Determine the error message based on the build result + echo "Error occurred: ${errorMessage}" // Log error message if the build fails } } } From 29df989f2e546317ccbb8e42b935ba298a0bcdec Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 20:40:08 +0300 Subject: [PATCH 233/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 3bc186e2..9e6f93a5 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -30,11 +30,11 @@ pipeline { try { echo "Starting Docker build" // Log message indicating the start of the Docker build process sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin // Log in to Docker registry using credentials - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . // Build Docker image with the tag of build number - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest // Tag the Docker image as 'latest' - docker push ${DOCKER_REPO}:${BUILD_NUMBER} // Push the Docker image tagged with the build number to the repository - docker push ${DOCKER_REPO}:latest // Push the Docker image tagged 'latest' to the repository + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin # Log in to Docker registry using credentials + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . # Build Docker image with the tag of build number + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest # Tag the Docker image as 'latest' + docker push ${DOCKER_REPO}:${BUILD_NUMBER} # Push the Docker image tagged with the build number to the repository + docker push ${DOCKER_REPO}:latest # Push the Docker image tagged 'latest' to the repository """ foo() // Call a function named 'foo' from the shared library echo "Docker build and push completed" // Log message indicating the completion of the Docker build and push @@ -52,13 +52,13 @@ pipeline { echo "Starting Unit Tests" // Log message indicating the start of unit tests docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh """ - python3 -m venv venv // Create a Python virtual environment - . venv/bin/activate // Activate the virtual environment - pip install --upgrade pip // Upgrade pip to the latest version - pip install -r requirements.txt // Install project dependencies from requirements.txt - pip install pytest-xdist pytest-timeout // Install pytest plugins for parallel test execution and timeout - python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py // Run unit tests with concurrency and timeout, saving results to XML - deactivate // Deactivate the virtual environment + python3 -m venv venv # Create a Python virtual environment + . venv/bin/activate # Activate the virtual environment + pip install --upgrade pip # Upgrade pip to the latest version + pip install -r requirements.txt # Install project dependencies from requirements.txt + pip install pytest-xdist pytest-timeout # Install pytest plugins for parallel test execution and timeout + python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py # Run unit tests with concurrency and timeout, saving results to XML + deactivate # Deactivate the virtual environment """ } echo "Unit Tests completed" // Log message indicating the completion of unit tests @@ -78,12 +78,12 @@ pipeline { echo "Starting Lint Tests" // Log message indicating the start of lint tests docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' - python3 -m venv venv // Create a Python virtual environment - . venv/bin/activate // Activate the virtual environment - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true // Run lint checks and save output to pylint.log, allowing the command to succeed even with linting issues - ls -alh // List files to verify presence - cat pylint.log // Display the content of the pylint log file - deactivate // Deactivate the virtual environment + python3 -m venv venv # Create a Python virtual environment + . venv/bin/activate # Activate the virtual environment + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true # Run lint checks and save output to pylint.log, allowing the command to succeed even with linting issues + ls -alh # List files to verify presence + cat pylint.log # Display the content of the pylint log file + deactivate # Deactivate the virtual environment ''' } echo "Lint Tests completed" // Log message indicating the completion of lint tests @@ -96,11 +96,11 @@ pipeline { always { script { try { - archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true // Archive the pylint log file, allowing empty archive if the file is missing + archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true # Archive the pylint log file, allowing empty archive if the file is missing echo "Pylint log content:" // Log message before displaying pylint log content - sh 'cat pylint.log' // Display the pylint log content + sh 'cat pylint.log' # Display the pylint log content } catch (Exception e) { - echo "Archiving or recording issues failed: ${e.getMessage()}" // Log error if archiving or displaying the log fails + echo "Archiving or recording issues failed: ${e.getMessage()}" # Log error if archiving or displaying the log fails } } } @@ -117,12 +117,12 @@ pipeline { sh """ for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then - docker rm -f \$id || true // Remove old containers except the current build container + docker rm -f \$id || true # Remove old containers except the current build container fi done """ sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true // Remove old Docker images except 'latest' and the current build image + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true # Remove old Docker images except 'latest' and the current build image """ cleanWs() // Clean the Jenkins workspace directory echo "Cleanup completed" // Log message indicating the completion of cleanup From 5d232d962c632db108c554340f4ed5639e677068 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 20:45:29 +0300 Subject: [PATCH 234/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 105 ++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index 9e6f93a5..ff25a4bb 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -1,24 +1,24 @@ -@Library('shared-lib') _ // Import the shared library named 'shared-lib' to use its functions +@Library('shared-lib') _ pipeline { options { - buildDiscarder(logRotator(daysToKeepStr: '14')) // Retain build logs for 14 days before discarding them - disableConcurrentBuilds() // Prevent multiple instances of this pipeline from running simultaneously - timestamps() // Add timestamps to the build logs for tracking - timeout(time: 40, unit: 'MINUTES') // Set a global timeout of 40 minutes for the entire pipeline + buildDiscarder(logRotator(daysToKeepStr: '14')) + disableConcurrentBuilds() + timestamps() + timeout(time: 40, unit: 'MINUTES') // Set a global timeout for the pipeline } environment { - IMG_NAME = "polybot:${BUILD_NUMBER}" // Define the Docker image name with the build number - DOCKER_REPO = "beny14/polybot" // Define the Docker repository name - SNYK_TOKEN = credentials('SNYK_TOKEN') // Retrieve Snyk token from Jenkins credentials store - TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') // Retrieve Telegram bot token from Jenkins credentials store + IMG_NAME = "polybot:${BUILD_NUMBER}" + DOCKER_REPO = "beny14/polybot" + SNYK_TOKEN = credentials('SNYK_TOKEN') + TELEGRAM_TOKEN = credentials('TELEGRAM_TOKEN') } agent { docker { - image 'beny14/dockerfile_agent:latest' // Use the Docker image 'beny14/dockerfile_agent:latest' for the build agent - args '--user root -v /var/run/docker.sock:/var/run/docker.sock' // Pass Docker-in-Docker setup arguments for the agent + image 'beny14/dockerfile_agent:latest' + args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } @@ -28,18 +28,20 @@ pipeline { withCredentials([usernamePassword(credentialsId: 'dockerhub_key', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { script { try { - echo "Starting Docker build" // Log message indicating the start of the Docker build process + echo "Starting Docker build" sh """ - echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin # Log in to Docker registry using credentials - docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . # Build Docker image with the tag of build number - docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest # Tag the Docker image as 'latest' - docker push ${DOCKER_REPO}:${BUILD_NUMBER} # Push the Docker image tagged with the build number to the repository - docker push ${DOCKER_REPO}:latest # Push the Docker image tagged 'latest' to the repository + echo ${USERPASS} | docker login -u ${USERNAME} --password-stdin + docker build -t ${DOCKER_REPO}:${BUILD_NUMBER} . + docker tag ${DOCKER_REPO}:${BUILD_NUMBER} ${DOCKER_REPO}:latest + docker push ${DOCKER_REPO}:${BUILD_NUMBER} + docker push ${DOCKER_REPO}:latest + """ - foo() // Call a function named 'foo' from the shared library - echo "Docker build and push completed" // Log message indicating the completion of the Docker build and push + + foo()//shared lib + echo "Docker build and push completed" } catch (Exception e) { - error "Build failed: ${e.getMessage()}" // Log error message if the build fails + error "Build failed: ${e.getMessage()}" } } } @@ -49,24 +51,25 @@ pipeline { stage('Unit Test') { steps { script { - echo "Starting Unit Tests" // Log message indicating the start of unit tests + echo "Starting Unit Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh """ - python3 -m venv venv # Create a Python virtual environment - . venv/bin/activate # Activate the virtual environment - pip install --upgrade pip # Upgrade pip to the latest version - pip install -r requirements.txt # Install project dependencies from requirements.txt - pip install pytest-xdist pytest-timeout # Install pytest plugins for parallel test execution and timeout - python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py # Run unit tests with concurrency and timeout, saving results to XML - deactivate # Deactivate the virtual environment + python3 -m venv venv + . venv/bin/activate + pip install --upgrade pip + pip install -r requirements.txt + pip install pytest-xdist pytest-timeout + # Run pytest with verbosity and timeout for each test + python3 -m pytest -n 4 --timeout=60 --junitxml results.xml tests/*.py + deactivate """ } - echo "Unit Tests completed" // Log message indicating the completion of unit tests + echo "Unit Tests completed" } } post { always { - junit allowEmptyResults: true, testResults: 'results.xml' // Archive unit test results for Jenkins, allowing empty results + junit allowEmptyResults: true, testResults: 'results.xml' } } } @@ -75,20 +78,20 @@ pipeline { steps { script { try { - echo "Starting Lint Tests" // Log message indicating the start of lint tests + echo "Starting Lint Tests" docker.image("${DOCKER_REPO}:${BUILD_NUMBER}").inside { sh ''' - python3 -m venv venv # Create a Python virtual environment - . venv/bin/activate # Activate the virtual environment - pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true # Run lint checks and save output to pylint.log, allowing the command to succeed even with linting issues - ls -alh # List files to verify presence - cat pylint.log # Display the content of the pylint log file - deactivate # Deactivate the virtual environment + python3 -m venv venv + . venv/bin/activate + pylint --disable=E1136,C0301,C0114,E1101,C0116,C0103,W0718,E0401,W0613,R1722,W0612,R0912,C0304,C0115,R1705 polybot/*.py > pylint.log || true + ls -alh + cat pylint.log + deactivate ''' } - echo "Lint Tests completed" // Log message indicating the completion of lint tests + echo "Lint Tests completed" } catch (Exception e) { - error "Test failed: ${e.getMessage()}" // Log error message if lint tests fail + error "Test failed: ${e.getMessage()}" } } } @@ -96,11 +99,11 @@ pipeline { always { script { try { - archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true # Archive the pylint log file, allowing empty archive if the file is missing - echo "Pylint log content:" // Log message before displaying pylint log content - sh 'cat pylint.log' # Display the pylint log content + archiveArtifacts artifacts: 'pylint.log', allowEmptyArchive: true + echo "Pylint log content:" + sh 'cat pylint.log' } catch (Exception e) { - echo "Archiving or recording issues failed: ${e.getMessage()}" # Log error if archiving or displaying the log fails + echo "Archiving or recording issues failed: ${e.getMessage()}" } } } @@ -111,28 +114,28 @@ pipeline { post { always { script { - echo "Cleaning up Docker containers and images" // Log message indicating the start of Docker cleanup - def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() // Get the container ID for the current build image + echo "Cleaning up Docker containers and images" + def containerId = sh(script: "docker ps -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}", returnStdout: true).trim() sh """ for id in \$(docker ps -a -q -f ancestor=${DOCKER_REPO}:${BUILD_NUMBER}); do if [ "\$id" != "${containerId}" ]; then - docker rm -f \$id || true # Remove old containers except the current build container + docker rm -f \$id || true fi done """ sh """ - docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true # Remove old Docker images except 'latest' and the current build image + docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep '${DOCKER_REPO}' | grep -v ':latest' | grep -v ':${BUILD_NUMBER}' | awk '{print \$2}' | xargs --no-run-if-empty docker rmi -f || true """ - cleanWs() // Clean the Jenkins workspace directory - echo "Cleanup completed" // Log message indicating the completion of cleanup + cleanWs() + echo "Cleanup completed" } } failure { script { - def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' // Determine the error message based on the build result - echo "Error occurred: ${errorMessage}" // Log error message if the build fails + def errorMessage = currentBuild.result == 'FAILURE' ? currentBuild.description : 'Build failed' + echo "Error occurred: ${errorMessage}" } } } From 31fa33d80f1d21ddadf30f717dd7853f2ab30c16 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 21:05:31 +0300 Subject: [PATCH 235/241] update build.Jenkinsfile add share-lib --- build.Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.Jenkinsfile b/build.Jenkinsfile index ff25a4bb..7b6d2673 100644 --- a/build.Jenkinsfile +++ b/build.Jenkinsfile @@ -70,6 +70,8 @@ pipeline { post { always { junit allowEmptyResults: true, testResults: 'results.xml' + echo "Unit Test log content:" + sh 'cat results.xml' } } } From c2e27a8e7429bf1442103d10bd2cd359ab6f07fd Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 21:14:03 +0300 Subject: [PATCH 236/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index b3658d4d..23210694 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -10,19 +10,34 @@ pipeline { stage('Build and Push Docker Image to Nexus') { steps { script { - def buildNumber = params.BUILD_NUMBER ? params.BUILD_NUMBER : 'latest' - def dockerImage = "${params.IMAGE_NAME}:${buildNumber}" + def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" echo "Starting build and push of Docker image ${dockerImage}" sh """ docker login localhost:8083 docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ - echo "Docker push to Nexus completed successfully" + echo "Docker push to Nexus completed" } } } + } + stages { + stage('Build and Push Docker Image to Nexus') { + steps { + script { + def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" + echo "Starting build and push of Docker image ${dockerImage}" + sh """ + docker login localhost:8083 + docker tag ${dockerImage} localhost:8083/${dockerImage} + docker push localhost:8083/${dockerImage} + """ + echo "Docker push to Nexus completed" + } + } + } } } From 98ce3b02745630855a220ba1cc24e78cd18505cd Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 21:17:46 +0300 Subject: [PATCH 237/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 23210694..f6a2128a 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -21,23 +21,5 @@ pipeline { } } } - - } - stages { - stage('Build and Push Docker Image to Nexus') { - steps { - script { - def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" - echo "Starting build and push of Docker image ${dockerImage}" - sh """ - docker login localhost:8083 - docker tag ${dockerImage} localhost:8083/${dockerImage} - docker push localhost:8083/${dockerImage} - """ - echo "Docker push to Nexus completed" - } - } - } - } } From 57364c4b4a392539125e32c5c64a5030cf935169 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 21:26:32 +0300 Subject: [PATCH 238/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index f6a2128a..52b4fc9a 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -13,7 +13,7 @@ pipeline { def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" echo "Starting build and push of Docker image ${dockerImage}" sh """ - docker login localhost:8083 + docker login localhost:8081 docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ From 02f75db760233184525e767657fbe44dc4b02ec4 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 22:24:12 +0300 Subject: [PATCH 239/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 52b4fc9a..f6a2128a 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -13,7 +13,7 @@ pipeline { def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" echo "Starting build and push of Docker image ${dockerImage}" sh """ - docker login localhost:8081 + docker login localhost:8083 docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ From 27bc8c9b873a284fb3f01999c2d05ea785a2f938 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sat, 20 Jul 2024 22:57:32 +0300 Subject: [PATCH 240/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index f6a2128a..5b313973 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -7,19 +7,30 @@ pipeline { } stages { - stage('Build and Push Docker Image to Nexus') { + stage('Push Docker Image to Nexus') { steps { - script { - def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" - echo "Starting build and push of Docker image ${dockerImage}" - sh """ - docker login localhost:8083 - docker tag ${dockerImage} localhost:8083/${dockerImage} - docker push localhost:8083/${dockerImage} - """ - echo "Docker push to Nexus completed" + withCredentials([usernamePassword(credentialsId: 'docker_nexus', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) { + script { + def dockerImage = "${params.IMAGE_NAME}:${params.BUILD_NUMBER}" + echo "Starting push of Docker image ${dockerImage} to Nexus" + sh """ + echo ${USERPASS} | docker login localhost:8083 -u ${USERNAME} --password-stdin + docker tag ${dockerImage} localhost:8083/${dockerImage} + docker push localhost:8083/${dockerImage} + """ + echo "Docker push to Nexus completed" + } } } } } -} + + post { + always { + echo "Pipeline completed" + } + failure { + echo "Pipeline failed" + } + } +} \ No newline at end of file From 45cb957607dc5c154251b25c0c1c8176f2e765d3 Mon Sep 17 00:00:00 2001 From: "BZ\\beny1" Date: Sun, 21 Jul 2024 19:44:34 +0300 Subject: [PATCH 241/241] update build.Jenkinsfile add share-lib --- deploy.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.Jenkinsfile b/deploy.Jenkinsfile index 5b313973..05fcf99e 100644 --- a/deploy.Jenkinsfile +++ b/deploy.Jenkinsfile @@ -18,7 +18,7 @@ pipeline { docker tag ${dockerImage} localhost:8083/${dockerImage} docker push localhost:8083/${dockerImage} """ - echo "Docker push to Nexus completed" + echo "Docker push to Nexus completed " } } }