[CI SKIP] Refactored project layout per Mark Wolfe Blog : https://www.wolfe.id.au/2020/03/10/how-do-i-structure-my-go-project/

This commit is contained in:
James Wells 2021-09-21 07:08:52 -07:00
parent 0557021282
commit a7747040ce
Signed by: jwells
GPG key ID: 73196D10B8E65666
31 changed files with 15 additions and 45 deletions

33
assets/docker/Dockerfile Normal file
View file

@ -0,0 +1,33 @@
# FROM golang:1.17-alpine3.14 as builder
FROM dragonheim/golang:1.17.1 as builder
ARG SEMVER
WORKDIR /gagent
COPY . .
ARG GOOS=${GOOS:-linux}
# ARG GOARCH=${GOARCH:-amd64}
ARG CGO_ENABLED=1
RUN apk add --no-cache zeromq-dev build-base git
RUN go build -o /gagent/bin/gagent -ldflags "-X main.semVER=${SEMVER}" cmd/gagent/main.go
RUN strip /gagent/bin/gagent
FROM alpine:3.14
ARG SEMVER
LABEL Name="G'Agent"
LABEL Maintainer="jwells@dragonheim.net"
LABEL License="MIT License"
LABEL version="${SEMVER}"
RUN apk add --no-cache zeromq && mkdir -p -m 0700 /etc/gagent
COPY --from=builder /gagent/assets/examples/gagent.hcl /etc/gagent/gagent.hcl
COPY --from=builder /gagent/bin/gagent /usr/bin/
# Router Client Worker
EXPOSE 35570/tcp 35571/tcp 35572/tcp
VOLUME /etc/gagent
CMD ["/usr/bin/gagent"]
HEALTHCHECK NONE

View file

@ -0,0 +1,12 @@
#####################
### Add 2 numbers ###
#####################
# HINT START
# - math
# - addition
# HINT END
set val1 1
set val2 2
set result [expr {val1 + val2}]
puts result

121
assets/examples/gagent.hcl Normal file
View file

@ -0,0 +1,121 @@
/*
* This is the name of this node and is only used
* for logging purposes.
*
* Optional.
*/
// name = "gagent-zulu.example.org"
/*
* This is the mode that this node operates in. There
* are three modes;
* client == Clients read the local agent file and
* forwards the contents on to a router
*
* router == Routers accept agents from clients and
* other routers and accepts responses to
* agents from workers and other routers.
*
* worker == Workers collect and process agents and
* send responses to routers for return
* the requesting client.
*
* If it is not defined, G'Agent will start in setup
* mode and attempt to write a new configuration file
* to the local directory. The file will be called
* gagent.hcl
*
* Required.
*/
mode = "router"
/*
* @TODO: Add authentication based on UUID
* This is the UUID used throughout the G'Agent system
* to uniquely identify this node. It is generated
* during setup if it doesn't exist.
*
* Required.
*/
// uuid = "7e9d13fe-5151-5876-66c0-20ca03e8fca4"
/*
* This is the IP Address to bind to, it defaults to
* 0.0.0.0
*
* Optional.
*/
// listenaddr = 0.0.0.0
/*
* This is the port to the router will listen for on
* for clients. It defaults to 35570.
*
* Optional.
*/
// clientport = 35571
/*
* This is the port to the router will listen for on
* for other routers. It defaults to 35570.
*
* Optional.
*/
// routerport = 35570
/*
* This is the port to the router will listen for on
* for workers. It defaults to 35571.
*
* Optional.
*/
// workerport = 35572
/*
* @TODO
* This is the list of known G'Agent clients. Clients
* are not registered dynamically, instead the only
* clients that may connect are those listed here,
* but client's of other routers may route, via tags,
* their agent here.
*
* Optional.
*/
// client "alpha" {
// clientid = "04f97538-270d-4ce3-b782-e09ef35830e9"
// }
// client "beta" {
// clientid = "04f97538-270d-4cf3-b782-e09ef35830e9"
// }
/*
* This is a list of known G'Agent routers. At least
* one router is required for workers and clients. If
* there is more than one router, clients and workers
* will connect to them in sequential order.
*/
// router "alpha" {
// routerid = "04f97538-270d-4cb3-b782-e09ef35830e9"
// address = "gagent-alpha.example.org"
// }
// router "beta" {
// routerid = "04f97538-270d-4cc3-b782-e09ef35830e9"
// address = "gagent-beta.example.org"
// }
/*
* This is a list of known G'Agent workers. This is only
* used by routers to determine which workers are
* allowed to accept and respond to agents.
*
* At least one worker is reuqired for routers.
*/
// worker "alpha" {
// workerid = "04f97538-270d-4ce3-b782-e09ef35830e9"
// }
// worker "beta" {
// workerid = "04f97538-270d-4cf3-b782-e09ef35830e9"
// }

View file

@ -0,0 +1,8 @@
###################
### Hello Earth ###
###################
array set GHINT ["thermal measurements" "gravity measurements" "gravity fluctuations"]
proc hello_earth {} {
puts "Hello Earth, does localized tempurature variations alter specific gravity?"
}
hello_earth

BIN
assets/gagent.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

View file

@ -0,0 +1,9 @@
provider "aws" {
alias = "us-west-2"
region = "us-west-2"
}
provider "aws" {
alias = "us-east-1"
region = "us-east-1"
}

View file

@ -0,0 +1,84 @@
variable "vpc_id" {}
data "aws_vpc" "selected" {
id = var.vpc_id
}
variable "regional_cidr_blocks" {
description = "A simple map of subnets used by region"
type = map
default = {
"us-west-2a-private" = "10.172.64.0/23",
"us-west-2b-private" = "10.172.66.0/23",
"us-west-2a-public" = "10.172.68.0/26",
"us-west-2b-public" = "10.172.68.64/26",
"us-east-1a-private" = "10.172.0.0/23",
"us-east-1b-private" = "10.172.2.0/23",
"us-east-1a-public" = "10.172.4.0/26",
"us-east-1b-public" = "10.172.4.64/26"
}
}
resource "aws_subnet" "aza-private" {
depends_on = [data.aws_vpc.selected]
vpc_id = data.aws_vpc.id
availability_zone = format("%sa", var.region)
cidr_block = var.regional_cidr_blocks[
format("%sa-private", var.region)
]
tags = merge(
var.extra_tags,
{
Name = "aza-private"
tier = "private"
}
)
}
# resource "aws_subnet" "aza-public" {
# depends_on = [data.aws_vpc.selected]
# vpc_id = data.aws_vpc.selected.id
# availability_zone = format("%sa", var.region)
# cidr_block = var.regional_cidr_blocks[
# format("%sa-public", var.region)
# ]
# tags = merge(
# var.extra_tags,
# {
# Name = "aza-public"
# tier = "public"
# }
# )
# }
#
# resource "aws_subnet" "azb-private" {
# depends_on = [data.aws_vpc.selected]
# vpc_id = data.aws_vpc.selected.id
# availability_zone = format("%sb", var.region)
# cidr_block = var.regional_cidr_blocks[
# format("%sb-private", var.region)
# ]
# tags = merge(
# var.extra_tags,
# {
# Name = "azb-private"
# tier = "private"
# }
# )
# }
#
# resource "aws_subnet" "azb-public" {
# depends_on = [data.aws_vpc.selected]
# vpc_id = data.aws_vpc.selected.id
# availability_zone = format("%sb", var.region)
# cidr_block = var.regional_cidr_blocks[
# format("%sb-public", var.region)
# ]
# tags = merge(
# var.extra_tags,
# {
# Name = "azb-public"
# tier = "public"
# }
# )
# }

View file

@ -0,0 +1,9 @@
variable "extra_tags" {
description = "Tags required on all resources"
type = map
default = {
"org" = "dragonheim"
"service" = "gagent"
"maintained_by" = "jwells@dragonheim.net"
}
}

View file

@ -0,0 +1,23 @@
variable "region" {}
variable "provider_alias" {}
variable "regional_vpc_cidr" {
description = "A simple map of VPC subnets used by region"
type = map
default = {
"us-west-2" = "10.172.64.0/19",
"us-east-1" = "10.172.0.0/19",
}
}
resource "aws_vpc" "gagent" {
instance_tenancy = "default"
enable_dns_support = true
cidr_block = var.regional_vpc_cidr[var.region]
tags = merge(
var.extra_tags,
{
Name = "gagent"
}
)
}

18
assets/tfenv/main.tf Normal file
View file

@ -0,0 +1,18 @@
# main.tf
module "us-east-1" {
source = "./cluster"
region = "us-east-1"
provider_alias = "us-east-1"
providers = {
aws = "aws.us-east-1"
}
}
module "us-west-2" {
source = "./cluster"
region = "us-west-2"
provider_alias = "us-west-2"
providers = {
aws = "aws.us-west-2"
}
}

View file

@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.0.7"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.59.0"
}
}
}