Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: install dependencies
- name: Install dependencies
run: |
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
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ jobs:
["1.20.x"]
privilege-level: >-
["unpriv", "priv"]
coverage:
uses: ./.github/workflows/coverage.yaml
with:
# note >-, args needs to be strings to be used as inputs
# for the reusable build.yaml workflow
go-version: >-
["1.20.x"]
privilege-level: >-
["unpriv", "priv"]
58 changes: 58 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Reusable stacker build for coverage
on:
workflow_call:
inputs:
go-version:
required: true
type: string
description: 'Stringified JSON object listing go versions'
privilege-level:
required: true
type: string
description: 'Stringified JSON object listing stacker privilege-level'
jobs:
build:
runs-on: ubuntu-22.04
services:
registry:
image: registry:2
ports:
- 5000:5000
strategy:
matrix:
go-version: ${{fromJson(inputs.go-version)}}
privilege-level: ${{fromJson(inputs.privilege-level)}}
name: "golang ${{ matrix.go-version }} privilege ${{ matrix.privilege-level }}"
steps:
- uses: actions/checkout@v3
- uses: benjlevesque/short-sha@v2.1
id: short-sha
- name: Set up golang ${{ matrix.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Install dependencies
run: |
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)
- if: github.event_name != 'release' || github.event.action != 'published'
name: Build and test
run: |
export GOCOVERDIR=.
make check-cov GCOVERDIR=. PRIVILEGE_LEVEL=${{ matrix.privilege-level }}
ls -altr
go tool covdata textfmt -i $GOCOVERDIR -o coverage-${{ matrix.privilege-level }}.txt
go tool covdata percent -i $GOCOVERDIR
ls -altr
env:
REGISTRY_URL: localhost:5000
- name: Upload code coverage
uses: codecov/codecov-action@v3
with:
files: coverage-${{ matrix.privilege-level}}.txt
35 changes: 31 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BUILD_TAGS = exclude_graphdriver_btrfs exclude_graphdriver_devicemapper containe

STACKER_OPTS=--oci-dir=.build/oci --roots-dir=.build/roots --stacker-dir=.build/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
build_stacker = go build $1 -tags "$(BUILD_TAGS) $2" -ldflags "-X main.version=$(VERSION_FULL) -X main.lxc_version=$(LXC_VERSION) $3" -o $4 ./cmd/stacker

STACKER_DOCKER_BASE?=docker://
STACKER_BUILD_BASE_IMAGE?=$(STACKER_DOCKER_BASE)alpine:edge
Expand All @@ -23,15 +23,30 @@ stacker: stacker-dynamic
--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)
--substitute VERSION_FULL=$(VERSION_FULL) \
--substitute WITH_COV=no

stacker-cov: stacker-dynamic
./stacker-dynamic --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) \
--substitute WITH_COV=yes

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

# can't use a comma in func call args, so do this instead
, := ,
stacker-static-cov: $(GO_SRC) go.mod go.sum cmd/stacker/lxc-wrapper/lxc-wrapper
$(call build_stacker,-cover -coverpkg="./pkg/...$(,)./cmd/...",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
$(call build_stacker,,,stacker-dynamic)
$(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
Expand Down Expand Up @@ -61,6 +76,18 @@ check: stacker lint
$(shell [ -z $(PRIVILEGE_LEVEL) ] || echo --privilege-level=$(PRIVILEGE_LEVEL)) \
$(patsubst %,test/%.bats,$(TEST))

check-cov: stacker-cov lint
sudo -E PATH="$$PATH" \
LXC_BRANCH=$(LXC_BRANCH) \
LXC_CLONE_URL=$(LXC_CLONE_URL) \
STACKER_BUILD_BASE_IMAGE=$(STACKER_BUILD_BASE_IMAGE) \
STACKER_BUILD_CENTOS_IMAGE=$(STACKER_BUILD_CENTOS_IMAGE) \
STACKER_BUILD_UBUNTU_IMAGE=$(STACKER_BUILD_UBUNTU_IMAGE) \
GOCOVERDIR=. \
./test/main.py \
$(shell [ -z $(PRIVILEGE_LEVEL) ] || echo --privilege-level=$(PRIVILEGE_LEVEL)) \
$(patsubst %,test/%.bats,$(TEST))

.PHONY: vendorup
vendorup:
go get -u
Expand Down
6 changes: 5 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ build:
export VERSION_FULL=${{VERSION_FULL}}

make -C /stacker-tree/cmd/stacker/lxc-wrapper clean
make -C /stacker-tree stacker-static
if [ x${{WITH_COV}} = x"yes" ]; then
make -C /stacker-tree stacker-static-cov
else
make -C /stacker-tree stacker-static
fi
2 changes: 1 addition & 1 deletion pkg/container/userns.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func MaybeRunInNamespace(config types.StackerConfig, userCmd []string) error {
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = env
cmd.Env = append(env, "GOCOVERDIR=.")
return errors.WithStack(cmd.Run())
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/stacker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ func runInternalGoSubcommand(config types.StackerConfig, args []string) error {
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
// FIXME: add coverage flag
env := []string{"GOCOVERDIR=."}
c.Env = env

return errors.WithStack(c.Run())
}
Expand Down
2 changes: 2 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ function image_copy {
STACKER_DOCKER_BASE=${STACKER_DOCKER_BASE:-docker://}
STACKER_BUILD_CENTOS_IMAGE=${STACKER_BUILD_CENTOS_IMAGE:-${STACKER_DOCKER_BASE}centos:latest}
STACKER_BUILD_UBUNTU_IMAGE=${STACKER_BUILD_UBUNTU_IMAGE:-${STACKER_DOCKER_BASE}ubuntu:latest}
GOCOVERDIR=${GOCOVERDIR:-.}
(
flock 9
[ -f "$ROOT_DIR/test/centos/index.json" ] || (image_copy "${STACKER_BUILD_CENTOS_IMAGE}" "oci:$ROOT_DIR/test/centos:latest" && chmod -R 777 "$ROOT_DIR/test/centos")
[ -f "$ROOT_DIR/test/ubuntu/index.json" ] || (image_copy "${STACKER_BUILD_UBUNTU_IMAGE}" "oci:$ROOT_DIR/test/ubuntu:latest" && chmod -R 777 "$ROOT_DIR/test/ubuntu")
) 9<$ROOT_DIR/test/main.py
export CENTOS_OCI="$ROOT_DIR/test/centos:latest"
export UBUNTU_OCI="$ROOT_DIR/test/ubuntu:latest"
export GOCOVERDIR="."

function sha() {
echo $(sha256sum $1 | cut -f1 -d" ")
Expand Down
1 change: 1 addition & 0 deletions test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

env = os.environ.copy()
env["PRIVILEGE_LEVEL"] = priv
env["GOCOVERDIR"] = "."

print("running tests in modes:", priv)
try:
Expand Down