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(deps): Bump github.com/containers/podman/v5 from 5.1.1 to 5.1.2 #3

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/pkg/cmdline/version.go export-subst
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: "/tools"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
71 changes: 71 additions & 0 deletions .github/workflows/macadam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build
on:
push:
pull_request: {}
jobs:
build:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
go:
- oldstable
- stable
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: >-
WORKAROUND: Fetch tags that points to the revisions
checked-out(actions/checkout#1467)
run: |-
git fetch --tags --force

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Build
run: make cross
- name: Upload macadam artifact
if: matrix.go == 'stable'
uses: actions/upload-artifact@v4
with:
name: amd64 linux binary
path: "./bin/macadam-linux-amd64"
test:
needs: build
strategy:
matrix:
os:
- ubuntu-22.04
- macos-13
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Test
run: make test
lint:
needs: build
runs-on: ubuntu-22.04
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run 'make check'
run: make check
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
run:
build-tags:
- containers_image_openpgp
- exclude_graphdriver_btrfs
- btrfs_noversion

38 changes: 32 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
.PHONY: all build clean cross test
.PHONY: all build check clean cross test

GIT_VERSION ?= $(shell git describe --always --dirty)
VERSION_LDFLAGS=-X github.com/crc-org/macadam/pkg/cmdline.gitVersion=$(GIT_VERSION)
# opengpg and btrfs support are used by github.com/containers/image and
# github.com/containers/storage when container images are fetched.
# These require external C libraries and their headers, it's simpler to disable
# them for now. Hopefully podman-machine does not use these features.
BUILDTAGS=containers_image_openpgp exclude_graphdriver_btrfs btrfs_noversion

DEFAULT_GOOS=$(shell go env GOOS)
DEFAULT_GOARCH=$(shell go env GOARCH)
Expand All @@ -7,8 +15,13 @@ all: build

build: bin/macadam-$(DEFAULT_GOOS)-$(DEFAULT_GOARCH)

TOOLS_DIR := tools
include tools/tools.mk

cross: bin/macadam-darwin-amd64 bin/macadam-darwin-arm64 bin/macadam-linux-amd64 bin/macadam-linux-arm64 bin/macadam-windows-amd64

check: lint vendorcheck test

test:
@go test -v ./pkg/...

Expand All @@ -18,27 +31,40 @@ clean:
bin/macadam-darwin-amd64: GOOS=darwin
bin/macadam-darwin-amd64: GOARCH=amd64
bin/macadam-darwin-amd64: force-build
@go build -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam
go build -tags "$(BUILDTAGS)" -ldflags "$(VERSION_LDFLAGS)" -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam

bin/macadam-darwin-arm64: GOOS=darwin
bin/macadam-darwin-arm64: GOARCH=arm64
bin/macadam-darwin-arm64: force-build
@go build -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam
go build -tags "$(BUILDTAGS)" -ldflags "$(VERSION_LDFLAGS)" -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam

bin/macadam-linux-amd64: GOOS=linux
bin/macadam-linux-amd64: GOARCH=amd64
bin/macadam-linux-amd64: force-build
@go build -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam
go build -tags "$(BUILDTAGS)" -ldflags "$(VERSION_LDFLAGS)" -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam

bin/macadam-linux-arm64: GOOS=linux
bin/macadam-linux-arm64: GOARCH=arm64
bin/macadam-linux-arm64: force-build
@go build -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam
go build -tags "$(BUILDTAGS)" -ldflags "$(VERSION_LDFLAGS)" -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam

bin/macadam-windows-amd64: GOOS=windows
bin/macadam-windows-amd64: GOARCH=amd64
bin/macadam-windows-amd64: force-build
@go build -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam
go build -tags "$(BUILDTAGS)" -ldflags "$(VERSION_LDFLAGS)" -o bin/macadam-$(GOOS)-$(GOARCH) ./cmd/macadam

.PHONY: lint
lint: $(TOOLS_BINDIR)/golangci-lint
@"$(TOOLS_BINDIR)"/golangci-lint run

.PHONY: vendor
vendor:
go mod tidy
go mod vendor

.PHONY: vendorcheck
vendorcheck:
./build-scripts/verify-vendor.sh

# the go compiler is doing a good job at not rebuilding unchanged files
# this phony target ensures bin/macadam-* are always considered out of date
Expand Down
25 changes: 25 additions & 0 deletions build-scripts/verify-vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

if [[ -n $(git status -s vendor/) ]]; then
echo 'vendor/ directory has uncommitted changes, please check `git status vendor`'
exit 1
fi

make vendor

go mod verify

echo "Diffing $(pwd)"
git diff --exit-code vendor go.mod go.sum

if [[ $? -eq 0 ]]
then
echo "$(pwd) is up to date."
else
echo "$(pwd) is out of date. Please run make vendor"
exit 1
fi
192 changes: 191 additions & 1 deletion cmd/macadam/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,199 @@
package main

import (
"errors"
"fmt"
"log/slog"
"os"

"github.com/crc-org/macadam/pkg/cmdline"

"github.com/containers/common/pkg/config"
ldefine "github.com/containers/podman/v5/libpod/define"

"github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
provider2 "github.com/containers/podman/v5/pkg/machine/provider"
"github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs"

_ "github.com/spf13/cobra"
)

var (
initOpts = define.InitOptions{}
defaultMachineName = machine.DefaultMachineName
)

type PodmanMachine struct {
provider vmconfigs.VMProvider
config *vmconfigs.MachineConfig
}

func startMachine(m *PodmanMachine) error {

machineName := m.config.Name
dirs, err := env.GetMachineDirs(m.provider.VMType())
if err != nil {
return err
}
/*
mc, err := vmconfigs.LoadMachineByName(machineName, dirs)
if err != nil {
return err
}
*/

fmt.Printf("Starting machine %q\n", machineName)

startOpts := machine.StartOptions{
NoInfo: false,
Quiet: false,
}
if err := shim.Start(m.config, m.provider, dirs, startOpts); err != nil {
return err
}
fmt.Printf("Machine %q started successfully\n", machineName)
//newMachineEvent(events.Start, events.Event{Name: vmName})
return nil
}

func initMachine(initOpts define.InitOptions) (*PodmanMachine, error) {
machine := PodmanMachine{}
provider, err := provider2.Get()
if err != nil {
return nil, err
}
machine.provider = provider

// The vmtype names need to be reserved and cannot be used for podman machine names
if _, err := define.ParseVMType(initOpts.Name, define.UnknownVirt); err == nil {
return nil, fmt.Errorf("cannot use %q for a machine name", initOpts.Name)
}

if !ldefine.NameRegex.MatchString(initOpts.Username) {
return nil, fmt.Errorf("invalid username %q: %w", initOpts.Username, ldefine.RegexError)
}

// Check if machine already exists
vmConfig, exists, err := shim.VMExists(initOpts.Name, []vmconfigs.VMProvider{provider})
if err != nil {
return nil, err
}
machine.config = vmConfig

// machine exists, return error
if exists {
return &machine, fmt.Errorf("%s: %w", initOpts.Name, define.ErrVMAlreadyExists)
}

/*
// check if a system connection already exists
cons, err := registry.PodmanConfig().ContainersConfDefaultsRO.GetAllConnections()
if err != nil {
return err
}
for _, con := range cons {
if con.ReadWrite {
for _, connection := range []string{initOpts.Name, fmt.Sprintf("%s-root", initOpts.Name)} {
if con.Name == connection {
return fmt.Errorf("system connection %q already exists. consider a different machine name or remove the connection with `podman system connection rm`", connection)
}
}
}
}
*/

for idx, vol := range initOpts.Volumes {
initOpts.Volumes[idx] = os.ExpandEnv(vol)
}

// TODO need to work this back in
// if finished, err := vm.Init(initOpts); err != nil || !finished {
// // Finished = true, err = nil - Success! Log a message with further instructions
// // Finished = false, err = nil - The installation is partially complete and podman should
// // exit gracefully with no error and no success message.
// // Examples:
// // - a user has chosen to perform their own reboot
// // - reexec for limited admin operations, returning to parent
// // Finished = *, err != nil - Exit with an error message
// return err
// }

err = shim.Init(initOpts, provider)
if err != nil {
return nil, err
}

/*
newMachineEvent(events.Init, events.Event{Name: initOpts.Name})
*/
fmt.Println("Machine init complete")

vmConfig, _, err = shim.VMExists(initOpts.Name, []vmconfigs.VMProvider{provider})
if err != nil {
return nil, err
}
machine.config = vmConfig

/*
now := false
if now {
return startMachine(initOpts.Name, provider)
}
*/
extra := ""

if initOpts.Name != defaultMachineName {
extra = " " + initOpts.Name
}
fmt.Printf("To start your machine run:\n\n\tpodman machine start%s\n\n", extra)
return &machine, err
}

func main() {
slog.Info("macadam")
slog.Info(fmt.Sprintf("macadam version %s", cmdline.Version()))

defaultConfig, err := config.New(&config.Options{
SetDefault: true, // This makes sure that following calls to config.Default() return this config
})
if err != nil {
os.Exit(1)
}

// defaults from cmd/podman/machine/init.go
initOpts.Name = defaultMachineName

initOpts.CPUS = defaultConfig.Machine.CPUs
initOpts.DiskSize = defaultConfig.Machine.DiskSize
initOpts.Memory = defaultConfig.Machine.Memory
defaultTz := defaultConfig.TZ()
if len(defaultTz) < 1 {
defaultTz = "local"
}
initOpts.TimeZone = defaultTz
initOpts.ReExec = false
initOpts.Username = defaultConfig.Machine.User
initOpts.Image = defaultConfig.Machine.Image
initOpts.Volumes = defaultConfig.Machine.Volumes.Get()
initOpts.USBs = []string{}
initOpts.VolumeDriver = ""
initOpts.IgnitionPath = ""
initOpts.Rootful = false
userModeNetworking := false
initOpts.UserModeNetworking = &userModeNetworking
// user-mode networking

machine, err := initMachine(initOpts)
if err != nil && !errors.Is(err, define.ErrVMAlreadyExists) {
slog.Error(err.Error())
}
if err := startMachine(machine); err != nil {
slog.Error(err.Error())
}
/*
if err != nil || errors.Is(err, define.ErrVMAlreadyExists)
{
*/
}
Loading