Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lolli001 committed Jul 18, 2024
1 parent d29b1ba commit cb98058
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
29 changes: 22 additions & 7 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- '**/*'
17 changes: 3 additions & 14 deletions modules/image-pipeline/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand All @@ -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"
}
}

0 comments on commit cb98058

Please sign in to comment.