Skip to content

Commit

Permalink
Get rid off builder image. (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Aug 18, 2023
1 parent 1c47752 commit ebb12b0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,28 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go 1.21
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'

- name: generate proto and lint
working-directory: proto
run: make protoc
go-version-file: 'go.mod'
cache: false

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
args: --build-tags integration -p bugs -p unused --timeout=3m
args: --build-tags integration -p bugs -p unused --timeout=5m

- name: Make tag
run: |
[ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true
- name: Build and push image
- name: Build
run: |
make release
- name: Push image
uses: docker/build-push-action@v4
with:
context: .
Expand All @@ -64,11 +65,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go 1.21
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
go-version-file: 'go.mod'

- name: Run integration tests
run: |
go test -tags=integration -timeout 600s -p 1 ./...
make test-integration
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
FROM metalstack/builder:latest as builder

FROM alpine:3.18
RUN apk -U add ca-certificates
COPY --from=builder /work/bin/metal-api /metal-api
COPY bin/metal-api /metal-api
CMD ["/metal-api"]
56 changes: 37 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
BINARY := metal-api
MAINMODULE := github.com/metal-stack/metal-api/cmd/metal-api
COMMONDIR := $(or ${COMMONDIR},../builder)
CGO_ENABLED := 1

SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
BUILDDATE := $(shell date --rfc-3339=seconds)
VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD))

MINI_LAB_KUBECONFIG := $(shell pwd)/../mini-lab/.kubeconfig

include $(COMMONDIR)/Makefile.inc
LINKMODE := -linkmode external -extldflags '-static -s -w' \
-X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'

.PHONY: release
release: protoc test build

.PHONY: build
build:
go build \
-tags 'osusergo netgo static_build' \
-ldflags \
"$(LINKMODE)" \
-o bin/metal-api \
github.com/metal-stack/metal-api/cmd/metal-api

md5sum bin/metal-api > bin/metal-api.md5

release:: spec check-diff all ;
bin/metal-api dump-swagger | jq -r -S 'walk(if type == "array" then sort_by(strings) else . end)' > spec/metal-api.json || { echo "jq >=1.6 required"; exit 1; }

.PHONY: spec
spec: all
bin/$(BINARY) dump-swagger | jq -r -S 'walk(if type == "array" then sort_by(strings) else . end)' > spec/metal-api.json || { echo "jq >=1.6 required"; exit 1; }
.PHONY: test
test: test-unit check-diff

.PHONY: test-unit
test-unit:
go test -race -cover ./...

.PHONY: test-integration
test-integration:
go test -tags=integration -timeout 600s -p 1 ./...

.PHONY: check-diff
check-diff: spec
git diff --exit-code spec pkg

.PHONY: redoc
redoc:
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/work -w /work letsdeal/redoc-cli bundle -o generate/index.html /work/spec/metal-api.json
xdg-open generate/index.html

.PHONY: protoc
protoc:
rm -rf pkg/api/v1
make -C proto protoc

.PHONY: protoc-docker
protoc-docker:
rm -rf pkg/api/v1
docker pull bufbuild/buf:1.14.0
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/work --tmpfs /.cache -w /work/proto bufbuild/buf:1.14.0 generate -v

.PHONY: mini-lab-push
mini-lab-push:
make
Expand Down
4 changes: 2 additions & 2 deletions proto/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAKEFLAGS += --no-print-directory
BUF_VERSION := 1.23.1
BUF_VERSION := 1.26.1

_buf:
docker run --rm \
Expand All @@ -16,4 +16,4 @@ protolint:

.PHONY: protoc
protoc: protolint
@$(MAKE) _buf CMD="generate -v"
@$(MAKE) _buf CMD="generate -v"

0 comments on commit ebb12b0

Please sign in to comment.