-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SmartColumbusOS/start
Start
- Loading branch information
Showing
9 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.terraform/ | ||
outputs/ | ||
terraform.tfstate.d/ | ||
*.out | ||
*.plan | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
library( | ||
identifier:'pipeline-lib@4.3.1', | ||
retriever:modernSCM([$class:'GitSCMSource', | ||
remote:'https://github.com/SmartColumbusOS/pipeline-lib', | ||
credentialsId:'jenkins-github-user']) | ||
) | ||
|
||
properties([ | ||
pipelineTriggers([scos.dailyBuildTrigger()]), | ||
parameters([ | ||
booleanParam(defaultValue: false, description: 'Deploy to development environment?', name: 'DEV_DEPLOYMENT'), | ||
string(defaultValue: 'development', description: 'Image tag to deploy to dev environment', name: 'DEV_IMAGE_TAG') | ||
]) | ||
]) | ||
|
||
def image, imageName | ||
def doStageIf = scos.&doStageIf | ||
def doStageIfDeployingToDev = doStageIf.curry(env.DEV_DEPLOYMENT == "true") | ||
def doStageIfMergedToMaster = doStageIf.curry(scos.changeset.isMaster && env.DEV_DEPLOYMENT == "false") | ||
def doStageIfRelease = doStageIf.curry(scos.changeset.isRelease) | ||
|
||
node ('infrastructure') { | ||
ansiColor('xterm') { | ||
scos.doCheckoutStage() | ||
|
||
doStageIfDeployingToDev('Deploy to Dev') { | ||
deployTo('dev', "--set image.tag=${env.DEV_IMAGE_TAG} --recreate-pods") | ||
} | ||
|
||
doStageIfMergedToMaster('Process Dev job') { | ||
scos.devDeployTrigger('micro-service-watchinator') | ||
} | ||
|
||
doStageIfMergedToMaster('Deploy to Staging') { | ||
deployTo('staging') | ||
scos.applyAndPushGitHubTag('staging') | ||
} | ||
|
||
doStageIfRelease('Deploy to Production') { | ||
deployTo('prod') | ||
scos.applyAndPushGitHubTag('prod') | ||
} | ||
} | ||
} | ||
|
||
|
||
def deployTo(environment, extraHelmCommandArgs = '') { | ||
def extraVars = [ | ||
'extraHelmCommandArgs': extraHelmCommandArgs | ||
] | ||
|
||
def terraform = scos.terraform(environment) | ||
sh "terraform init && terraform workspace new ${environment}" | ||
terraform.plan(terraform.defaultVarFile, extraVars) | ||
terraform.apply() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# micro_service_watchinator-deploy | ||
Deploy repository for micro_service_watchinator | ||
|
||
|
||
# Deploying Via Terraform | ||
``` | ||
env=dev | ||
terraform init -backend-config=../common/backends/alm.conf | ||
terraform workspace new $env | ||
terraform plan --var-file=variables/$env.tfvars -var 'watchinator_image_name=199837183662.dkr.ecr.us-east-2.amazonaws.com/scos/micro-service-watchinator:<Image Tag>' --out=my.out | ||
terraform apply my.out | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
data "terraform_remote_state" "env_remote_state" { | ||
backend = "s3" | ||
workspace = "${terraform.workspace}" | ||
|
||
config { | ||
bucket = "${var.alm_state_bucket_name}" | ||
key = "operating-system" | ||
region = "us-east-2" | ||
role_arn = "${var.alm_role_arn}" | ||
} | ||
} | ||
|
||
resource "local_file" "kubeconfig" { | ||
filename = "${path.module}/outputs/kubeconfig" | ||
content = "${data.terraform_remote_state.env_remote_state.eks_cluster_kubeconfig}" | ||
} | ||
|
||
resource "local_file" "helm_vars" { | ||
filename = "${path.module}/outputs/${terraform.workspace}.yaml" | ||
|
||
content = <<EOF | ||
CONSUMER_URI: wss://streams.${data.terraform_remote_state.env_remote_state.dns_zone_name}/socket/websocket | ||
image: | ||
repository: ${var.image_repository} | ||
tag: ${var.tag} | ||
EOF | ||
} | ||
|
||
resource "null_resource" "helm_deploy" { | ||
provisioner "local-exec" { | ||
command = <<EOF | ||
export KUBECONFIG=${local_file.kubeconfig.filename} | ||
helm upgrade --install --namespace=watchinator ${var.watchinator_deploy_name} chart/ \ | ||
--values ${local_file.helm_vars.filename} | ||
EOF | ||
} | ||
|
||
triggers { | ||
# Triggers a list of values that, when changed, will cause the resource to be recreated | ||
# ${uuid()} will always be different thus always executing above local-exec | ||
hack_that_always_forces_null_resources_to_execute = "${uuid()}" | ||
} | ||
} | ||
|
||
variable "alm_role_arn" { | ||
description = "The ARN for the assume role for ALM access" | ||
default = "arn:aws:iam::199837183662:role/jenkins_role" | ||
} | ||
|
||
variable "alm_state_bucket_name" { | ||
description = "The name of the S3 state bucket for ALM" | ||
default = "scos-alm-terraform-state" | ||
} | ||
|
||
variable "watchinator_deploy_name" { | ||
description = "The helm deploy name to give to the watchinator" | ||
default = "watchinator" | ||
} | ||
|
||
variable "image_repository" { | ||
description = "The image repository" | ||
default = "199837183662.dkr.ecr.us-east-2.amazonaws.com/scos/micro-service-watchinator" | ||
} | ||
|
||
variable "tag" { | ||
description = "The tag/version of the image to deploy" | ||
default = "latest" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
replicaCount: 1 | ||
CONSUMER_URI: "" | ||
metrics: | ||
port: 4002 | ||
resourceLimits: | ||
cpu: 100m | ||
memory: 128Mi | ||
|
||
namespace: watchinator | ||
image: | ||
repository: smartcitiesdata/micro-service-watchinator | ||
tag: 1.0.0 | ||
pullPolicy: IfNotPresent |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
alm_state_bucket_name = "scos-sandbox-terraform-state" | ||
|
||
alm_role_arn = "arn:aws:iam::068920858268:role/admin_role" |
Empty file.