From 7b69b308db81e6a608084c84a0d2f7188cab8f04 Mon Sep 17 00:00:00 2001 From: lolli001 Date: Wed, 24 Jul 2024 14:31:42 -0400 Subject: [PATCH] Updated --- buildspec.yml | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index c4870b1..5c015f6 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -1,27 +1,28 @@ version: 0.2 +env: + variables: + AWS_REGION: "us-gov-west-1" + CODE_SRC_DIR: "source" + CODEBUILD_SRC_DIR_SourceAnsibleOutput: "/codebuild/output/src3467/src/s3/01" + phases: install: - runtime-versions: - python: 3.11 commands: - echo "Installing Python version 3.11 ..." - pyenv global $PYTHON_311_VERSION - - echo "Installing Ansible ..." - - pip3 install ansible - pre_build: - commands: - - echo "Setting up environment ..." + - stat ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/init.sh && bash ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/init.sh ${CODEBUILD_SRC_DIR_SourceAnsibleOutput} || echo "No init.sh script found" - 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: + - stat /bin/packer || unzip -o packer.zip + - stat /bin/packer || $(mv packer /bin && rm packer.zip) + pre_build: commands: - echo "Configuring AWS credentials" + - echo "Fetching AWS credentials from ECS metadata service" + - echo "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}" - 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` @@ -30,13 +31,19 @@ phases: - 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` + build: + commands: - echo "Building HashiCorp Packer template, build.pkr.hcl" - - cd ${CODEBUILD_SRC_DIR} + - cd ${CODEBUILD_SRC_DIR}/${CODE_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 + - 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 AMI ID ..." - - /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 \ No newline at end of file + - cd ${CODEBUILD_SRC_DIR}/${CODE_SRC_DIR} + - test -s ami_id.txt || exit 1 + +artifacts: + files: + - '**/*' + discard-paths: yes \ No newline at end of file