Skip to content

Commit

Permalink
Merge pull request #221 from weaveworks/static-ami-generator
Browse files Browse the repository at this point in the history
Generation of static AMI list
  • Loading branch information
richardcase authored Sep 21, 2018
2 parents 3992f9d + 23aaab4 commit 78209ca
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 38 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; http://editorconfig.org/

root = true

[*]
charset = utf-8

end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

indent_size = 4
indent_style = space

[*.go]
indent_style = tab

[Makefile]
indent_style = tab
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ARG COVERALLS_TOKEN
ENV COVERALLS_TOKEN $COVERALLS_TOKEN

WORKDIR $EKSCTL
RUN make lint && make test && make \
RUN make lint && make test && make build \
&& cp ./eksctl /out/usr/local/bin/eksctl

RUN go build ./vendor/github.com/heptio/authenticator/cmd/heptio-authenticator-aws \
Expand Down
64 changes: 47 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,39 @@ git_commit := $(shell git describe --dirty --always)
EKSCTL_BUILD_IMAGE ?= weaveworks/eksctl:build
EKSCTL_IMAGE ?= weaveworks/eksctl:latest

.PHONY: build
build:
@go build -ldflags "-X main.gitCommit=$(git_commit) -X main.builtAt=$(built_at)" ./cmd/eksctl
.DEFAULT_GOAL:=help

##@ Dependencies

.PHONY: install-build-deps
install-build-deps:
install-build-deps: ## Install dependencies (packages and tools)
@cd build && dep ensure && ./install.sh

##@ Build

.PHONY: build
build: ## Build eksctl
@go build -ldflags "-X main.gitCommit=$(git_commit) -X main.builtAt=$(built_at)" ./cmd/eksctl

##@ Testing & CI

.PHONY: test
test: generate
test: generate ## Run unit tests
@git diff --exit-code pkg/nodebootstrap/assets.go > /dev/null || (git --no-pager diff; exit 1)
@git diff --exit-code ./pkg/eks/mocks > /dev/null || (git --no-pager diff; exit 1)
@go test -v -covermode=count -coverprofile=coverage.out ./pkg/... ./cmd/...
@test -z $(COVERALLS_TOKEN) || $(GOPATH)/bin/goveralls -coverprofile=coverage.out -service=circle-ci

.PHONY: lint
lint:
lint: ## Run GoMetalinter over the codebase
@$(GOPATH)/bin/gometalinter ./...

.PHONY: ci
ci: test lint
ci: test lint ## Target for CI system to invoke to run tests and linting

TEST_CLUSTER ?= integration-test-dev
.PHONY: integration-test-dev
integration-test-dev: build
integration-test-dev: build ## Run the integration tests without cluster teardown. For use when developing integration tests.
@./eksctl utils write-kubeconfig \
--auto-kubeconfig \
--name=$(TEST_CLUSTER)
Expand All @@ -39,23 +47,35 @@ integration-test-dev: build
-eksctl.delete=false \
-eksctl.kubeconfig=$(HOME)/.kube/eksctl/clusters/$(TEST_CLUSTER)

create-integration-test-dev-cluster: build
create-integration-test-dev-cluster: build ## Create a test cluster for use when developing integration tests
@./eksctl create cluster --name=integration-test-dev --auto-kubeconfig

delete-integration-test-dev-cluster: build
delete-integration-test-dev-cluster: build ## Delete the test cluster for use when developing integration tests
@./eksctl delete cluster --name=integration-test-dev --auto-kubeconfig

.PHONY: integration-test
integration-test: build
integration-test: build ## Run the integration tests (with cluster creation and cleanup)
@go test -tags integration -v -timeout 21m ./tests/integration/...

##@ Code Generation

.PHONY: generate
generate:
generate: ## Generate code
@chmod g-w ./pkg/nodebootstrap/assets/*
@go generate ./pkg/nodebootstrap ./pkg/eks/mocks

.PHONY: generate-ami
generate-ami: ## Generate the list of AMIs for use with static resolver. Queries AWS.
@go generate ./pkg/ami

.PHONY: ami-check
ami-check: generate-ami ## Check whether the AMIs have been updated and fail if they have. Designed for a automated test
@git diff --exit-code pkg/ami/static_resolver_ami.go > /dev/null || (git --no-pager diff; exit 1)

##@ Docker

.PHONY: eksctl-build-image
eksctl-build-image:
eksctl-build-image: ## Create the the eksctl build docker image
@-docker pull $(EKSCTL_BUILD_IMAGE)
@docker build --tag=$(EKSCTL_BUILD_IMAGE) --cache-from=$(EKSCTL_BUILD_IMAGE) ./build

Expand All @@ -65,11 +85,13 @@ EKSCTL_IMAGE_BUILD_ARGS += --build-arg=COVERALLS_TOKEN=$(COVERALLS_TOKEN)
endif

.PHONY: eksctl-image
eksctl-image: eksctl-build-image
eksctl-image: eksctl-build-image ## Create the eksctl image
@docker build --tag=$(EKSCTL_IMAGE) $(EKSCTL_IMAGE_BUILD_ARGS) ./

##@ Release

.PHONY: release
release: eksctl-build-image
release: eksctl-build-image ## Create a new eksctl release
@docker run \
--env=GITHUB_TOKEN \
--env=CIRCLE_TAG \
Expand All @@ -85,12 +107,20 @@ JEKYLL := docker run --tty --rm \
--publish="4000:4000" \
starefossen/github-pages

##@ Site

.PHONY: server-pages
serve-pages:
serve-pages: ## Serve the site locally
@-docker rm -f eksctl-jekyll
@$(JEKYLL) jekyll serve -d /_site --watch --force_polling -H 0.0.0.0 -P 4000

.PHONY: build-page
build-pages:
build-pages: ## Generate the site using jekyll
@-docker rm -f eksctl-jekyll
@$(JEKYLL) jekyll build --verbose

##@ Utility

.PHONY: help
help: ## Display this help. Thanks to https://suva.sh/posts/well-documented-makefiles/
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
131 changes: 131 additions & 0 deletions pkg/ami/generate/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions pkg/ami/static_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,10 @@ import (
"fmt"

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/weaveworks/eksctl/pkg/eks/api"
"github.com/weaveworks/eksctl/pkg/utils"
)

// TODO: This file will be go generated in the future
// https://github.com/weaveworks/eksctl/issues/49

// StaticImages is a map of images in each region by
// image OS family and by class
var StaticImages = map[string]map[int]map[string]string{
ImageFamilyAmazonLinux2: {
ImageClassGeneral: {
api.EKS_REGION_US_WEST_2: "ami-0a54c984b9f908c81",
api.EKS_REGION_US_EAST_1: "ami-0440e4f6b9713faf6",
api.EKS_REGION_EU_WEST_1: "ami-0c7a4976cb6fafd3a",
},
ImageClassGPU: {
api.EKS_REGION_US_WEST_2: "ami-0731694d53ef9604b",
api.EKS_REGION_US_EAST_1: "ami-058bfb8c236caae89",
api.EKS_REGION_EU_WEST_1: "ami-0706dc8a5eed2eed9",
},
},
}
//go:generate go run generate/main.go

// StaticDefaultResolver resolves the AMI to the defaults for the region
type StaticDefaultResolver struct {
Expand Down
21 changes: 21 additions & 0 deletions pkg/ami/static_resolver_ami.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78209ca

Please sign in to comment.