Skip to content

Commit

Permalink
Vc/multistage build (#96)
Browse files Browse the repository at this point in the history
* make the build more flexible

* add curl to the base image for debugging connectivity
  • Loading branch information
DoctorVin authored Sep 20, 2023
1 parent 861fe84 commit 521dce9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM alpine:3.18.0
RUN apk -U add curl

ENTRYPOINT ["/usr/sbin/conditionorc"]

Expand Down
38 changes: 38 additions & 0 deletions Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM golang:1.21.1-alpine3.18 AS deps

WORKDIR /go/src/github.com/metal-toolbox/conditionorc
COPY go.mod go.sum ./
RUN go mod download
WORKDIR /go
COPY pkg ./pkg

FROM deps AS builder
WORKDIR /go/src/github.com/metal-toolbox/conditionorc
ARG LDFLAG_LOCATION=github.com/metal-toolbox/conditionorc/internal/version
ARG GIT_COMMIT
ARG GIT_BRANCH
ARG GIT_SUMMARY
ARG VERSION
ARG BUILD_DATE

COPY main.go ./
COPY cmd ./cmd/
COPY internal ./internal
COPY pkg ./pkg

RUN GOOS=linux GOARCH=amd64 go build -o /bin/conditionorc \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
-X ${LDFLAG_LOCATION}.GitSummary=${GIT_SUMMARY} \
-X ${LDFLAG_LOCATION}.AppVersion=${VERSION} \
-X ${LDFLAG_LOCATION}.BuildDate=${BUILD_DATE}"

FROM alpine:3.18.0
RUN apk -U add curl

WORKDIR /usr/sbin/

COPY --from=builder --chmod=755 /bin/conditionorc .

ENTRYPOINT ["/usr/sbin/conditionorc"]
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ VERSION := $(shell git describe --tags 2> /dev/null)
BUILD_DATE := $(shell date +%s)
GIT_COMMIT_FULL := $(shell git rev-parse HEAD)
GO_VERSION := $(shell expr `go version |cut -d ' ' -f3 |cut -d. -f2` \>= 16)
DOCKER_IMAGE := "ghcr.io/metal-toolbox/conditionorc"
DOCKER_IMAGE ?= "ghcr.io/metal-toolbox/conditionorc"
REPO := "https://github.com/metal-toolbox/conditionorc.git"

.DEFAULT_GOAL := help
Expand Down Expand Up @@ -84,6 +84,14 @@ ifndef SWAG_INSTALLED
endif
swag init --parseDependency --parseDepth 1

# experimental
multistage-image:
docker build -f Dockerfile.builder -t ${DOCKER_IMAGE}:latest . \
--build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg GIT_SUMMARY=$(GIT_SUMMARY) --build-arg VERSION=$(VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) --label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) --label=org.label-schema.vcs-url=$(REPO)


# https://gist.github.com/prwhite/8168133
# COLORS
Expand Down

0 comments on commit 521dce9

Please sign in to comment.