Skip to content

Commit

Permalink
Merge pull request #1 from SmartColumbusOS/start
Browse files Browse the repository at this point in the history
Start
  • Loading branch information
dickthedev authored Sep 30, 2019
2 parents c763b5c + 24a9e59 commit 7997da9
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.terraform/
outputs/
terraform.tfstate.d/
*.out
*.plan
.DS_Store
56 changes: 56 additions & 0 deletions Jenkinsfile
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()
}
10 changes: 10 additions & 0 deletions README.md
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
```
69 changes: 69 additions & 0 deletions main.tf
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"
}
13 changes: 13 additions & 0 deletions micro-service-watchinator.yaml
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 added variables/dev.tfvars
Empty file.
Empty file added variables/prod.tfvars
Empty file.
3 changes: 3 additions & 0 deletions variables/sandbox.tfvars
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 added variables/staging.tfvars
Empty file.

0 comments on commit 7997da9

Please sign in to comment.