Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added Jenkins job to remove retire user files from S3 #1800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions devops/jobs/CheckRetireUser.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package devops.jobs
import static org.edx.jenkins.dsl.Constants.common_wrappers

class CheckRetireUsers {
public static def job = { dslFactory, extraVars ->
assert extraVars.containsKey("DEPLOYMENTS") : "Please define DEPLOYMENTS. It should be list of strings."
assert extraVars.containsKey("IGNORE_LIST") : "Please define IGNORE_LIST. It should be list of strings."
assert !(extraVars.get("DEPLOYMENTS") instanceof String) : "Make sure DEPLOYMENTS is a list of string"

extraVars.get('DEPLOYMENTS').each { deployment , configuration ->
configuration.environments.each { environment ->


dslFactory.job(extraVars.get("FOLDER_NAME","Monitoring") + "/check-retire-users-for-${deployment}") {
parameters {
stringParam('CONFIGURATION_REPO', 'https://github.com/edx/configuration.git')
stringParam('CONFIGURATION_BRANCH', 'master')
}

wrappers common_wrappers

wrappers {
credentialsBinding {
usernamePassword("USERNAME", "PASSWORD", "${deployment}-users-retire-credentials")
def variable = "${deployment}-check-retire-users"
string("ROLE_ARN", variable)
}
}

def rdsignore = ""
extraVars.get('IGNORE_LIST').each { ignore ->
rdsignore = "${rdsignore}-i ${ignore} "
}

def whitelistregions = ""
configuration.REGION_LIST.each { include ->
whitelistregions = "${whitelistregions}-r ${include} "
}

environmentVariables {
env('ENVIRONMENT', environment)
env('DEPLOYMENT', deployment)
env('AWS_DEFAULT_REGION', extraVars.get('REGION'))
env('RDSIGNORE', rdsignore)
env('WHITELISTREGIONS', whitelistregions)
}

multiscm {
git {
remote {
url('$CONFIGURATION_REPO')
branch('$CONFIGURATION_BRANCH')
}
extensions {
cleanAfterCheckout()
pruneBranches()
relativeTargetDirectory('configuration')
}
}
}
steps {
shell(dslFactory.readFileFromWorkspace('devops/resources/check_retire_users.sh'))

}

publishers {
mailer(extraVars.get('NOTIFY_ON_FAILURE'), false, false)

}
}
}
}
}
}
29 changes: 29 additions & 0 deletions devops/resources/check_retire_users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set +u
. /edx/var/jenkins/jobvenvs/virtualenv_tools.sh
# creates a venv with its location stored in variable "venvpath"
create_virtualenv --python=python3.8 --clear
. "$venvpath/bin/activate"
set -u

cd $WORKSPACE/configuration/util/jenkins/remove_retire_user_s3_files

pip install -r requirements.txt
. ../assume-role.sh

# Assume role for different envs
set +x
assume-role ${ROLE_ARN}
set -x

# Set RDSIGNORE if not set in job, need because we're setting -u
# Otherwise we get an error "RDSIGNORE: unbound variable"
if [[ ! -v RDSIGNORE ]]; then
RDSIGNORE=""
fi
if [[ ! -v WHITELISTREGIONS ]]; then
WHITELISTREGIONS=""
fi

python ./remove_retire_user_s3_files.py --environment ${ENVIRONMENT} --deploy ${DEPLOYMENT} --region $AWS_DEFAULT_REGION
Loading