Add Makefile and Dockerfiles for distribution
This commit is contained in:
parent
7ee081f9f0
commit
1a89933feb
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
tags
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,4 +14,5 @@
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
tag-checker
|
||||
tag-checker-*
|
||||
|
21
.pre-commit-config.yaml
Normal file
21
.pre-commit-config.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.4.0
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-merge-conflict
|
||||
- repo: git://github.com/dnephin/pre-commit-golang
|
||||
rev: v0.3.5
|
||||
hooks:
|
||||
- id: go-fmt
|
||||
- id: go-imports
|
||||
# - id: gometalinter
|
||||
# - id: golangci-lint
|
||||
- repo: https://github.com/IamTheFij/docker-pre-commit
|
||||
rev: v2.0.0
|
||||
hooks:
|
||||
- id: docker-compose-check
|
||||
- id: hadolint-system
|
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@ -0,0 +1,10 @@
|
||||
FROM alpine:latest as certs
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
FROM scratch
|
||||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
ARG ARCH=amd64
|
||||
COPY ./tag-checker-linux-${ARCH} /tag-checker
|
||||
|
||||
ENTRYPOINT [ "/tag-checker" ]
|
27
Dockerfile.multi-stage
Normal file
27
Dockerfile.multi-stage
Normal file
@ -0,0 +1,27 @@
|
||||
ARG REPO=library
|
||||
FROM golang:1.15-alpine AS builder
|
||||
|
||||
# hadolint ignore=DL3018
|
||||
RUN apk add --no-cache git
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./go.mod ./go.sum /app/
|
||||
RUN go mod download
|
||||
|
||||
COPY ./main.go /app/
|
||||
|
||||
ARG ARCH=amd64
|
||||
ARG VERSION=dev
|
||||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
|
||||
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o tag-checker .
|
||||
|
||||
FROM alpine:latest as certs
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
FROM scratch
|
||||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /app/tag-checker /
|
||||
|
||||
ENTRYPOINT [ "/tag-checker" ]
|
131
Makefile
Normal file
131
Makefile
Normal file
@ -0,0 +1,131 @@
|
||||
OUTPUT ?= tag-checker
|
||||
DOCKER_TAG ?= $(OUTPUT)-dev-${USER}
|
||||
GIT_TAG_NAME := $(shell git tag -l --contains HEAD)
|
||||
GIT_SHA := $(shell git rev-parse HEAD)
|
||||
VERSION := $(if $(GIT_TAG_NAME),$(GIT_TAG_NAME),$(GIT_SHA))
|
||||
|
||||
GOFILES = *.go go.mod go.sum
|
||||
|
||||
.PHONY: default
|
||||
default: build
|
||||
|
||||
.PHONY: all
|
||||
all: check test itest
|
||||
|
||||
# Downloads dependencies into vendor directory
|
||||
vendor: $(GOFILES)
|
||||
go mod vendor
|
||||
|
||||
# Runs the application, useful while developing
|
||||
.PHONY: run
|
||||
run:
|
||||
go run .
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -coverprofile=coverage.out
|
||||
go tool cover -func=coverage.out
|
||||
@go tool cover -func=coverage.out | awk -v target=75.0% \
|
||||
'/^total:/ { print "Total coverage: " $$3 " Minimum coverage: " target; if ($$3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }'
|
||||
|
||||
# Installs pre-commit hooks
|
||||
.PHONY: install-hooks
|
||||
install-hooks:
|
||||
pre-commit install --install-hooks
|
||||
|
||||
# Runs pre-commit checks on files
|
||||
.PHONY: check
|
||||
check:
|
||||
pre-commit run --all-files
|
||||
|
||||
# Output target
|
||||
$(OUTPUT): $(GOFILES)
|
||||
@echo Version: $(VERSION)
|
||||
go build -ldflags '-X "main.version=${VERSION}"' -o $(OUTPUT)
|
||||
|
||||
# Alias for building
|
||||
.PHONY: build
|
||||
build: $(OUTPUT)
|
||||
|
||||
$(OUTPUT)-darwin-amd64: $(GOFILES)
|
||||
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
|
||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
||||
-o $(OUTPUT)-darwin-amd64
|
||||
|
||||
$(OUTPUT)-linux-amd64: $(GOFILES)
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
|
||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
||||
-o $(OUTPUT)-linux-amd64
|
||||
|
||||
$(OUTPUT)-linux-arm: $(GOFILES)
|
||||
GOOS=linux GOARCH=arm CGO_ENABLED=0 \
|
||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
||||
-o $(OUTPUT)-linux-arm
|
||||
|
||||
$(OUTPUT)-linux-arm64: $(GOFILES)
|
||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
|
||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
||||
-o $(OUTPUT)-linux-arm64
|
||||
|
||||
.PHONY: build-linux-static
|
||||
build-linux-static: $(OUTPUT)-linux-amd64 $(OUTPUT)-linux-arm $(OUTPUT)-linux-arm64
|
||||
|
||||
.PHONY: build-all-static
|
||||
build-all-static: $(OUTPUT)-darwin-amd64 build-linux-static
|
||||
|
||||
# Cleans all build artifacts
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(OUTPUT)
|
||||
rm -f $(OUTPUT)-linux-*
|
||||
|
||||
# Cleans vendor directory
|
||||
.PHONY: clean-vendor
|
||||
clean-vendor:
|
||||
rm -fr ./vendor
|
||||
|
||||
.PHONY: docker-build
|
||||
docker-build: $(OUTPUT)-linux-amd64
|
||||
docker build . -t ${DOCKER_TAG}-linux-amd64
|
||||
|
||||
# Cross build for arm architechtures
|
||||
.PHONY: docker-build-arm
|
||||
docker-build-arm: $(OUTPUT)-linux-arm
|
||||
docker build --build-arg REPO=arm32v7 --build-arg ARCH=arm . -t ${DOCKER_TAG}-linux-arm
|
||||
|
||||
.PHONY: docker-build-arm
|
||||
docker-build-arm64: $(OUTPUT)-linux-arm64
|
||||
docker build --build-arg REPO=arm64v8 --build-arg ARCH=arm64 . -t ${DOCKER_TAG}-linux-arm64
|
||||
|
||||
.PHONY: docker-run
|
||||
docker-run: docker-build
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-amd64
|
||||
|
||||
# Cross run on host architechture
|
||||
.PHONY: docker-run-arm
|
||||
docker-run-arm: docker-build-arm
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm
|
||||
|
||||
.PHONY: docker-run-arm64
|
||||
docker-run-arm64: docker-build-arm64
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm64
|
||||
|
||||
# Multi stage builds
|
||||
.PHONY: docker-staged-build
|
||||
docker-staged-build:
|
||||
docker build --build-arg VERSION=${VERSION} \
|
||||
-t ${DOCKER_TAG}-linux-amd64 \
|
||||
-f Dockerfile.multi-stage .
|
||||
|
||||
# Cross build for arm architechtures
|
||||
.PHONY: docker-staged-build-arm
|
||||
docker-staged-build-arm:
|
||||
docker build --build-arg VERSION=${VERSION} \
|
||||
--build-arg REPO=arm32v7 --build-arg ARCH=arm -t ${DOCKER_TAG}-linux-arm \
|
||||
-f Dockerfile.multi-stage .
|
||||
|
||||
.PHONY: docker-staged-build-arm
|
||||
docker-staged-build-arm64:
|
||||
docker build --build-arg VERSION=${VERSION} \
|
||||
--build-arg REPO=arm64v8 --build-arg ARCH=arm64 -t ${DOCKER_TAG}-linux-arm64 \
|
||||
-f Dockerfile.multi-stage .
|
Loading…
Reference in New Issue
Block a user