Skip to content

Commit

Permalink
fix: move the oci folder out of the stacker binary's way
Browse files Browse the repository at this point in the history
This is done by organizing the code into pkg and internal directories.
Files from cmd/ were also moved to cmd/stacker, according to the go
guidelines.

Fixes #296
Fixes #332

Signed-off-by: Ariel Miculas <[email protected]>
  • Loading branch information
Ariel Miculas committed Dec 8, 2022
1 parent e937010 commit 557d407
Show file tree
Hide file tree
Showing 74 changed files with 98 additions and 98 deletions.
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_BUILD_BASE_IMAGE?=docker://alpine:edge
LXC_CLONE_URL?=https://github.com/lxc/lxc
Expand All @@ -21,19 +21,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 All @@ -60,4 +60,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"

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

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/internal/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/internal"
"stackerbuild.io/stacker/internal/log"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/container"
)

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/internal"
"stackerbuild.io/stacker/internal/log"
)

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/internal"
)

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/internal"
)

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/internal/log"
"stackerbuild.io/stacker/internal/overlay"
"stackerbuild.io/stacker/pkg/atomfs"
"stackerbuild.io/stacker/pkg/lib"
)

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"
stackerlog "stackerbuild.io/stacker/internal/log"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/container"
)

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/internal"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
"stackerbuild.io/stacker/pkg/squashfs"
)

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/internal"
"stackerbuild.io/stacker/pkg/lib"
)

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/internal"
)

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/internal"
)

/*
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions base.go → internal/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/internal/log"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
)

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

const DefaultShell = "/bin/sh"
Expand Down
6 changes: 3 additions & 3 deletions cache.go → internal/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/internal/log"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
)

const currentCacheVersion = 12
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go → internal/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/internal/types"
)

func TestLayerHashing(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions deps.go → internal/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package stacker

import (
"sort"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
)

// StackerDepsDAG processes the dependencies between different stacker recipes
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions grab.go → internal/grab.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path"

"github.com/pkg/errors"
"stackerbuild.io/stacker/container"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/container"
)

func Grab(sc types.StackerConfig, storage types.Storage, name string, source string, targetDir string) error {
Expand Down
6 changes: 3 additions & 3 deletions import.go → internal/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/pkg/errors"
"github.com/udhos/equalfile"
"github.com/vbatts/go-mtree"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/internal/log"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
)

// filesDiffer returns true if the files are different, false if they are the same.
Expand Down
2 changes: 1 addition & 1 deletion lock.go → internal/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"

"github.com/pkg/errors"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/internal/types"
)

func findLock(st *syscall.Stat_t) error {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions network.go → internal/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/cheggaaa/pb/v3"
"github.com/pkg/errors"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/internal/log"
"stackerbuild.io/stacker/pkg/lib"
)

// download with caching support in the specified cache dir.
Expand Down
6 changes: 3 additions & 3 deletions overlay/metadata.go → internal/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/internal/log"
"stackerbuild.io/stacker/internal/types"
stackeroci "stackerbuild.io/stacker/pkg/oci"
)

type overlayMetadata struct {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions overlay/overlay-dirs.go → internal/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/internal/types"
"stackerbuild.io/stacker/pkg/lib"
)

// generateOverlayDirsLayers generates oci layers from all overlay_dirs of this image
Expand Down
2 changes: 1 addition & 1 deletion overlay/overlay.go → internal/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/internal/types"
)

var _ types.Storage = &overlay{}
Expand Down
12 changes: 6 additions & 6 deletions overlay/pack.go → internal/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/internal/log"
"stackerbuild.io/stacker/internal/storage"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
stackeroci "stackerbuild.io/stacker/pkg/oci"
"stackerbuild.io/stacker/pkg/squashfs"
)

func safeOverlayName(d digest.Digest) string {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package overlay

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

func UnprivSetup(config types.StackerConfig, uid, gid int) error {
Expand Down
6 changes: 3 additions & 3 deletions publisher.go → internal/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/opencontainers/umoci"
"github.com/opencontainers/umoci/oci/casext"
"github.com/pkg/errors"
"stackerbuild.io/stacker/lib"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/internal/log"
"stackerbuild.io/stacker/internal/types"
"stackerbuild.io/stacker/pkg/lib"
)

type PublishArgs struct {
Expand Down
8 changes: 4 additions & 4 deletions storage.go → internal/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"path"

"github.com/pkg/errors"
"stackerbuild.io/stacker/log"
"stackerbuild.io/stacker/overlay"
"stackerbuild.io/stacker/storage"
"stackerbuild.io/stacker/types"
"stackerbuild.io/stacker/internal/log"
"stackerbuild.io/stacker/internal/overlay"
"stackerbuild.io/stacker/internal/storage"
"stackerbuild.io/stacker/internal/types"
)

var storageTypeFile = "storage.type"
Expand Down
Loading

0 comments on commit 557d407

Please sign in to comment.