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

added Jenkins and push scripts with cloudfronts cmd #1

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
23 changes: 9 additions & 14 deletions .github/workflows/trigger-jenkins.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
on: push
# on: push

jobs:
launch_jenkins_job:
name: trigger jenkins job
runs-on: ubuntu-latest
steps:
-
name: Trigger Jenkins Job
uses: sbitio/trigger-jenkins-job@jenkins
# with:
# JENKINS_USER: ${{ secrets.JENKINS_USER }}
# JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
# JENKINS_HOST: ${{ secrets.JENKINS_HOST }}
# JENKINS_JOB: ${{ secrets.JENKINS_JOB }}
# jobs:
# launch_jenkins_job:
# name: trigger jenkins job
# runs-on: ubuntu-latest
# steps:
# -
# name: Trigger Jenkins Job
# uses: sbitio/trigger-jenkins-job@master
111 changes: 111 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
def allowedBranches = ["main", "jenkins"]

def uploadedFiles = ""

pipeline {
agent {
kubernetes {
label 'dind-agent'
}
}
environment {
GIT_AUTHOR_NAME = "Jenkins"
GIT_COMMITTER_NAME = "Jenkins"
}

stages {

stage('Getting Commit Id of Last Push') {
steps {
script {
echo "bob started building"

env.LAST_PUSH = """${sh(
returnStdout: true,
script: '''
set +x;
cat s3LastCommitPush.txt
'''
)}"""

echo "last push commit Id ${env.LAST_PUSH}"
}
}
}

stage('Uploading Asstes') {
steps {
script {
def changedFiles = """${sh(
returnStdout: true,
script: '''
set +x;
git diff ${LAST_PUSH} ${GIT_COMMIT} --name-only --diff-filter=AMR;
'''
)}""".trim().split("\n")

for (file in changedFiles) {
def contentType = ""
if (file == 'package.json') {
continue;
} else if (file ==~ '.*\\.mp4$') {
contentType = "video/mp4"
} else if (file ==~ '.*\\.mp3$') {
contentType = "audio/mpeg"
} else if (file ==~ '.*\\.png$') {
contentType = "image/png"
} else if (file ==~ '.*\\.gif$') {
contentType = "image/gif"
} else if (file ==~ '.*\\.ttf$') {
contentType = "application/font-sfnt"
} else if (file ==~ '.*\\.json$') {
contentType = "application/json"
} else if (file ==~ '.*\\.svg$') {
contentType = "image/svg+xml"
}
else {
continue
}

echo "bob is pushing file ${file} to s3"

def s3Path = "s3://beckn-frontend-assets/${file}"

sh "chmod +x ./push.sh"
sh ("./push.sh ${file} --no-compress --no-resize --no-check")

uploadedFiles += "\n${file}"
}
}
}
}

stage('Updating S3 Push Record') {
steps {
script {
env.SUMMARY = "Files Uploaded: ${uploadedFiles == '' ? 'NA' : uploadedFiles}"

def branchName = 'jenkins'
def commitMessage = "[skip ci] updating s3LastCommitPush"

sh "git config user.email '[email protected]'"
sh "git config user.name 'ny-jenkins'"

sh "git remote set-url origin [email protected]:nammayatri/asset-store.git"
sh "git checkout ${branchName}"

sh "echo ${GIT_COMMIT} > s3LastCommitPush.txt"
sh "git add s3LastCommitPush.txt"

sh "git commit -m \"${commitMessage}\""
sh "git push"

echo "${SUMMARY}"

echo "bob builded successfully 😎"
}
}
}

}
}
Binary file added beckn/passculture/user/images/dummy6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ check_if_png_is_valid()
invalidate_asset()
{
s3_path="$1"
npm run cdn:invalidate $s3_path --prefix node_modules/release-scripts
aws cloudfront create-invalidation --distribution-id $distributionId --paths $s3_path
printf "invalidated $s3_path"
}

push_asset() {
Expand All @@ -64,18 +65,19 @@ push_asset() {

printf "Pushing $local_path to $s3_path ...\n\n"

npm run s3:uploadFile $local_path $s3_path --prefix node_modules/release-scripts -- --public --titan # TODO :: create promise for api call to S3
aws s3 cp $local_path $s3_path
}

asset=""
bucket=jp-remote-assets # TODO : set PROD bucket
bucket="beckn-frontend-assets" # TODO : PROD bucket
distributionId="EZCA94ADQWCV1"
force_push=false

if [ $(echo $@ | sed "s/--[a-zA-Z]*-*[a-zA-Z]*//g" | tr -d '[:space:]' | wc -c) -ne 0 ]
then asset=$(echo $@ | sed "s/--[a-zA-Z]*-*[a-zA-Z]*//g" | tr -d '[:space:]'); fi

if [[ "$@" =~ --sandbox ]]
then bucket="beta-hyper-sdk-assets"; fi # TODO :: set sandbox bucket (optional)
then bucket="beckn-frontend-assets"; fi # TODO :: sandbox bucket (optional)

echo -------------- s3 push starting -------------------

Expand Down Expand Up @@ -123,5 +125,5 @@ then

pathToPush="s3://$bucket/$asset"
push_asset $local_path $pathToPush
invalidate_asset $pathToPush
# invalidate_asset $local_path
fi
1 change: 1 addition & 0 deletions s3LastCommitPush.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3ea1db36fefc3187bd38972210107c95233dc885