GithubHelp home page GithubHelp logo

infra_challenge's Introduction

infra_challenge

Requirements

  • Python3
  • pip3
  • localstack version 2.0.2

Prerequisites

curl -X POST 'http://localhost:4566/s3-vidhya-test'' curl -X POST 'http://localhost:4566/s3-vidhya-test'/deployhash112/' -H 'Content-Length: 0'

Usage

  • Install the python libs via pip
pip3 install -r requirements.txt
  • Run the cleanup_old_deployments.py with an argument X such as:
python3 cleanup_old_deployments.py 4 --dry-run

Note: here 4 = # of old deployments to cleanup

  • Run unit test with command
python3 test_cleanup_old_deployments.py 

Questions

  1. Where should we run this script?
  • Ideally the script can be run straight from command line/terminal window. The more elegant solution is to hook the script into a CI/CD system like Jenkins. You can create a cron job using a Jenkinsfile as below:
    pipeline {
    agent any
    triggers {
        cron('0 0 * * *')  // Run the job at midnight every day
    }
    stages {
        stage('Run Python Script') {
            steps {
                sh 'python /path/to/my/cleanup_old_deployments.py'
            }
        }
    }
}

  1. How should we test the script before running it production?
  • Run the script in a Test Environment first. Followed by Staging environment. Also a good option would be to take a backup of all the folders before running the script in Production. In case a folder gets accidentally deleted, can recover the same. The script is codified to use --dry-run to ideally simulate what folders will be deleted.
  1. If we want to add an additional requirement of deleting deploys older than 30 days while keeping X deployments. What additional changes would you need to make in the script?
  • The logic would like something like modifying the main() function to calculate the creation date of each deployment folder and compare it with the current date. If the difference between the two dates is greater than 30 days, then the deployment folder should be deleted.

Scope for Improvements

  • Remove hard-coded bucket name. Can be passed in as a parameter or specify a list of buckets so the script is re-usable.
  • Write better unit tests
  • Integrate with a CI/CD system like Jenkins or GitLab

infra_challenge's People

Contributors

vidhyachari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.