-
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.
- Loading branch information
Showing
10 changed files
with
209 additions
and
18 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
bin/ | ||
.idea/ | ||
cover.out | ||
golangci-lint | ||
golangci-lint | ||
.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 @@ | ||
v0.15.0 |
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,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/*" |
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
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,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 |
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,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) |
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,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) |
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,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) |
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
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,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 |