diff --git a/.telegramToken b/.telegramToken deleted file mode 100644 index b77b1f81..00000000 --- a/.telegramToken +++ /dev/null @@ -1 +0,0 @@ -5379937883:AAF9kGAOMUPKzDrPsZbVrp6exqVeud6QWn8 \ No newline at end of file diff --git a/BotDeploy.Jenkinsfile b/BotDeploy.Jenkinsfile deleted file mode 100644 index d7ddf52e..00000000 --- a/BotDeploy.Jenkinsfile +++ /dev/null @@ -1,45 +0,0 @@ -pipeline { - agent any - - parameters { - string(name: 'BOT_IMAGE_NAME') - } - - stages{ - stage("Install Ansible") { - steps { - sh 'python3 -m pip install ansible' - sh '/var/lib/jenkins/.local/bin/ansible-galaxy collection install community.general' - } - } - stage("Generate Ansible Inventory") { - environment { - BOT_EC2_APP_TAG = "danishainBot" - BOT_EC2_REGION = "eu-north-1" - } - steps { - sh 'aws ec2 describe-instances --region $BOT_EC2_REGION --filters "Name=tag:App,Values=$BOT_EC2_APP_TAG" --query "Reservations[].Instances[]" > hosts.json' - sh 'python3 prepare_ansible_inv.py' - sh ''' - echo "Inventory generated" - cat hosts - ''' - } - } - stage('Ansible Bot Deploy') { - environment { - ANSIBLE_HOST_KEY_CHECKING = 'False' - REGISTRY_URL = '352708296901.dkr.ecr.eu-north-1.amazonaws.com' - REGISTRY_REGION = 'eu-north-1' - } - - steps { - withCredentials([sshUserPrivateKey(credentialsId: 'bot-instances', usernameVariable: 'ssh_user', keyFileVariable: 'privatekey')]) { - sh ''' - /var/lib/jenkins/.local/bin/ansible-playbook botDeploy.yaml --extra-vars "registry_region=$REGISTRY_REGION registry_url=$REGISTRY_URL bot_image=$BOT_IMAGE_NAME" --user=${ssh_user} -i hosts --private-key ${privatekey} - ''' - } - } - } - } -} \ No newline at end of file diff --git a/Drake - Falling Back-sOreUnGoIMg.mp4 b/Drake - Falling Back-sOreUnGoIMg.mp4 deleted file mode 100644 index 25545f77..00000000 Binary files a/Drake - Falling Back-sOreUnGoIMg.mp4 and /dev/null differ diff --git a/JenkinsAgent.Dockerfile b/JenkinsAgent.Dockerfile deleted file mode 100644 index 4e565be9..00000000 --- a/JenkinsAgent.Dockerfile +++ /dev/null @@ -1 +0,0 @@ -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/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/ \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 3d6b1aad..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1,46 +0,0 @@ -pipeline { - agent { - docker { - label 'danishain' - image '352708296901.dkr.ecr.eu-north-1.amazonaws.com/danishain-jenkins-agent:1' - args '--user root -v /var/run/docker.sock:/var/run/docker.sock' - } - } - - options { - buildDiscarder(logRotator(daysToKeepStr: '30')) - disableConcurrentBuilds() - timestamps() - } - environment { - REGISTRY_URL = "352708296901.dkr.ecr.eu-north-1.amazonaws.com" - IMAGE_TAG = "0.0.$BUILD_NUMBER" - IMAGE_NAME = "danishain-bot" - } - stages { - stage('Build') { - steps { - sh ''' - aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin $REGISTRY_URL - docker build -t $IMAGE_NAME:$IMAGE_TAG . - docker tag $IMAGE_NAME:$IMAGE_TAG $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG - docker push $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG - ''' - } - post { - always { - sh ''' - docker image prune -f --filter "label=app=bot" - ''' - } - } - } - stage('Trigger Deploy') { - steps { - build job: 'BotDeploy', wait: false, parameters: [ - string(name: 'BOT_IMAGE_NAME', value: "${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}") - ] - } - } - } -} \ No newline at end of file diff --git a/botDeploy.yaml b/botDeploy.yaml deleted file mode 100644 index a0f552f8..00000000 --- a/botDeploy.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- hosts: bot - vars: - ansible_python_interpreter: /usr/bin/python3 - tasks: - - name: Install docker python package - ansible.builtin.pip: - name: docker - executable: pip3 - - - name: Docker login - ansible.builtin.shell: | - aws ecr get-login-password --region {{ registry_region }} | docker login --username AWS --password-stdin {{ registry_url }} - - name: Deploy the bot Docker container - community.general.docker_container: - image: "{{ bot_image }}" - name: bot - state: started - restart_policy: always \ No newline at end of file diff --git a/infra/jenkins/dev/BotBuild.Jenkinsfile b/infra/jenkins/dev/BotBuild.Jenkinsfile index c2e6ee48..4e676421 100644 --- a/infra/jenkins/dev/BotBuild.Jenkinsfile +++ b/infra/jenkins/dev/BotBuild.Jenkinsfile @@ -2,17 +2,27 @@ pipeline { agent { docker { // TODO build & push your Jenkins agent image, place the URL here - image '' + label 'danishain' + image '352708296901.dkr.ecr.eu-north-1.amazonaws.com/danishain-jenkins-ex1:latest' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } - + environment { + REGISTRY_URL = "public.ecr.aws/r7m7o9d4" + IMAGE_TAG = "0.0.$BUILD_NUMBER" + IMAGE_NAME = "danishain-bot-dev" + } stages { stage('Build') { steps { // TODO dev bot build stage sh ''' echo "building..." + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $REGISTRY_URL + docker build -t $IMAGE_NAME:$IMAGE_TAG . -f services/bot/Dockerfile + docker tag $IMAGE_NAME:$IMAGE_TAG $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG + docker push $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG + echo "done" ''' } } @@ -20,7 +30,7 @@ pipeline { stage('Trigger Deploy') { steps { build job: 'BotDeploy', wait: false, parameters: [ - string(name: 'BOT_IMAGE_NAME', value: "") + string(name: 'BOT_IMAGE_NAME', value: "${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}") ] } } diff --git a/infra/jenkins/dev/BotDeploy.Jenkinsfile b/infra/jenkins/dev/BotDeploy.Jenkinsfile index a4cdf512..9f7d720f 100644 --- a/infra/jenkins/dev/BotDeploy.Jenkinsfile +++ b/infra/jenkins/dev/BotDeploy.Jenkinsfile @@ -1,8 +1,9 @@ pipeline { agent { docker { - // TODO build & push your Jenkins agent image, place the URL here - image '' + // TODO build & push your Jenkins agent image, place the URL heree + label 'danishain' + image '352708296901.dkr.ecr.eu-north-1.amazonaws.com/danishain-jenkins-ex1:latest' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } @@ -28,7 +29,7 @@ pipeline { # replace placeholders in YAML k8s files bash common/replaceInFile.sh $K8S_CONFIGS/bot.yaml APP_ENV $APP_ENV bash common/replaceInFile.sh $K8S_CONFIGS/bot.yaml BOT_IMAGE $BOT_IMAGE_NAME - bash common/replaceInFile.sh $K8S_CONFIGS/bot.yaml TELEGRAM_TOKEN $(echo $TELEGRAM_TOKEN | base64) + bash common/replaceInFile.sh $K8S_CONFIGS/bot.yaml TELEGRAM_TOKEN $(echo -n $TELEGRAM_TOKEN | base64) # apply the configurations to k8s cluster kubectl apply --kubeconfig ${KUBECONFIG} -f $K8S_CONFIGS/bot.yaml diff --git a/infra/jenkins/dev/WorkerBuild.Jenkinsfile b/infra/jenkins/dev/WorkerBuild.Jenkinsfile index ae3885b8..2a0d983b 100644 --- a/infra/jenkins/dev/WorkerBuild.Jenkinsfile +++ b/infra/jenkins/dev/WorkerBuild.Jenkinsfile @@ -1,11 +1,39 @@ pipeline { agent { docker { - // TODO build & push your Jenkins agent image, place the URL here - image '' + // TODO build & push your Jenkins agent image, place the URL heree + image '352708296901.dkr.ecr.eu-north-1.amazonaws.com/danishain-jenkins-ex1:latest' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } // TODO dev worker build stage + environment { + REGISTRY_URL = "public.ecr.aws/r7m7o9d4" + IMAGE_TAG = "0.0.$BUILD_NUMBER" + IMAGE_NAME = "danishain-worker-dev" + } + stages { + stage('Build') { + steps { + // TODO dev bot build stage + sh ''' + echo "building..." + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $REGISTRY_URL + docker build -t $IMAGE_NAME:$IMAGE_TAG . -f services/worker/Dockerfile + docker tag $IMAGE_NAME:$IMAGE_TAG $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG + docker push $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG + echo "done" + ''' + } + } + + stage('Trigger Deploy') { + steps { + build job: 'WorkerDeploy', wait: false, parameters: [ + string(name: 'WORKER_IMAGE_NAME', value: "${REGISTRY_URL}/${IMAGE_NAME}:${IMAGE_TAG}") + ] + } + } + } } \ No newline at end of file diff --git a/infra/jenkins/dev/WorkerDeploy.Jenkinsfile b/infra/jenkins/dev/WorkerDeploy.Jenkinsfile index 56514698..5b237fee 100644 --- a/infra/jenkins/dev/WorkerDeploy.Jenkinsfile +++ b/infra/jenkins/dev/WorkerDeploy.Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent { docker { // TODO build & push your Jenkins agent image, place the URL here - image '' + image '352708296901.dkr.ecr.eu-north-1.amazonaws.com/danishain-jenkins-ex1:latest' args '--user root -v /var/run/docker.sock:/var/run/docker.sock' } } diff --git a/prepare_ansible_inv.py b/prepare_ansible_inv.py deleted file mode 100644 index de359ae1..00000000 --- a/prepare_ansible_inv.py +++ /dev/null @@ -1,32 +0,0 @@ -import json - - -def get_instance_name(tags): - for tag in tags: - if tag['Key'] == 'Name': - return tag['Value'] - - raise RuntimeError('Name was not found') - - -def prepare_ansible_inventory(): - with open('hosts.json') as f: - instances = json.load(f) - - hosts = [] - for instance in instances: - instance_name = get_instance_name(instance['Tags']) - instance_ip = instance['PublicIpAddress'] - - hosts.append( - f"{instance_name} ansible_host={instance_ip}\n" - ) - - with open('hosts', 'w') as f: - f.write('[bot]\n') - f.writelines(hosts) - - -if __name__ == '__main__': - - prepare_ansible_inventory() diff --git a/services/bot/Dockerfile b/services/bot/Dockerfile index aa911aaa..e11192b9 100644 --- a/services/bot/Dockerfile +++ b/services/bot/Dockerfile @@ -3,5 +3,4 @@ WORKDIR /app ENV APP_PATH=services/bot COPY . . RUN pip install -r $APP_PATH/requirements.txt - -CMD ["python3", "services/bot/app.py"] \ No newline at end of file +CMD ["python3","-m", "services/bot/app.py"] \ No newline at end of file diff --git a/services/bot/app.py b/services/bot/app.py index afcd1b45..16a090bb 100644 --- a/services/bot/app.py +++ b/services/bot/app.py @@ -60,7 +60,7 @@ def _message_handler(self, update, context): 'chat_id': {'StringValue': chat_id, 'DataType': 'String'} } ) - logger.info(f'msg {response.get("MessageId")} has been sent to queue') + logger.info(f'msg {response.get("MessageId")} has been sent to queue this is a check PR') self.send_text(update, f'Your message is being processed...', chat_id=chat_id) except botocore.exceptions.ClientError as error: