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: refactor packer templates #221

Merged
merged 6 commits into from
May 14, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(packer) cleanup references to former .auto.pkrvars.hcl
Signed-off-by: Damien Duportal <[email protected]>
dduportal committed May 14, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fc4c2d1b291f131458f5fe508f00ce2e8ceefebf
33 changes: 6 additions & 27 deletions Jenkinsfile_k8s
Original file line number Diff line number Diff line change
@@ -134,40 +134,19 @@ pipeline {
AWS_SECRET_ACCESS_KEY = credentials('packer-aws-secret-access-key')
PACKER_HOME_DIR = "/tmp/packer.d.${PKR_VAR_image_type}.${PKR_VAR_architecture}.${PKR_VAR_agent}"
PACKER_PLUGIN_PATH = "${PACKER_HOME_DIR}/plugins"
PACKER_VARS_FILE = ".auto.pkrvars.hcl"
// Define Packer Input variables through environment variables prefixed with 'PKR_VAR_'
// Re.f https://www.packer.io/docs/templates/hcl_templates/variables#assigning-values-to-build-variables
PKR_VAR_build_type = "${env.TAG_NAME ? 'prod' : (env.BRANCH_IS_PRIMARY ? 'staging' : 'dev') }"
PKR_VAR_image_version = "${env.TAG_NAME ?: ''}"
PKR_VAR_scm_ref = "${env.GIT_COMMIT}"
// Reuse the updatecli Github token to ensure that packer init does not hit the rate limit
GITHUB_IAT_TOKEN = credentials('github-app-infra')
}
stages {
stage('Prepare on primary branch') {
when {
expression { env.BRANCH_IS_PRIMARY }
}
steps {
sh '''
echo 'build_type = "staging"' >> "${PACKER_VARS_FILE}"
'''
}
}
stage('Prepare on Tag') {
when {
buildingTag()
}
steps {
sh '''
set -eu
echo 'build_type = "prod"' >> "${PACKER_VARS_FILE}"
echo 'image_version = "'${TAG_NAME}'"' >> "${PACKER_VARS_FILE}"
'''
}
}
stage('Prepare and Report') {
steps {
withEnv(["PACKER_GITHUB_API_TOKEN=${GITHUB_IAT_TOKEN_PSW}"]) {
sh '''
echo 'scm_ref = "'"$(git rev-parse --short --verify HEAD)"'"' >> "${PACKER_VARS_FILE}"
./run-packer.sh report
'''
sh './run-packer.sh report'
}
}
}
5 changes: 1 addition & 4 deletions run-packer.sh
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ then
fi
fi

## Always run initialization to ensure plugins are download and workspace is set up
## Always run initialization to ensure plugins are downloaded and workspace is set up
$packer_cmd init "${packer_template_dir}"

## Define Packer flags based on the current environment (look at the `Jenkinsfile` to diagnose the pipeline)
@@ -73,9 +73,6 @@ case $1 in
echo "= Current Packer environment:"
env | grep -i PKR_VAR
env | grep -i PACKER
PACKER_VARS_FILE=.auto.pkrvars.hcl
echo "= Current Packer var file ${PACKER_VARS_FILE} =="
cat "${PACKER_VARS_FILE}"
;;
*)
echo "Error: Packer action '$1' is unknown."