Skip to content

Commit

Permalink
Add Makefile and Dockerfile (#18)
Browse files Browse the repository at this point in the history
* Add Dockerfile

* Add Makefile and manage tools using bingo
  • Loading branch information
onprem committed Feb 4, 2021
1 parent dfcae69 commit 378889b
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .bingo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# Ignore everything
*

# But not these files:
!.gitignore
!*.mod
!README.md
!Variables.mk
!variables.env

*tmp.mod
14 changes: 14 additions & 0 deletions .bingo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Project Development Dependencies.

This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo.

* Run `bingo get` to install all tools having each own module file in this directory.
* Run `bingo get <tool>` to install <tool> that have own module file in this directory.
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod.
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool.
* For go: Import `.bingo/variables.go` to for variable names.
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies.

## Requirements

* Go 1.14+
31 changes: 31 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.3.1. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO ?= $(shell which go)

# Bellow generated variables ensure that every time a tool under each variable is invoked, the correct version
# will be used; reinstalling only if needed.
# For example for goimports variable:
#
# In your main Makefile (for non array binaries):
#
#include .bingo/Variables.mk # Assuming -dir was set to .bingo .
#
#command: $(GOIMPORTS)
# @echo "Running goimports"
# @$(GOIMPORTS) <flags/args..>
#
GOIMPORTS := $(GOBIN)/goimports-v0.1.0
$(GOIMPORTS): $(BINGO_DIR)/goimports.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/goimports-v0.1.0"
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=goimports.mod -o=$(GOBIN)/goimports-v0.1.0 "golang.org/x/tools/cmd/goimports"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.36.0
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.36.0"
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.36.0 "github.com/golangci/golangci-lint/cmd/golangci-lint"

1 change: 1 addition & 0 deletions .bingo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files.
5 changes: 5 additions & 0 deletions .bingo/goimports.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require golang.org/x/tools v0.1.0 // cmd/goimports
5 changes: 5 additions & 0 deletions .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/golangci/golangci-lint v1.36.0 // cmd/golangci-lint
14 changes: 14 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.3.1. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
GOBIN=${GOBIN:=$(go env GOBIN)}

if [ -z "$GOBIN" ]; then
GOBIN="$(go env GOPATH)/bin"
fi


GOIMPORTS="${GOBIN}/goimports-v0.1.0"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.36.0"

22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.15-alpine3.13 as builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build ./cmd/foundry

FROM archlinux:base-devel-20210124.0.14185

WORKDIR /app

COPY --from=builder /app/foundry .

EXPOSE 10201
EXPOSE 10200

ENTRYPOINT ["./foundry"]

66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
include .bingo/Variables.mk
FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)

GO111MODULE ?= on
export GO111MODULE

GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin

DOCKER_IMAGE_REPO ?= quay.io/prmsrswt/foundry
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short HEAD)

help: ## Displays help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

.PHONY: all
all: format build

.PHONY: build
build: ## Build foundry.
@echo ">> building foundry"
@go build ./cmd/foundry

.PHONY: install
install: ## Build and install foundry.
@echo ">> installing foundry"
@go install github.com/prmsrswt/foundry/cmd/foundry

.PHONY: deps
deps: ## Ensures fresh go.mod and go.sum.
@go mod tidy
@go mod verify

.PHONY: format
format: ## Formats Go code including imports.
format: $(GOIMPORTS)
@echo ">> formatting code"
@$(GOIMPORTS) -w $(FILES_TO_FMT)

.PHONY: test
test: ## Runs all Go unit tests.
@echo ">> running unit tests"
@go test -v -timeout=30m $(shell go list ./... | grep -v /vendor/)

.PHONY: coverage
coverage: ## Create test coverage profile
@echo ">> creating test coverage profile"
@go test -v -covermode=count -coverprofile=coverage.out $(shell go list ./... | grep -v /vendor/)

.PHONY: lint
lint: ## Runs various static analysis against our code.
lint: $(GOLANGCI_LINT) format deps
@echo ">> examining all of the Go files"
@go vet -stdmethods=false ./...
@echo ">> linting all of the Go files GOGC=${GOGC}"
@$(GOLANGCI_LINT) run

.PHONY: docker
docker: ## Build Docker image
@echo ">> building docker image 'foundry'"
@docker build -t foundry .

.PHONY: docker-push
docker-push: ## Pushes 'foundry' docker image to "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)".
@echo ">> pushing image"
@docker tag "foundry" "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)"
@docker push "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# `foundry`

[![Coverage Status](https://coveralls.io/repos/github/prmsrswt/foundry/badge.svg?branch=main)](https://coveralls.io/github/prmsrswt/foundry?branch=main)
[![Docker Repository on Quay](https://quay.io/repository/prmsrswt/foundry/status "Docker Repository on Quay")](https://quay.io/repository/prmsrswt/foundry)

## Overview

Expand Down
5 changes: 3 additions & 2 deletions pkg/furnace/furnacepb/furnace.pb.go

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

1 change: 1 addition & 0 deletions pkg/furnace/furnacepb/furnace_grpc.pb.go

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

0 comments on commit 378889b

Please sign in to comment.