Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
version: 2.1
jobs:
test:
machine: true
steps:
- checkout

- run:
name: Build application Docker image
command: docker-compose build

- run:
name: Lint
command: |
make lint-in-docker

- run:
name: Test
command: |
make test-in-docker

deploy:
machine: true
steps:
- checkout

- run:
name: Setup system
command: |
docker login -u="$DOCKER_LOGIN" -p="$DOCKER_PASS" $DOCKER_SERVER
- run:
name: Build application Docker image
command: |
docker-compose build
- run:
name: Build static version and create target image
command: |
make build-in-docker docker

- run:
name: Install jinja2-cli
command: |
pip install jinja2-cli[yaml]
- run:
name: Install gcloud and kubectl
command: |
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update
sudo /opt/google-cloud-sdk/bin/gcloud --quiet components install kubectl
sudo chown circleci:circleci ~/.config/gcloud/ -R

- run:
name: Build and deploy
command: |
make decrypt

if [ "$CIRCLE_BRANCH" == "master" ]; then
echo $GCLOUD_STG_SERVICE_KEY > gcloud-service-key.json
gcloud auth activate-service-account --key-file=gcloud-service-key.json
gcloud container clusters get-credentials syncano-stg --zone europe-west1 --project syncano-staging

make deploy-staging

elif [ "$CIRCLE_BRANCH" == "stable" ]; then
echo $GCLOUD_EU1_SERVICE_KEY > gcloud-service-key.json
gcloud auth activate-service-account --key-file=gcloud-service-key.json
gcloud container clusters get-credentials syncano-eu1 --zone europe-west1 --project pioner-syncano-prod-9cfb

make deploy-production
fi

make clean

workflows:
test:
jobs:
- test:
filters:
branches:
ignore:
- master
- stable

deploy:
jobs:
- deploy:
filters:
branches:
only:
- master
- stable
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/---bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: "\U0001F41B Bug report"
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/---feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: "\U0001F680 Feature request"
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Additional context**
Add any other context or screenshots about the feature request here.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/build/acme*
/certs
coverage*.out
/dev/
/debug*
*.unenc
90 changes: 90 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
run:
timeout: 2m
tests: false
skip-dirs:
- assets
- dev
- proto
- mocks

issues:
exclude-rules:
- text: declaration of "err" shadows declaration
linters:
- govet

linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 20
maligned:
suggest-new: true
dupl:
threshold: 150
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- whyNoLint
- commentedOutCode

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exhaustive
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- wsl

# don't enable:
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - godox
# - gocognit
# - gomnd
# - lll
# - maligned
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.15
ARG EMAIL=devops@syncano.com
ENV GOPROXY=https://proxy.golang.org
WORKDIR /opt/build

COPY go.mod go.sum ./
RUN go mod download
104 changes: 104 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
ifndef DOCKERIMAGE
DOCKERIMAGE := syncano/acme-proxy
endif

CURRENTPACKAGE := github.com/Syncano/acme-proxy
EXECNAME := acme_proxy

PATH := $(PATH):$(GOPATH)/bin
GOFILES=$(shell find . -mindepth 2 -type f -name '*.go' ! -path "./.*" ! -path "./dev/*" ! -path "*/proto/*")
GOTESTPACKAGES = $(shell find . -mindepth 2 -type f -name '*.go' ! -path "./.*" ! -path "./internal/*" ! -path "./dev/*" ! -path "*/mocks/*" ! -path "*/proto/*" | xargs -n1 dirname | sort | uniq)

BUILDTIME = $(shell date +%Y-%m-%dT%H:%M)
GITSHA = $(shell git rev-parse --short HEAD)

LDFLAGS = -s -w \
-X github.com/Syncano/acme-proxy/app/version.GitSHA=$(GITSHA) \
-X github.com/Syncano/acme-proxy/app/version.buildtimeStr=$(BUILDTIME)


.PHONY: help clean lint fmt test stest cov goconvey lint-in-docker test-in-docker build build-in-docker docker deploy-staging deploy-production start migrate devserver run-server
.DEFAULT_GOAL := help
$(VERBOSE).SILENT:

help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

require-%:
if ! hash ${*} 2>/dev/null; then \
echo "! ${*} not installed"; \
exit 1; \
fi

clean: ## Cleanup repository
go clean ./...
rm -f build/$(EXECNAME)
find deploy -name "*.unenc" -delete
git clean -f

lint: ## Run lint checks
echo "=== lint ==="
if ! hash golangci-lint 2>/dev/null; then \
echo "Installing golangci-lint"; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $$(go env GOPATH)/bin v1.30.0; \
fi
golangci-lint run $(ARGS)

fmt: ## Format code through goimports
gofmt -s -w $(GOFILES)
go run golang.org/x/tools/cmd/goimports -local $(CURRENTPACKAGE) -w $(GOFILES)

test: ## Run unit with race check and create coverage profile
echo "=== unit test ==="
echo "mode: atomic" > coverage-all.out
$(foreach pkg,$(GOTESTPACKAGES),\
go test -timeout 5s -short -race -coverprofile=coverage.out -covermode=atomic $(ARGS) $(pkg) || exit;\
tail -n +2 coverage.out >> coverage-all.out 2>/dev/null;)

stest: ## Run only short tests (unit tests) without race check
echo "=== short test ==="
go test -timeout 5s -short $(ARGS) $(GOTESTPACKAGES)

cov: ## Show per function coverage generated by test
echo "=== coverage ==="
go tool cover -func=coverage-all.out

goconvey: ## Run goconvey test server
go run github.com/smartystreets/goconvey -excludedDirs "dev,internal,mocks,proto,assets,deploy,build" -timeout 5s -depth 2

lint-in-docker: require-docker-compose ## Run lint in docker environment
docker-compose run --no-deps --rm server make lint

test-in-docker: require-docker-compose ## Run full test suite in docker environment
docker-compose run --rm server make build test

build: ## Build
go build -ldflags "$(LDFLAGS)" -o ./build/$(EXECNAME)

build-in-docker: require-docker-compose ## Build in docker environment
docker-compose run --no-deps --rm -e CGO_ENABLED=0 server make build

docker: require-docker ## Builds docker image for application (requires static version to be built first)
docker build -t $(DOCKERIMAGE) build

deploy-staging: require-kubectl ## Deploy application to staging
echo "=== deploying staging ==="
kubectl config use-context gke_syncano-staging_europe-west1_syncano-stg
./deploy.sh --migration staging $(GITSHA) $(ARGS)

deploy-production: require-kubectl ## Deploy application to production
echo "=== deploying eu1 ==="
kubectl config use-context gke_pioner-syncano-prod-9cfb_europe-west1_syncano-eu1
./deploy.sh --migration eu1 $(GITSHA)

start: require-docker-compose ## Run docker-compose of an app
docker-compose -f docker-compose.yml -f build/docker-compose.yml up

migrate: ## Migrate SQL structure
go run . db up

devserver: ## Run devserver
SERVICE_NAME=acme-proxy DEBUG=1 FORCE_TERM=1 go run github.com/cespare/reflex --regex='\.go$$' --inverse-regex='_test\.go$$' --start-service -- go run . server

run-server: build ## Build and run server binary
./build/$(EXECNAME) $(ARGS) server
Loading