From cb98058974fa54d4c65a9ae4de7bdcf082d35bac Mon Sep 17 00:00:00 2001 From: lolli001 Date: Thu, 18 Jul 2024 17:10:46 -0400 Subject: [PATCH] Updated --- buildspec.yml | 29 +++++++++++++++++++++------- modules/image-pipeline/build.pkr.hcl | 17 +++------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index 7783626..08c4dcb 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -5,18 +5,33 @@ phases: runtime-versions: python: 3.11 commands: - - echo "Installing necessary dependencies" + - echo "Installing Python version 3.11 ..." + - pyenv global $PYTHON_311_VERSION + - echo "Installing Ansible and Packer ..." - pip install ansible - - pip install awscli + - curl -s -qL -o packer.zip https://releases.hashicorp.com/packer/1.10.3/packer_1.10.3_linux_amd64.zip + - unzip -o packer.zip + - mv packer /bin + pre_build: + commands: + - echo "Configuring AWS credentials" + - aws configure set region $AWS_REGION + - aws configure set aws_access_key_id `jq -r '.AccessKeyId' aws_credentials.json` + - aws configure set aws_secret_access_key `jq -r '.SecretAccessKey' aws_credentials.json` + - aws configure set aws_session_token `jq -r '.Token' aws_credentials.json` build: commands: - - echo "Running Packer build" - - packer build -var project_name=rhel-arm-image-pipeline-demo -var ansible_dir=${CODEBUILD_SRC_DIR_SourceAnsibleOutput} modules/image-pipeline/build.pkr.hcl + - echo "Building HashiCorp Packer template, build.pkr.hcl" + - cd ${CODEBUILD_SRC_DIR}/${CODE_SRC_DIR} + - /bin/packer init build.pkr.hcl + - ln -s ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/roles + - /bin/packer build -var project_name=rhel-arm-image-pipeline-demo -var ansible_dir=${CODEBUILD_SRC_DIR_SourceAnsibleOutput} build.pkr.hcl post_build: commands: - - echo "Saving the AMI ID" - - packer build -var 'ami_id=$(cat ami_id.txt)' modules/image-pipeline/build.pkr.hcl + - echo "Build completed" + - cd ${CODEBUILD_SRC_DIR}/${CODE_SRC_DIR} + - test -s ami_id.txt || exit 1 artifacts: files: - - ami_id.txt \ No newline at end of file + - '**/*' \ No newline at end of file diff --git a/modules/image-pipeline/build.pkr.hcl b/modules/image-pipeline/build.pkr.hcl index dc091fe..c72da85 100644 --- a/modules/image-pipeline/build.pkr.hcl +++ b/modules/image-pipeline/build.pkr.hcl @@ -1,21 +1,11 @@ -variable "project_name" { - type = string - default = "rhel-arm-image-pipeline-demo" -} - -variable "ansible_dir" { - type = string - default = "" -} - packer { required_plugins { amazon = { - version = ">= 1.3.2" + version = ">= 1.0.0" source = "github.com/hashicorp/amazon" } ansible = { - version = ">= 1.1.1" + version = ">= 1.0.0" source = "github.com/hashicorp/ansible" } } @@ -30,10 +20,9 @@ source "amazon-ebs" "rhel-arm" { } build { - name = "${var.project_name}" sources = ["source.amazon-ebs.rhel-arm"] provisioner "ansible" { - playbook_file = "${var.ansible_dir}/ansible/rhel-arm-baseline.yaml" + playbook_file = "${var.ansible_dir}/rhel-arm-baseline.yaml" } }