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

Reorganize the code into pkg and internal directories, this moves the oci directory out of stacker binary's way #335

Merged
merged 1 commit into from
Dec 15, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*.swp
*.stacker
stacker
stacker-dynamic
/stacker
/stacker-dynamic
.build

# IDEs
Expand Down
14 changes: 7 additions & 7 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
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

STACKER_DOCKER_BASE?=docker://
STACKER_BUILD_BASE_IMAGE?=$(STACKER_DOCKER_BASE)alpine:edge
Expand All @@ -24,19 +24,19 @@ stacker: stacker-dynamic
--substitute LXC_CLONE_URL=$(LXC_CLONE_URL) \
--substitute LXC_BRANCH=$(LXC_BRANCH)

stacker-static: $(GO_SRC) go.mod go.sum cmd/lxc-wrapper/lxc-wrapper
stacker-static: $(GO_SRC) go.mod go.sum 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/lxc-wrapper/lxc-wrapper
stacker-dynamic: $(GO_SRC) go.mod go.sum cmd/stacker/lxc-wrapper/lxc-wrapper
$(call build_stacker,,,stacker-dynamic)

cmd/lxc-wrapper/lxc-wrapper: cmd/lxc-wrapper/lxc-wrapper.c
make -C cmd/lxc-wrapper LDFLAGS=-static LDLIBS="$(shell pkg-config --static --libs lxc) -lpthread -ldl" lxc-wrapper
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: lint
lint: cmd/lxc-wrapper/lxc-wrapper $(GO_SRC)
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
Expand Down Expand Up @@ -69,4 +69,4 @@ vendorup:
clean:
-unshare -Urm rm -rf stacker stacker-dynamic .build
-rm -r ./test/centos ./test/ubuntu
-make -C cmd/lxc-wrapper clean
-make -C cmd/stacker/lxc-wrapper clean
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ build:
export GOPATH=/stacker-tree/.build/gopath
export LXC_VERSION=$(git -C /lxc rev-parse HEAD)

make -C /stacker-tree/cmd/lxc-wrapper clean
make -C /stacker-tree/cmd/stacker/lxc-wrapper clean
make -C /stacker-tree stacker-static
6 changes: 3 additions & 3 deletions cmd/build.go → cmd/stacker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
ariel-miculas marked this conversation as resolved.
Show resolved Hide resolved

"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/squashfs"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/squashfs"
"stackerbuild.io/stacker/pkg/stacker"
"stackerbuild.io/stacker/pkg/types"
)

var buildCmd = cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/check.go → cmd/stacker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/pkg/xattr"
"github.com/urfave/cli"
"stackerbuild.io/stacker/overlay"
"stackerbuild.io/stacker/pkg/overlay"
)

var checkCmd = cli.Command{
Expand Down
8 changes: 4 additions & 4 deletions cmd/chroot.go → cmd/stacker/chroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

"github.com/pkg/errors"
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/container"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/container"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/stacker"
"stackerbuild.io/stacker/pkg/types"
)

var chrootCmd = cli.Command{
Expand Down
4 changes: 2 additions & 2 deletions cmd/clean.go → cmd/stacker/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/pkg/errors"
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/stacker"
)

var cleanCmd = cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/gc.go → cmd/stacker/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/pkg/stacker"
)

var gcCmd = cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/grab.go → cmd/stacker/grab.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/pkg/errors"
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/pkg/stacker"
)

var grabCmd = cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/inspect.go → cmd/stacker/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/opencontainers/umoci/oci/casext"
"github.com/pkg/errors"
"github.com/urfave/cli"
stackeroci "stackerbuild.io/stacker/oci"
stackeroci "stackerbuild.io/stacker/pkg/oci"
)

var inspectCmd = cli.Command{
Expand Down
8 changes: 4 additions & 4 deletions cmd/internal_go.go → cmd/stacker/internal_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/pkg/errors"
"github.com/urfave/cli"
"golang.org/x/sys/unix"
"stackerbuild.io/stacker/atomfs"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/overlay"
"stackerbuild.io/stacker/pkg/atomfs"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/overlay"
)

var internalGoCmd = cli.Command{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/main.go → cmd/stacker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"github.com/urfave/cli"
"golang.org/x/term"
"gopkg.in/yaml.v2"
"stackerbuild.io/stacker/container"
stackerlog "stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/container"
stackerlog "stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/types"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions cmd/publish.go → cmd/stacker/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"github.com/pkg/errors"
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/squashfs"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/squashfs"
"stackerbuild.io/stacker/pkg/stacker"
"stackerbuild.io/stacker/pkg/types"
)

var publishCmd = cli.Command{
Expand Down
4 changes: 2 additions & 2 deletions cmd/recursive-build.go → cmd/stacker/recursive-build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/stacker"
)

const stackerFilePathRegex = "\\/stacker.yaml$"
Expand Down
2 changes: 1 addition & 1 deletion cmd/unpriv-setup.go → cmd/stacker/unpriv-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/pkg/stacker"
)

var unprivSetupCmd = cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate.go → cmd/stacker/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"
"github.com/urfave/cli"
"stackerbuild.io/stacker"
"stackerbuild.io/stacker/pkg/stacker"
)

/*
Expand Down
4 changes: 2 additions & 2 deletions atomfs/molecule.go → pkg/atomfs/molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
"stackerbuild.io/stacker/mount"
"stackerbuild.io/stacker/squashfs"
"stackerbuild.io/stacker/pkg/mount"
"stackerbuild.io/stacker/pkg/squashfs"
)

type Molecule struct {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion atomfs/oci.go → pkg/atomfs/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

ispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/umoci"
stackeroci "stackerbuild.io/stacker/oci"
stackeroci "stackerbuild.io/stacker/pkg/oci"
)

type MountOCIOpts struct {
Expand Down
6 changes: 3 additions & 3 deletions container/container.go → pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

"github.com/lxc/go-lxc"
"github.com/pkg/errors"
embed_exec "stackerbuild.io/stacker/embed-exec"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
embed_exec "stackerbuild.io/stacker/pkg/embed-exec"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/types"
)

const (
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions container/userns.go → pkg/container/userns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os/exec"

"github.com/pkg/errors"
stackeridmap "stackerbuild.io/stacker/container/idmap"
embed_exec "stackerbuild.io/stacker/embed-exec"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
stackeridmap "stackerbuild.io/stacker/pkg/container/idmap"
embed_exec "stackerbuild.io/stacker/pkg/embed-exec"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/types"
)

// A wrapper which executes userCmd in a namespace if stacker has not already
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package containers_storage

import (
"github.com/containers/image/v5/storage"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/pkg/lib"
)

func init() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/image_test.go → pkg/lib/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/opencontainers/umoci/mutate"
"github.com/opencontainers/umoci/oci/casext"
"github.com/stretchr/testify/assert"
"stackerbuild.io/stacker/squashfs"
"stackerbuild.io/stacker/pkg/squashfs"
)

func createImage(dir string, tag string) error {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions overlay/metadata.go → pkg/overlay/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/umoci/oci/casext"
"github.com/pkg/errors"
"stackerbuild.io/stacker/log"
stackeroci "stackerbuild.io/stacker/oci"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/log"
stackeroci "stackerbuild.io/stacker/pkg/oci"
"stackerbuild.io/stacker/pkg/types"
)

type overlayMetadata struct {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions overlay/overlay-dirs.go → pkg/overlay/overlay-dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/umoci"
"github.com/pkg/errors"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/types"
)

// generateOverlayDirsLayers generates oci layers from all overlay_dirs of this image
Expand Down
2 changes: 1 addition & 1 deletion overlay/overlay.go → pkg/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/pkg/errors"
"golang.org/x/sys/unix"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/types"
)

var _ types.Storage = &overlay{}
Expand Down
12 changes: 6 additions & 6 deletions overlay/pack.go → pkg/overlay/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"github.com/opencontainers/umoci/oci/layer"
"github.com/pkg/errors"
"github.com/pkg/xattr"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
stackeroci "stackerbuild.io/stacker/oci"
"stackerbuild.io/stacker/squashfs"
"stackerbuild.io/stacker/storage"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/log"
stackeroci "stackerbuild.io/stacker/pkg/oci"
"stackerbuild.io/stacker/pkg/squashfs"
"stackerbuild.io/stacker/pkg/storage"
"stackerbuild.io/stacker/pkg/types"
)

func safeOverlayName(d digest.Digest) string {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion overlay/unpriv-setup.go → pkg/overlay/unpriv-setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package overlay

import (
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/types"
)

func UnprivSetup(config types.StackerConfig, uid, gid int) error {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion squashfs/squashfs.go → pkg/squashfs/squashfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/pkg/errors"
"golang.org/x/sys/unix"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/pkg/log"
)

var checkZstdSupported sync.Once
Expand Down
2 changes: 1 addition & 1 deletion squashfs/verity.go → pkg/squashfs/verity.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import (
"github.com/martinjungblut/go-cryptsetup"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
"stackerbuild.io/stacker/mount"
"stackerbuild.io/stacker/pkg/mount"
)

const VerityRootHashAnnotation = "io.stackeroci.stacker.squashfs_verity_root_hash"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions base.go → pkg/stacker/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/opencontainers/umoci/oci/casext"
"github.com/opencontainers/umoci/oci/layer"
"github.com/pkg/errors"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/types"
)

type BaseLayerOpts struct {
Expand Down
6 changes: 3 additions & 3 deletions build.go → pkg/stacker/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/opencontainers/umoci/oci/casext"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"stackerbuild.io/stacker/container"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/container"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/types"
)

const DefaultShell = "/bin/sh"
Expand Down
6 changes: 3 additions & 3 deletions cache.go → pkg/stacker/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"github.com/opencontainers/umoci/oci/casext"
"github.com/pkg/errors"
"github.com/vbatts/go-mtree"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/log"
"stackerbuild.io/stacker/pkg/types"
)

const currentCacheVersion = 12
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go → pkg/stacker/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/opencontainers/umoci"
"github.com/opencontainers/umoci/oci/casext"
"github.com/stretchr/testify/assert"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/pkg/types"
)

func TestLayerHashing(t *testing.T) {
Expand Down
Loading