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

Keep moving messages using sqsmv #29

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env*
3 changes: 3 additions & 0 deletions .envs.sh.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
export SQSMV_AWS_ACCESS_KEY_ID="sample-aws-access-key-id"
export SQSMV_AWS_SECRET_ACCESS_KEY="sample-secret-access-key"
31 changes: 6 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
dist
/bin
/.go
/.push-*
/.container-*
/.dockerfile-*
.envs.sh
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: go
services:
- docker
script:
- make build
# - test -f bin/linux_amd64/sqsmv
# - make all-container
# - docker images | grep "^practodev/sqsmv"
# - make test
5 changes: 5 additions & 0 deletions Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM {ARG_FROM}

ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}

ENTRYPOINT ["/{ARG_BIN}", "run"]
262 changes: 205 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,205 @@
# command to build and run on the local OS.
GO_BUILD = go build

# command to compiling the distributable. Specify GOOS and GOARCH for
# the target OS.
GO_DIST = CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO_BUILD) -a -tags netgo -ldflags '-w'

APP = sqsmv
TMP_BUILD = tmp/$(APP)
DIST_DIR = dist

TAG ?= `git describe --tags | sed -e 's/^v//'`

.PHONY: dist

all: clean tools lint goimports vet dist

deps:
go get -t ./...

prepare:
mkdir -p build dist

tools:
go get golang.org/x/tools/cmd/goimports
go get golang.org/x/lint/golint

lint: golint vet goimports vet

vet:
go vet

golint:
ret=0 && test -z "$$(golint . | tee /dev/stderr)" || ret=1 ; exit $$ret

goimports:
ret=0 && test -z "$$(goimports -l . | tee /dev/stderr)" || ret=1 ; exit $$ret

dist: prepare dist-linux dist-darwin dist-windows

dist-linux:
GOOS=linux GOARCH=amd64 go build -o $(TMP_BUILD)
tar -C tmp -zcvf $(DIST_DIR)/$(APP)-$(TAG)-linux.gz $(APP)
rm $(TMP_BUILD)

dist-darwin:
GOOS=darwin GOARCH=amd64 go build -o $(TMP_BUILD)
tar -C tmp -zcvf $(DIST_DIR)/$(APP)-$(TAG)-darwin.gz $(APP)
rm $(TMP_BUILD)

dist-windows:
GOOS=windows GOARCH=amd64 go build -o $(TMP_BUILD)
tar -C tmp -zcvf $(DIST_DIR)/$(APP)-$(TAG)-windows.gz $(APP)
rm $(TMP_BUILD)

clean:
rm -rf build dist
# The binary to build (just the basename).
# This can be overwritten from command line using
BIN := sqsmv
KUBE_CONTEXT := ""

UNIQUE:=$(shell date +%s)

# Where to push the docker image.
REGISTRY := practodev

# This version-strategy uses git tags to set the version string
VERSION := $(shell git describe --tags --always --dirty)
#
# This version-strategy uses a manual value to set the version string
#VERSION := 1.2.3

###
### These variables should not need tweaking.
###

SRC_DIRS := cmd pkg # directories which hold app source (not vendored)

ALL_PLATFORMS := darwin/amd64 linux/amd64
# linux/arm linux/arm64 linux/ppc64le linux/s390x

# Used internally. Users should pass GOOS and/or GOARCH.
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))

BASEIMAGE ?= gcr.io/distroless/static

IMAGE := $(REGISTRY)/$(BIN)
TAG := $(VERSION)

BUILD_IMAGE ?= golang:1.13.7-alpine

# If you want to build all binaries, see the 'all-build' rule.
# If you want to build all containers, see the 'all-container' rule.
# If you want to build AND push all containers, see the 'all-push' rule.
all: build

# For the following OS/ARCH expansions, we transform OS/ARCH into OS_ARCH
# because make pattern rules don't match with embedded '/' characters.

build-%:
@$(MAKE) build \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))

container-%:
@$(MAKE) container \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))

push-%:
@$(MAKE) push \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))

all-build: $(addprefix build-, $(subst /,_, $(ALL_PLATFORMS)))

all-container: $(addprefix container-, $(subst /,_, $(ALL_PLATFORMS)))

all-push: $(addprefix push-, $(subst /,_, $(ALL_PLATFORMS)))

fmt:
@echo "formatting code"
/bin/sh -c "./hack/format.sh"

build: bin/$(OS)_$(ARCH)/$(BIN)

# Directories that we need created to build/test.
BUILD_DIRS := bin/$(OS)_$(ARCH) \
.go/bin/$(OS)_$(ARCH) \
.go/cache

# The following structure defeats Go's (intentional) behavior to always touch
# result files, even if they have not changed. This will still run `go` but
# will not trigger further work if nothing has actually changed.
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
$(OUTBIN): .go/$(OUTBIN).stamp
@true

# This will build the binary under ./.go and update the real binary iff needed.
.PHONY: .go/$(OUTBIN).stamp
.go/$(OUTBIN).stamp: $(BUILD_DIRS)
@echo "making $(OUTBIN)"
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/sh -c " \
ARCH=$(ARCH) \
OS=$(OS) \
VERSION=$(VERSION) \
./hack/build.sh \
"
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
mv .go/$(OUTBIN) $(OUTBIN); \
date >$@; \
fi

# Example: make shell CMD="-c 'date > datefile'"
shell: $(BUILD_DIRS)
@echo "launching a shell in the containerized build environment"
@docker run \
-ti \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/sh $(CMD)

# Used to track state in hidden files.
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)

container: .container-$(DOTFILE_IMAGE) say_container_name
.container-$(DOTFILE_IMAGE): bin/$(OS)_$(ARCH)/$(BIN) Dockerfile.in
@sed \
-e 's|{ARG_BIN}|$(BIN)|g' \
-e 's|{ARG_ARCH}|$(ARCH)|g' \
-e 's|{ARG_OS}|$(OS)|g' \
-e 's|{ARG_FROM}|$(BASEIMAGE)|g' \
Dockerfile.in > .dockerfile-$(OS)_$(ARCH)
@docker build -t $(IMAGE):$(TAG) -f .dockerfile-$(OS)_$(ARCH) .
@docker images -q $(IMAGE):$(TAG) > $@

say_container_name:
@echo "container: $(IMAGE):$(TAG)"

push: .push-$(DOTFILE_IMAGE) say_push_name
.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE)
@docker push $(IMAGE):$(TAG)

say_push_name:
@echo "pushed: $(IMAGE):$(TAG)"

manifest-list: push
platforms=$$(echo $(ALL_PLATFORMS) | sed 's/ /,/g'); \
manifest-tool \
--username=oauth2accesstoken \
--password=$$(gcloud auth print-access-token) \
push from-args \
--platforms "$$platforms" \
--template $(REGISTRY)/$(BIN):$(VERSION)__OS_ARCH \
--target $(REGISTRY)/$(BIN):$(VERSION)

version:
@echo $(VERSION)

test: $(BUILD_DIRS)
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/sh -c " \
ARCH=$(ARCH) \
OS=$(OS) \
VERSION=$(VERSION) \
./hack/test.sh $(SRC_DIRS) \
"

$(BUILD_DIRS):
@mkdir -p $@

clean: container-clean bin-clean

container-clean:
rm -rf .container-* .dockerfile-* .push-*

bin-clean:
rm -rf .go bin

deploy:
@echo "Creating kubernetes deployment at: ./artifacts/deployment.yaml"
@cp artifacts/deployment-template.yaml artifacts/deployment.yaml
VERSION=$(VERSION) ./hack/generate.sh artifacts/deployment.yaml
@kubectl --context=$(KUBE_CONTEXT) delete deploy -ncentral sqsmv
@kubectl --context=$(KUBE_CONTEXT) apply -f artifacts/deployment.yaml || @kubectl --context=$(KUBE_CONTEXT) create -f artifacts/deployment.yaml
@kubectl --context=$(KUBE_CONTEXT) get pods -n central | grep sqsmv
Loading