Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build improvements #443

Merged
merged 1 commit into from Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/build.yaml
Expand Up @@ -36,18 +36,33 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Setup Environment
smoser marked this conversation as resolved.
Show resolved Hide resolved
run: |
gopath=$PWD/.build/gopath
echo "GOPATH=$gopath" >> $GITHUB_ENV
echo "GOCACHE=$gopath/gocache" >> $GITHUB_ENV
echo "PATH=$gopath/bin:$PATH" >> $GITHUB_ENV

echo "PWD=$PWD"
cat "$GITHUB_ENV"
- name: install dependencies
run: |
sudo add-apt-repository -y ppa:project-machine/squashfuse
sudo apt-get update
sudo apt-get install -yy lxc-utils lxc-dev libacl1-dev jq libcap-dev libseccomp-dev libpam-dev bats parallel libzstd-dev
GO111MODULE=off go get github.com/opencontainers/umoci/cmd/umoci
sudo cp ~/go/bin/umoci /usr/bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
sudo apt-get install -yy autoconf automake make autogen autoconf libtool binutils git squashfs-tools libcryptsetup-dev libdevmapper-dev cryptsetup-bin squashfuse
(cd /tmp && git clone https://github.com/AgentD/squashfs-tools-ng && cd squashfs-tools-ng && ./autogen.sh && ./configure --prefix=/usr && make -j2 && sudo make -j2 install && sudo ldconfig -v)
(cd /tmp && git clone https://github.com/anuvu/squashfs && cd squashfs && make && sudo cp squashtool/squashtool /usr/bin)
echo "running kernel is: $(uname -a)"
- name: Go-download
run: |
make go-download
- name: Build-level1
run: |
make show-info
make stacker-dynamic VERSION_FULL=${{ matrix.build-id }}
- name: Build
run: |
make stacker VERSION_FULL=${{ matrix.build-id }}
Expand Down
33 changes: 26 additions & 7 deletions Makefile
@@ -1,12 +1,17 @@
GO_SRC=$(shell find . -path ./.build -prune -false -o -name \*.go)
TOP_LEVEL := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
BUILD_D = $(TOP_LEVEL)/.build
export GOPATH = $(BUILD_D)/gopath
export GOCACHE = $(GOPATH)/gocache

GO_SRC=$(shell find pkg cmd -name \*.go)
VERSION?=$(shell git describe --tags || git rev-parse HEAD)
VERSION_FULL?=$(if $(shell git status --porcelain --untracked-files=no),$(VERSION)-dirty,$(VERSION))

LXC_VERSION?=$(shell pkg-config --modversion lxc)

BUILD_TAGS = exclude_graphdriver_btrfs exclude_graphdriver_devicemapper containers_image_openpgp osusergo netgo

STACKER_OPTS=--oci-dir=.build/oci --roots-dir=.build/roots --stacker-dir=.build/stacker --storage-type=overlay
STACKER_OPTS=--oci-dir=$(BUILD_D)/oci --roots-dir=$(BUILD_D)/roots --stacker-dir=$(BUILD_D)/stacker --storage-type=overlay

build_stacker = go build -tags "$(BUILD_TAGS) $1" -ldflags "-X main.version=$(VERSION_FULL) -X main.lxc_version=$(LXC_VERSION) $2" -o $3 ./cmd/stacker

Expand All @@ -17,31 +22,40 @@ STACKER_BUILD_UBUNTU_IMAGE?=$(STACKER_DOCKER_BASE)ubuntu:latest
LXC_CLONE_URL?=https://github.com/lxc/lxc
LXC_BRANCH?=stable-5.0

stacker: stacker-dynamic
./stacker-dynamic --debug $(STACKER_OPTS) build \
STAGE1_STACKER ?= ./stacker-dynamic

STACKER_DEPS = $(GO_SRC) go.mod go.sum

stacker: $(STAGE1_STACKER) $(STACKER_DEPS) cmd/stacker/lxc-wrapper/lxc-wrapper.c
$(STAGE1_STACKER) --debug $(STACKER_OPTS) build \
-f build.yaml --shell-fail \
--substitute STACKER_BUILD_BASE_IMAGE=$(STACKER_BUILD_BASE_IMAGE) \
--substitute LXC_CLONE_URL=$(LXC_CLONE_URL) \
--substitute LXC_BRANCH=$(LXC_BRANCH) \
--substitute VERSION_FULL=$(VERSION_FULL)

stacker-static: $(GO_SRC) go.mod go.sum cmd/stacker/lxc-wrapper/lxc-wrapper
stacker-static: $(STACKER_DEPS) cmd/stacker/lxc-wrapper/lxc-wrapper
$(call build_stacker,static_build,-extldflags '-static',stacker)

# TODO: because we clean lxc-wrapper in the nested build, this always rebuilds.
# Could find a better way to do this.
stacker-dynamic: $(GO_SRC) go.mod go.sum cmd/stacker/lxc-wrapper/lxc-wrapper
stacker-dynamic: $(STACKER_DEPS) cmd/stacker/lxc-wrapper/lxc-wrapper
$(call build_stacker,,,stacker-dynamic)

cmd/stacker/lxc-wrapper/lxc-wrapper: cmd/stacker/lxc-wrapper/lxc-wrapper.c
make -C cmd/stacker/lxc-wrapper LDFLAGS=-static LDLIBS="$(shell pkg-config --static --libs lxc) -lpthread -ldl" lxc-wrapper


.PHONY: go-download
go-download:
go mod download

.PHONY: lint
lint: cmd/stacker/lxc-wrapper/lxc-wrapper $(GO_SRC)
go mod tidy
go fmt ./... && ([ -z $(CI) ] || git diff --exit-code)
bash test/static-analysis.sh
go test -v -trimpath -cover -coverpkg ./... -coverprofile=coverage.txt -covermode=atomic -tags "$(BUILD_TAGS)" ./...
go test -v -trimpath -cover -coverpkg stackerbuild.io/stacker/./... -coverprofile=coverage.txt -covermode=atomic -tags "$(BUILD_TAGS)" stackerbuild.io/stacker/./...
$(shell go env GOPATH)/bin/golangci-lint run --build-tags "$(BUILD_TAGS)"

TEST?=$(patsubst test/%.bats,%,$(wildcard test/*.bats))
Expand All @@ -61,6 +75,11 @@ check: stacker lint
$(shell [ -z $(PRIVILEGE_LEVEL) ] || echo --privilege-level=$(PRIVILEGE_LEVEL)) \
$(patsubst %,test/%.bats,$(TEST))

.PHONY:
show-info:
@echo BUILD_D=$(BUILD_D)
@go env

.PHONY: vendorup
vendorup:
go get -u
Expand Down
7 changes: 4 additions & 3 deletions build.yaml
Expand Up @@ -84,9 +84,10 @@ build:
#!/bin/sh
# golang wants somewhere to put its garbage
export HOME=/root
export GOPATH=/stacker-tree/.build/gopath
export LXC_VERSION=$(git -C /lxc rev-parse HEAD)
export VERSION_FULL=${{VERSION_FULL}}

make -C /stacker-tree/cmd/stacker/lxc-wrapper clean
make -C /stacker-tree stacker-static
cd /stacker-tree
make show-info
make -C cmd/stacker/lxc-wrapper clean
make stacker-static