244 lines
6.5 KiB
Jsonnet
244 lines
6.5 KiB
Jsonnet
local materialUtil = import 'material.jsonnet';
|
|
local helpers = import 'pipeline_helper.jsonnet';
|
|
local pipeline_manifest = import 'pipeline_manifest.json';
|
|
local name = pipeline_manifest.name;
|
|
local pipelines = pipeline_manifest.pipelines;
|
|
|
|
local elastic_profile_map = {
|
|
build: {
|
|
build: 'prod-default',
|
|
},
|
|
test: {
|
|
test: 'prod-default',
|
|
},
|
|
dev: {
|
|
migrate: 'prod-default',
|
|
deploy: 'nonprod-infra',
|
|
},
|
|
qa: {
|
|
migrate: 'prod-default',
|
|
deploy: 'nonprod-infra',
|
|
},
|
|
uat: {
|
|
migrate: 'prod-default',
|
|
deploy: 'nonprod-infra',
|
|
},
|
|
prod: {
|
|
migrate: 'prod-default',
|
|
deploy: 'prod-infra',
|
|
},
|
|
};
|
|
|
|
local infra_provisioner_arg = {
|
|
'rds-deploy': 'database',
|
|
's3-deploy': 's3-buckets',
|
|
'iam-deploy': 'iam-roles',
|
|
'redis-deploy': 'redis',
|
|
'docdb-deploy': 'docdb',
|
|
};
|
|
|
|
{
|
|
test(pipeline):: [
|
|
{
|
|
test:{
|
|
fetch_materials: true,
|
|
approval: {
|
|
type: 'success',
|
|
allow_only_on_success: false,
|
|
},
|
|
jobs: {
|
|
test: {
|
|
timeout: 0,
|
|
elastic_profile_id: elastic_profile_map[pipeline.env].test,
|
|
tasks: [
|
|
{
|
|
exec: {
|
|
command: 'bash',
|
|
arguments: [
|
|
'-c',
|
|
'git submodule update --remote --init',
|
|
],
|
|
working_directory: 'test',
|
|
run_if: 'passed',
|
|
},
|
|
},
|
|
{
|
|
exec: {
|
|
arguments: [
|
|
'-c',
|
|
'eval $(aws ecr get-login --no-include-email --region ap-south-1 --registry-id 193044292705) && docker-compose up --abort-on-container-exit',
|
|
],
|
|
command: 'bash',
|
|
run_if: 'passed',
|
|
working_directory: 'test',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}
|
|
},
|
|
],
|
|
build(pipeline):: [
|
|
{
|
|
build: {
|
|
fetch_materials: true,
|
|
jobs: {
|
|
build: {
|
|
timeout: 0,
|
|
elastic_profile_id: elastic_profile_map[pipeline.env].build,
|
|
tasks: [
|
|
{
|
|
exec: {
|
|
arguments: [
|
|
'-c',
|
|
'docker-build' + ' ' + pipeline_manifest.name,
|
|
],
|
|
command: 'bash',
|
|
run_if: 'passed',
|
|
},
|
|
},
|
|
],
|
|
artifacts: [
|
|
{
|
|
build: {
|
|
source: 'image_version',
|
|
destination: '',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
migrate(pipeline):: [
|
|
{
|
|
migration: {
|
|
fetch_materials: true,
|
|
approval: {
|
|
type: helpers.getApprovalType(pipeline.stages,'migrate'),
|
|
allow_only_on_success: false,
|
|
},
|
|
jobs: {
|
|
migration: {
|
|
elastic_profile_id: elastic_profile_map[pipeline.env].migrate,
|
|
tasks: [
|
|
{
|
|
fetch: {
|
|
is_file: true,
|
|
source: 'image_version',
|
|
destination: 'deployment',
|
|
pipeline: helpers.artifactPipeline(pipeline),
|
|
stage: 'build',
|
|
job: 'build',
|
|
run_if: 'passed',
|
|
},
|
|
},
|
|
{
|
|
script: ' cd deployment \n . fetch_config_portal \n eval $(aws ecr get-login --no-include-email --region ap-south-1 --registry-id 193044292705)\n docker run -w /usr/local \\ \n -e DATASOURCE_URL=${DATASOURCE_URL} -e DATASOURCE_USERNAME=${DATASOURCE_USERNAME} \\ \n -e DATASOURCE_PASSWORD=${DATASOURCE_PASSWORD} `cat image_version` java -jar database.jar',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
deploy(pipeline):: [
|
|
{
|
|
deploy: {
|
|
fetch_materials: true,
|
|
approval: {
|
|
type: helpers.getApprovalType(pipeline.stages,'deploy'),
|
|
allow_only_on_success: false,
|
|
},
|
|
jobs: {
|
|
deploy: {
|
|
timeout: 0,
|
|
elastic_profile_id: elastic_profile_map[pipeline.env].deploy,
|
|
tasks: [
|
|
{
|
|
fetch: {
|
|
is_file: true,
|
|
source: 'image_version',
|
|
destination: 'deployment',
|
|
pipeline: helpers.artifactPipeline(pipeline),
|
|
stage: 'build',
|
|
job: 'build',
|
|
run_if: 'passed',
|
|
},
|
|
},
|
|
{
|
|
exec: {
|
|
arguments: [
|
|
'-c',
|
|
'portal_deploy ${ENVIRONMENT} `cat image_version`',
|
|
],
|
|
command: 'bash',
|
|
run_if: 'passed',
|
|
working_directory: 'deployment',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
deployAwsResourcesWithPlan(pipeline, type):: [
|
|
{
|
|
plan: {
|
|
approval: {
|
|
type: "manual",
|
|
allow_only_on_success: false
|
|
},
|
|
environment_variables: {
|
|
"ADDITIONAL_OPTIONS": "--plan"
|
|
},
|
|
jobs: {
|
|
"deploy": {
|
|
elastic_profile_id: 'prod-infra',
|
|
tasks: [
|
|
{
|
|
script: '. fetch_manifest\n infra-provisioner-v2 -m $MANIFEST ${ADDITIONAL_OPTIONS} all\n'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
deploy: {
|
|
approval: {
|
|
type: "manual",
|
|
allow_only_on_success: false
|
|
},
|
|
environment_variables: {
|
|
"ADDITIONAL_OPTIONS": ""
|
|
},
|
|
jobs: {
|
|
"deploy": {
|
|
elastic_profile_id: 'prod-infra',
|
|
tasks: [
|
|
{
|
|
script: ". fetch_manifest\n infra-provisioner-v2 -m $MANIFEST ${ADDITIONAL_OPTIONS} all\n"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
},
|
|
],
|
|
getStages(pipeline)::
|
|
if pipeline.type == 'test' then $.test(pipeline)
|
|
else if pipeline.type == 'build' then $.build(pipeline)
|
|
else if pipeline.type == 'migrate-deploy' then (
|
|
(if std.objectHas(helpers.stageMap(pipeline), 'migrate') then $.migrate(pipeline) else []) +
|
|
(if std.objectHas(helpers.stageMap(pipeline), 'deploy') then $.deploy(pipeline) else [])
|
|
) else if pipeline.type == 'rds-deploy' ||
|
|
pipeline.type == 's3-deploy' ||
|
|
pipeline.type == 'redis-deploy' ||
|
|
pipeline.type == 'docdb-deploy' ||
|
|
pipeline.type == 'iam-deploy' then $.deployAwsResourcesWithPlan(pipeline, infra_provisioner_arg[pipeline.type])
|
|
}
|