Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lolli001 committed Jul 24, 2024
1 parent de6dbae commit 80bcd07
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
29 changes: 25 additions & 4 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,34 @@ phases:
- pyenv global $PYTHON_311_VERSION
- echo "Installing Ansible ..."
- pip3 install ansible
pre_build:
commands:
- echo "Setting up environment ..."
- which pip3 || curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
- which pip3 || python3 get-pip.py --user
- stat $(python -m site --user-base)/bin/ansible-playbook || python3 -m pip install --user ansible pywinrm
- export PATH=$PATH:$(python -m site --user-base)/bin
- stat /bin/packer || curl -s -qL -o packer.zip https://releases.hashicorp.com/packer/1.10.3/packer_1.10.3_linux_amd64.zip
- stat /bin/packer || unzip -o packer.zip && mv packer /bin && rm packer.zip
- stat ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/init.sh && bash ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/init.sh ${CODEBUILD_SRC_DIR_SourceAnsibleOutput} || echo "No init.sh script found"
build:
commands:
- echo "Building with Packer ..."
- packer init build.pkr.hcl
- packer build -var project_name=rhel-arm-image-pipeline-demo -var ansible_dir=${CODEBUILD_SRC_DIR}/ansible build.pkr.hcl
- echo "Configuring AWS credentials"
- curl -qL -o aws_credentials.json http://169.254.170.2/${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI} > aws_credentials.json
- aws configure set region $AWS_REGION
- aws configure set aws_access_key_id `jq -r '.AccessKeyId' aws_credentials.json`
- export AWS_ACCESS_KEY_ID=`jq -r '.AccessKeyId' aws_credentials.json`
- aws configure set aws_secret_access_key `jq -r '.SecretAccessKey' aws_credentials.json`
- export AWS_SECRET_ACCESS_KEY=`jq -r '.SecretAccessKey' aws_credentials.json`
- aws configure set aws_session_token `jq -r '.Token' aws_credentials.json`
- export AWS_SESSION_TOKEN=`jq -r '.Token' aws_credentials.json`
- echo "Building HashiCorp Packer template, build.pkr.hcl"
- cd ${CODEBUILD_SRC_DIR}
- /bin/packer init build.pkr.hcl
- ln -s ${CODEBUILD_SRC_DIR}/roles
- /bin/packer build -var project_name=rhel-arm-image-pipeline-demo -var ansible_dir=${CODEBUILD_SRC_DIR} build.pkr.hcl
post_build:
commands:
- echo "Saving AMI ID ..."
- packer build -machine-readable build.pkr.hcl | tee >(grep 'artifact,0,id' | cut -d, -f6 | cut -d: -f2 > ami_id.txt)
- /bin/packer build -machine-readable build.pkr.hcl | tee >(grep 'artifact,0,id' | cut -d, -f6 | cut -d: -f2 > ami_id.txt)
- test -s ami_id.txt || exit 1
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module "rhel-arm" {
state = local.state_config
vpc_config = local.vpc_config
source_ami = "ami-03f5c6b8195c66b04"
instance_type = "t4g.micro"
instance_type = "t3.micro"
}

resource "random_password" "winrm" {
Expand Down
2 changes: 1 addition & 1 deletion modules/image-pipeline/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "amazon-ebs" "rhel" {
ami_name = "rhel-arm-{{timestamp}}"
instance_type = "t4g.micro" # Ensure the instance type is ARM64 compatible
instance_type = "t3.micro" # Ensure the instance type is ARM64 compatible
region = "us-gov-west-1"
source_ami = "ami-03f5c6b8195c66b04" # Updated AMI ID for RHEL 9 ARM
ssh_username = "ec2-user"
Expand Down

0 comments on commit 80bcd07

Please sign in to comment.