Skip to content

Commit

Permalink
Version display on unleash index (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starefossen authored Sep 25, 2023
1 parent 4f640e0 commit eca002a
Show file tree
Hide file tree
Showing 15 changed files with 2,173 additions and 89 deletions.
9 changes: 9 additions & 0 deletions .dockerfileignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.*
.*/
bin/
charts/
hack/
tmp/
CODEOWNERS
Dockerfile
flake.*
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ updates:
directory: "/"
schedule:
interval: "monthly"
groups:
actions:
patterns:
- "*"
- package-ecosystem: "docker"
directory: "/"
schedule:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,51 @@ jobs:
- id: name
run: echo "name=${{ github.event.repository.name }}" >> ${GITHUB_OUTPUT}

lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: "1.21"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m

build:
name: Build and Test code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore cached binaries
uses: actions/cache/restore@v3
with:
path: ${{ github.workspace }}/bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile', 'go.mod') }}
- name: Set up Go environment
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Install make
run: sudo apt-get update && sudo apt-get install make
- run: make fmt
- run: make vet
- run: make check
- run: make test
- run: make build
- name: Cache installed binaries
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile', 'go.mod') }}

build_and_push:
name: Build and push
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang 1.20.7
golang 1.21.1
45 changes: 27 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
FROM golang:1.20-alpine as builder
RUN apk add --no-cache git make curl build-base
ENV GOOS=linux
# Build the bifrost binary
FROM golang:1.21 as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /src

COPY go.mod ./
COPY go.sum ./
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

COPY . ./
RUN make test
RUN make check
RUN make alpine
# Copy the go source
COPY . .

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o bifrost main.go

# Use distroless as minimal base image to package the bifrost binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/bifrost .
USER 65532:65532

FROM alpine:3.18
RUN apk add --no-cache ca-certificates tzdata
RUN export PATH=$PATH:/app
WORKDIR /app
COPY --from=builder /src/bin/bifrost /app/bifrost
COPY --from=builder /src/templates /app/templates
CMD ["/app/bifrost"]
ENTRYPOINT ["/bifrost"]
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ LAST_COMMIT = $(shell git rev-parse --short HEAD)
LDFLAGS := -X github.com/nais/bifrost/pkg/version.Revision=$(LAST_COMMIT) -X github.com/nais/bifrost/pkg/version.Date=$(DATE) -X github.com/nais/bifrost/pkg/version.BuildUnixTime=$(BUILDTIME)

.PHONY: all
all: fmt check test bifrost
all: fmt lint vet check test build

.PHONY: bifrost
bifrost:
.PHONY: build
build:
go build -o bin/bifrost -ldflags "-s $(LDFLAGS)" .

.PHONY: test
Expand All @@ -25,15 +25,19 @@ start:
fmt: gofumpt
$(GOFUMPT) -w ./

.PHONY: lint
lint: golangci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: check
check: staticcheck govulncheck
$(STATICCHECK) ./...
$(GOVULNCHECK) ./...

.PHONY: alpine
alpine:
go build -a -installsuffix cgo -o bin/bifrost -ldflags "-s $(LDFLAGS)" .

.PHONY: docker
docker:
docker build -t ${IMG} .
Expand All @@ -47,6 +51,7 @@ $(LOCALBIN):
GOVULNCHECK ?= $(LOCALBIN)/govulncheck
STATICCHECK ?= $(LOCALBIN)/staticcheck
GOFUMPT ?= $(LOCALBIN)/gofumpt
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

.PHONY: govulncheck
govulncheck: $(GOVULNCHECK) ## Download govulncheck locally if necessary.
Expand All @@ -62,3 +67,8 @@ $(STATICCHECK): $(LOCALBIN)
gofumpt: $(GOFUMPT) ## Download gofumpt locally if necessary.
$(GOFUMPT): $(LOCALBIN)
test -s $(LOCALBIN)/gofumpt || GOBIN=$(LOCALBIN) go install mvdan.cc/gofumpt@latest

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint
Loading

0 comments on commit eca002a

Please sign in to comment.