Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to go 1.22 and use version from go.mod #214

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Install Golang
uses: actions/setup-go@v5
with:
go-version: '1.20.x'
go-version-file: 'go.mod'
- name: run make lint
run: make lint
- name: run make build-linux
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
.idea/
cover.out
golangci-lint
golangci-lint
.DS_Store
1 change: 1 addition & 0 deletions .moia-mk.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.15.0
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/moia-dev/aws-apigateway-exporter

go 1.20
go 1.22

require (
github.com/aws/aws-sdk-go v1.51.32
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand All @@ -28,7 +30,9 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand All @@ -43,4 +47,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
88 changes: 88 additions & 0 deletions mk-templates/assets/ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "An ECR repository"
Parameters:
RepositoryName:
Type: String
Description: Name of the ECR repository.
Resources:
Repository:
Type: "AWS::ECR::Repository"
Properties:
RepositoryName: !Ref "RepositoryName"
ImageScanningConfiguration:
scanOnPush: true
LifecyclePolicy:
LifecyclePolicyText: |
{
"rules": [
{
"rulePriority": 1,
"description": "Keep at minimum 50 prd images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["prd"],
"countType": "imageCountMoreThan",
"countNumber": 50
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 2,
"description": "Keep at minimum 50 int images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["int"],
"countType": "imageCountMoreThan",
"countNumber": 50
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 3,
"description": "Keep at minimum 50 dev images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["dev"],
"countType": "imageCountMoreThan",
"countNumber": 50
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 4,
"description": "Keep only 200 images, expire all others (except those marked with dev, int, prd)",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 200
},
"action": {
"type": "expire"
}
}
]
}
RepositoryPolicyText:
Version: "2012-10-17"
Statement:
- Sid: allowK8s
Effect: Allow
Principal:
AWS:
- "*"
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
Condition:
ForAnyValue:StringLike:
aws:PrincipalOrgPaths:
- "o-h4a0f4tabz/r-xg0k/ou-xg0k-29qckrwr/*"
- "o-h4a0f4tabz/r-xg0k/ou-xg0k-4hgab4ao/*"
16 changes: 3 additions & 13 deletions mk-templates/assets/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# https://github.com/golangci/golangci/wiki/Configuration
service:
# use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.49.x
golangci-lint-version: 1.54.x

run:
# golang-ci lint runtime timeout
deadline: 5m
# moias latest supported Go version
go: "1.20"
go: "1.22"
# see: https://golangci-lint.run/usage/configuration/
modules-download-mode: vendor
modules-download-mode: readonly
# include test files or not.
tests: false

Expand All @@ -26,8 +26,6 @@ linters:
- whitespace
# godot checks if all top-level comments contain a period at the end of the last sentence if needed.
- godot
# depguard to make sure import paths specific are required
- depguard
# gocyclo calculates cyclomatic complexities of functions in Go source code.
- gocyclo
# gosec inspects source code for security problems by scanning the Go AST.
Expand All @@ -47,14 +45,6 @@ issues:
- errcheck

linters-settings:
# depguard settings
depguard:
list-type: blacklist
include-go-root: true
# error on the following import paths:
packages-with-error-message:
- github.com/stretchr/testify/assert: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
- github.com/pkg/errors: "Use fmt or errors instead of github.com/pkg/errors"
# gofumpt settings
gofumpt:
extra-rules: true
Expand Down
39 changes: 39 additions & 0 deletions mk-templates/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This make target makes environment variables mandatory

ssm-get = $(shell aws ssm get-parameter --name '$(1)' --with-decryption --region '$(AWS_REGION)' --query 'Parameter.Value' --output text)

aws-vpc-link-id = $(shell aws apigateway get-vpc-links | jq '.items[] | select(.name == "$(MOIA_ENVIRONMENT)-inlb-link") | .id')

# To properly use this, you need to add guard-{YOUR_ENV_VAR} as a dependency
# to your make target.
# Example:
# Consider you want to make MOIA_ENVIRONMENT mandatory for your deploy make
# target. You then need to add the following line to your deploy target:
# deploy: guard-MOIA_ENVIRONMENT
# ...
#
# There is also a special case for MOIA_ENVIRONMENT. If we have a kubernetes
# context, we check if the name of environment in the cluster name is the same
# otherwise we abort as well, because the wrong env will probably be applied in
# the wrong cluster
guard-%:
@if [ $* = "MOIA_ENVIRONMENT" ]; then \
if [ -x "$$(command -v kubectl)" ]; then \
cluster="$$(kubectl cluster-info 2>/dev/null | head -n1 | awk '{print $$NF}' | sed $$'s,\x1b\\[[0-9;]*[a-zA-Z],,g')"; \
env="$$(echo "$$cluster" | sed 's/^https\:\/\/api\.cluster\.trip\.\([a-z][a-z]*\)\.moia\-group\.io$$/\1/')"; \
if [ -n "$$cluster" ] && [ -z "$$env" ]; then \
echo "Couldn't determine the environment from the cluster URL: $$cluster"; \
exit 2; \
fi; \
if [ "$$env" = "poc" ] || [ "$$env" = "dev" ] || [ "$$env" = "int" ] || [ "$$env" = "prd" ]; then \
if [ "$$env" != "$$MOIA_ENVIRONMENT" ]; then \
echo "Cluster name is $$cluster, but MOIA_ENVIRONMENT is $$MOIA_ENVIRONMENT. Aborting..."; \
exit 1; \
fi \
fi \
fi \
fi; \
if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
7 changes: 5 additions & 2 deletions mk-templates/docker.mk
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(SELF_DIR)/common.mk

DOCKER_REGISTRY ?= 614608043005.dkr.ecr.eu-central-1.amazonaws.com
DOCKER_IMAGE_TAG ?= latest
DOCKER_FILE ?= Dockerfile
DOCKER_AWS_REGION ?= eu-central-1

.PHONY: docker-build
docker-build:
docker-build: guard-SERVICE guard-DOCKER_REGISTRY
docker build --no-cache -t $(DOCKER_REGISTRY)/$(SERVICE):$(DOCKER_IMAGE_TAG) -f $(DOCKER_FILE) .

.PHONY: push-image
push-image: docker-build
push-image: guard-SERVICE guard-DOCKER_REGISTRY docker-build
aws ecr get-login-password --region $(DOCKER_AWS_REGION) | docker login --username AWS --password-stdin $(DOCKER_REGISTRY)
docker push $(DOCKER_REGISTRY)/$(SERVICE):$(DOCKER_IMAGE_TAG)
14 changes: 14 additions & 0 deletions mk-templates/ecr.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(SELF_DIR)/common.mk

AWS_REGION ?= eu-central-1

.PHONY: ecr
ecr: guard-SERVICE guard-AWS_REGION
ecr: ${SELF_DIR}/assets/ecr.yml
aws cloudformation deploy \
--no-fail-on-empty-changeset \
--template-file $< \
--stack-name $(SERVICE)-ecr \
--parameter-overrides RepositoryName=$(SERVICE) \
--region $(AWS_REGION)
34 changes: 34 additions & 0 deletions mk-templates/github.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# this makefile can be used to create a Github Release in a repository, with all binaries for
# linux and darwin as seperate applications
GITHUB_OWNER = moia-dev
GITHUB_REPOSITORY = $(shell basename `git rev-parse --show-toplevel`)

ifdef GIT_VERSION
VERSION = ${GIT_VERSION}
else
VERSION = $(shell git describe --always --tags --dirty)
endif

# we need to do some magic here, because importing this will not work when we are not
# in this folder, e.g. from ../ the include will fail-- make is not smart.
#
# the last word of the MAKEFILE_LIST is the current makefile, so we can take that
# and append it to the include directory so that it will always be accurate
#
# not that you cannot use make -f with this approach, and must run the make targets
# in the same directory as the Makefile
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(SELF_DIR)/common.mk

.PHONY: release-dependencies
release-dependencies:
go get -u github.com/aktau/github-release

.PHONY: release
release: guard-VERSION release-dependencies
$(if $(GITHUB_TOKEN),,$(eval GITHUB_TOKEN=$(call ssm-get,/Github/ApiToken)))
github-release info --user $(GITHUB_OWNER) --repo $(GITHUB_REPOSITORY) -s $(GITHUB_TOKEN)
github-release release --user $(GITHUB_OWNER) --repo $(GITHUB_REPOSITORY) --tag $(VERSION) --name $(VERSION) -s $(GITHUB_TOKEN)
for f in bin/linux_amd64/*; do github-release upload --user $(GITHUB_OWNER) --repo $(GITHUB_REPOSITORY) -s $(GITHUB_TOKEN) --tag $(VERSION) --name `basename $${f}`_linux_amd64 --file $${f}; done
for f in bin/darwin_amd64/*; do github-release upload --user $(GITHUB_OWNER) --repo $(GITHUB_REPOSITORY) -s $(GITHUB_TOKEN) --tag $(VERSION) --name `basename $${f}`_darwin_amd64 --file $${f}; done
github-release edit --user $(GITHUB_OWNER) --repo $(GITHUB_REPOSITORY) -s $(GITHUB_TOKEN) --tag $(VERSION) --name $(VERSION) --description $(VERSION)
10 changes: 8 additions & 2 deletions mk-templates/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ SYSTEM := $(shell uname -s | tr A-Z a-z)_$(shell uname -m | sed "
GO_PREFIX := CGO_ENABLED=0 GOFLAGS=-mod=vendor GOPRIVATE=github.com/moia-dev
GO := $(GO_PREFIX) go
# This collects every path, which contains go files in the current project
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LINT_TARGETS := $(shell find -name '*.go' | sed -e "s|\(.*\)/.*\.go\$$|\1/...|g" | grep -v vendor | grep -v node_modules | uniq)
endif
ifeq ($(UNAME_S),Darwin)
LINT_TARGETS := $(shell find . -name '*.go' | sed -e "s|\(.*\)/.*\.go\$$|\1/...|g" | grep -v vendor | grep -v node_modules | uniq)
endif
# The current version of golangci-lint.
# See: https://github.com/golangci/golangci-lint/releases
GOLANGCI_LINT_VERSION ?= 1.51.2
GOLANGCI_LINT_VERSION ?= 1.56.2

# Executes the linter on all our go files inside of the project
.PHONY: lint create-golint-config
lint: bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
$(GO_PREFIX) ./bin/golangci-lint-$(GOLANGCI_LINT_VERSION) --timeout 120s run $(LINT_TARGETS)
$(GO_PREFIX) ./bin/golangci-lint-$(GOLANGCI_LINT_VERSION) --timeout 240s run $(LINT_TARGETS)

.PHONY: create-golint-config
create-golint-config:
Expand Down
15 changes: 15 additions & 0 deletions mk-templates/jsonnet.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SYSTEM := $(shell uname -s | tr A-Z a-z)_$(shell uname -m | sed "s/x86_64/amd64/")
# The current version of the jsonnet-bundler
# See: https://github.com/jsonnet-bundler/jsonnet-bundler/releases
JB_VERSION := 0.4.0

.PHONY: bin/jb
bin/jb: bin/jb-$(JB_VERSION)

# Downloads the current jsonnet-bundler executable into the bin directory and
# makes it executable
bin/jb-$(JB_VERSION):
mkdir -p bin
curl -sSLf \
https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v$(JB_VERSION)/jb-$(shell echo $(SYSTEM) | tr '_' '-') \
-o $@ && chmod +x $@ && ln -s $@ bin/jb