Skip to content

Commit

Permalink
Merge pull request #12 from 9seconds/ci-docker
Browse files Browse the repository at this point in the history
Updates for dockerfile
  • Loading branch information
9seconds committed Feb 19, 2021
2 parents 773a869 + 717f2c6 commit 808238f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github/
.bin/
topographer
*.md
LICENSE
Dockerfile
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

FROM golang:1.15-alpine AS build-env

ENV CGO_ENABLED=0

RUN set -x \
&& apk --update add git make
&& apk --update add \
ca-certificates \
git \
make

ADD . /go/src/github.com/9seconds/topographer
WORKDIR /go/src/github.com/9seconds/topographer
ADD . /app
WORKDIR /app

RUN set -x \
&& make clean \
Expand All @@ -23,18 +28,18 @@ RUN set -x \
###############################################################################
# PACKAGE STAGE

FROM alpine:latest
FROM scratch

ENTRYPOINT ["/topographer"]
CMD ["-config", "/config.hjson"]
EXPOSE 80

RUN set -x \
&& apk add --no-cache --update ca-certificates

COPY --from=build-env \
/go/src/github.com/9seconds/topographer/topographer \
/etc/ssl/certs/ca-certificates.crt \
/etc/ssl/certs/ca-certificates.crt
COPY --from=build-env \
/app/topographer \
/topographer
COPY --from=build-env \
/go/src/github.com/9seconds/topographer/example.config.hjson \
/app/example.config.hjson \
/config.hjson
30 changes: 24 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
IMAGE_NAME := topographer
APP_NAME := topographer
IMAGE_NAME := $(APP_NAME)

CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")

GOLANGCI_LINT_VERSION := v1.37.0

VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru)
VERSION_TAG := $(shell git describe --tags --always)
VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru)
VERSION_TAG := $(shell git describe --tags --always)
STATIC_BUILD_FLAGS := -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"

GOBIN := $(ROOT_DIR)/.bin
GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
Expand All @@ -16,11 +20,22 @@ GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
all: build

.PHONY: build
@go build -mod=readonly
@go build -mod=readonly -o "$(APP_NAME)"

.PHONY: static-build
static-build:
@go build -mod=readonly -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
@go build -mod=readonly $(STATIC_BUILD_FLAGS) -o "$(APP_NAME)"

$(APP_NAME)-%: GOOS=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f1 -d-)
$(APP_NAME)-%: GOARCH=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f2 -d-)
$(APP_NAME)-%: ccbuilds
@env "GOOS=$(GOOS)" "GOARCH=$(GOARCH)" \
go build \
$(COMMON_BUILD_FLAGS) \
-o "./ccbuilds/$(APP_NAME)-$(GOOS)-$(GOARCH)"

ccbuilds:
@rm -rf ./ccbuilds && mkdir -p ./ccbuilds

.PHONY: test
test:
Expand All @@ -30,6 +45,9 @@ test:
citest:
@go test -coverprofile=coverage.txt -covermode=atomic -race -v ./...

.PHONY: crosscompile
crosscompile: $(CC_BINARIES)

.PHONY: clean
clean:
@git clean -xfd && \
Expand Down

0 comments on commit 808238f

Please sign in to comment.