Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions codepipeline-tf/buildspec_yml/apply_buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Copyright (c) 2023, Xgrid Inc, https://xgrid.co
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier:Apache-2.0

version: 0.2

phases:
pre_build:
commands:
- echo $0
- apk --update add aws-cli
- ls
- cd infrastructure
- cat backend.tf
- |
terraform workspace select ${namespace}
build:
commands:
- cat backend.tf
- mkdir python
- apk add python3
- apk add py3-pip
- apk add zip
- pip3 install -t python/ prometheus-client
- zip -r python.zip ./python
- echo "Applying XC3 Infrastructure"
- terraform apply -auto-approve || echo "Terraform apply failed, but continuing the pipeline....."
artifacts:
files:
- '**/*'
32 changes: 32 additions & 0 deletions codepipeline-tf/buildspec_yml/destroy_buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#Copyright (c) 2023, Xgrid Inc, https://xgrid.co
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier:Apache-2.0

version: 0.2

phases:
pre_build:
commands:
- echo $0
- ls
- cd infrastructure
- cat backend.tf
- |
terraform workspace select ${namespace}
build:
commands:
- echo "Destroying the XC3 Infrastructure"
- terraform destroy --auto-approve


artifacts:
files:
- '**/*'
67 changes: 67 additions & 0 deletions codepipeline-tf/buildspec_yml/init_buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#Copyright (c) 2023, Xgrid Inc, https://xgrid.co

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# SPDX-License-Identifier:Apache-2.0

version: 0.2

phases:
pre_build:
commands:
- echo $0
- echo "Initializing the XC3 Infrastructure"
- ls
- cd infrastructure
- ls
- echo ${s3_bucket_name}

- sed -i "s/export bucket_name=.*/export bucket_name=\"$s3_bucket_name\"/" config.sh
- sed -i "s/export project=.*/export project=\"$namespace\"/" config.sh
- sed -i "s/export domain=.*/export domain=\"${domain_name}\"/" config.sh
- sed -i "s/export namespace=.*/export namespace=\"$namespace\"/" config.sh
- sed -i "s/export env=.*/export env=\"prod\"/" config.sh

- cat config.sh
- apk --update add bash
- apk --update add aws-cli
- bash pre_req.sh

- sed -i "s/\"terraform-state-xc3\"/\"$s3_bucket_name\"/g" backend.tf
- sed -i 's/xc3\/xc3.tfstate/'${key}'/g' backend.tf

- cat backend.tf
- sed -i "s/\"testing\"/\"$namespace\"/g" terraform.auto.tfvars
- sed -i "s/\"123456789\"/\"$account_id\"/g" terraform.auto.tfvars
- sed -i "s/\"\"/\"$domain_name\"/g" terraform.auto.tfvars

- sed -i 's/"testing"/'${namespace}'/g' terraform.auto.tfvars
- sed -i 's/"123456789"/'${account_id}'/g' terraform.auto.tfvars
- sed -i 's/""/'${domain_name}'/g' terraform.auto.tfvars
- sed -i 's/create_cloudtrail_kms\s*=\s*true/create_cloudtrail_kms = false/g' terraform.auto.tfvars
- sed -i 's/create_cloudtrail\s*=\s*true/create_cloudtrail = false/g' terraform.auto.tfvars
- sed -i 's/create_cloudtrail_s3_bucket\s*=\s*true/create_cloudtrail_s3_bucket = false/g' terraform.auto.tfvars

- cat terraform.auto.tfvars
build:
commands:
- terraform init
- |
if ! terraform workspace select ${namespace}; then
terraform workspace new ${namespace}
terraform workspace select ${namespace}
fi
- terraform validate
artifacts:
files:
- '**/*'
31 changes: 31 additions & 0 deletions codepipeline-tf/buildspec_yml/plan_buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#Copyright (c) 2023, Xgrid Inc, https://xgrid.co
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier:Apache-2.0

version: 0.2

phases:
pre_build:
commands:
- echo $0
- ls
- cd infrastructure
- cat backend.tf
- cat terraform.auto.tfvars
- |
terraform workspace select ${namespace}
build:
commands:
- echo "Plan Run of XC3 Infrastructure"
- terraform plan
artifacts:
files:
- '**/*'
34 changes: 34 additions & 0 deletions codepipeline-tf/buildspec_yml/unit_test_buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#Copyright (c) 2023, Xgrid Inc, https://xgrid.co
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier:Apache-2.0

version: 0.2

phases:
install:
commands:
- echo Installing Python Services
- apk update && apk upgrade
- apk add python3
- apk add py3-pip
build:
commands:
- ls
- cd infrastructure
- ls
- terraform workspace select ${namespace}
- cd ../tests/unit_test
- ls
- pytest *.py && echo "Tests passed" || echo "Tests failed"
- cd ../../infrastructure/
artifacts:
files:
- '**/*'
46 changes: 46 additions & 0 deletions codepipeline-tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright (c) 2023, Xgrid Inc, https://xgrid.co

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
*/

# code pipeline module
module "xc3_pipeline" {

source = "./modules/xc3_codepipeline"
tags = var.tags

namespace_name = var.namespace_name
account_id = var.account_id
domain_name = var.domain_name
xc3_codepipeline_role = var.xc3_codepipeline_role
codebuild_service_role = var.codebuild_service_role
codestar_connections = var.codestar_connections
approve_comment_for_apply = var.approve_comment_for_apply
approve_comment_for_destroy = var.approve_comment_for_destroy
buildspec_folder_path = var.buildspec_folder_path
init_buildspec = var.init_buildspec
plan_buildspec = var.plan_buildspec
test_buildspec = var.test_buildspec
apply_buildspec = var.apply_buildspec
destroy_buildspec = var.destroy_buildspec
compute_type_for_building = var.compute_type_for_building
os_type = var.os_type
docker_image_used = var.docker_image_used
s3_bucket_name = var.s3_bucket_name
full_repository_id = var.full_repository_id
full_branch_name = var.full_branch_name
key = var.key
}
Loading