Browse Source

build: opt for cache using

build/docker
Evan 7 months ago
parent
commit
48ed45c2b4
  1. 2
      Dockerfile
  2. 6
      Makefile

2
Dockerfile

@ -18,6 +18,6 @@ RUN VERSION=$(git describe --tags)-$(git rev-parse --short HEAD) && \
-ldflags="-w -X 'github.com/mutsuki333/calendar/cmd.Version=${VERSION}' -X 'github.com/mutsuki333/calendar/services.Version=${VERSION}' -linkmode external -extldflags '-static'" \
-o /calendar main.go
FROM scratch
FROM scratch as release
COPY --from=backend /calendar .
CMD ["/calendar"]

6
Makefile

@ -1,5 +1,5 @@
VERSION=$(shell git describe --tags)
VERSION=$(shell git describe --tags --abbrev=0)
BUILD=$(shell git rev-parse --short HEAD)
PROJECTNAME := $(shell basename "$(PWD)")
@ -40,7 +40,9 @@ min:
go build -tags min $(LDFLAGS) -o $(GOBIN)/$(PROJECTNAME)-min $(GOFILES)
docker-build:
docker build -t $(PROJECTNAME) -t $(PROJECTNAME):$(VERSION) -t $(PROJECTNAME):$(VERSION)-$(BUILD) .
docker build --target backend --cache-from=$(PROJECTNAME):backend -t $(PROJECTNAME):backend .
docker build --target release --cache-from=$(PROJECTNAME):backend -t $(PROJECTNAME) -t $(PROJECTNAME):$(VERSION) .
# -t $(PROJECTNAME):$(VERSION)-$(BUILD) .
docker-run: docker-build
docker run -it --rm --name $(PROJECTNAME) -p 8080:8080 $(PROJECTNAME)