Skip to content

Commit 85266dd

Browse files
committed
set env variables to execute commands
before executing any action we need to update the environment variables PODMAN_CONNECTIONS_CONF, PODMAN_DATA_DIR and PODMAN_RUNTIME_DIR to define a specific location where to store macadam data. This way we prevent to write macadam stuff within podman-related folders Signed-off-by: lstocchi <[email protected]>
1 parent 5b7cb5d commit 85266dd

File tree

9 files changed

+121
-13
lines changed

9 files changed

+121
-13
lines changed

cmd/macadam/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/cfergeau/macadam/cmd/macadam/registry"
1010
"github.com/cfergeau/macadam/pkg/cmdline"
11+
"github.com/cfergeau/macadam/pkg/env"
1112
"github.com/containers/podman/v5/libpod/define"
1213
"github.com/spf13/cobra"
1314
)
@@ -52,6 +53,7 @@ var (
5253
TraverseChildren: true,
5354
Version: cmdline.Version(),
5455
DisableFlagsInUseLine: true,
56+
PersistentPreRunE: machinePreRunE,
5557
}
5658

5759
defaultLogLevel = "warn"
@@ -82,3 +84,7 @@ func Execute() {
8284

8385
os.Exit(registry.GetExitCode())
8486
}
87+
88+
func machinePreRunE(c *cobra.Command, args []string) error {
89+
return env.SetupEnvironment()
90+
}

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ require (
1414
github.com/spf13/pflag v1.0.5 // indirect
1515
)
1616

17+
require github.com/containers/storage v1.56.0
18+
1719
require (
1820
dario.cat/mergo v1.0.1 // indirect
1921
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
@@ -42,7 +44,6 @@ require (
4244
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
4345
github.com/containers/ocicrypt v1.2.0 // indirect
4446
github.com/containers/psgo v1.9.0 // indirect
45-
github.com/containers/storage v1.56.0 // indirect
4647
github.com/containers/winquit v1.1.0 // indirect
4748
github.com/coreos/go-systemd/v22 v22.5.1-0.20231103132048-7d375ecc2b09 // indirect
4849
github.com/crc-org/vfkit v0.5.1 // indirect
@@ -179,6 +180,8 @@ require (
179180
tags.cncf.io/container-device-interface v0.8.0 // indirect
180181
)
181182

182-
replace github.com/containers/podman/v5 => github.com/cfergeau/podman/v5 v5.0.0-20241127161353-592fb5161f59
183+
replace github.com/containers/podman/v5 => github.com/cfergeau/podman/v5 v5.0.0-20250224120923-ac315765d104
183184

184185
replace github.com/crc-org/machine => github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078
186+
187+
replace github.com/containers/gvisor-tap-vsock => github.com/cfergeau/gvisor-tap-vsock v0.7.3-0.20241209155656-dc16c2d91990

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
3333
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
3434
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
3535
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
36+
github.com/cfergeau/gvisor-tap-vsock v0.7.3-0.20241209155656-dc16c2d91990 h1:NrYHaizZuMJX+7C/y5YS0PRDt1JFKRfsvEp0DBNQEuo=
37+
github.com/cfergeau/gvisor-tap-vsock v0.7.3-0.20241209155656-dc16c2d91990/go.mod h1:gjdY4JBWnynrXsxT8+OM7peEOd4FCZpoOWjSadHva0g=
3638
github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078 h1:KpgRncgq6ZiWDnLe6R58dJjd6QSuU7RDqRrpl11Dxcg=
3739
github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078/go.mod h1:trWeQimjfE3dJ8qWOxI4ePtYm13aecK42bf01s6h/Nc=
38-
github.com/cfergeau/podman/v5 v5.0.0-20241127161353-592fb5161f59 h1:ftTxlR1SCKLTyvJraZUVxO01+i9hvTVC3r7osaY5/HA=
39-
github.com/cfergeau/podman/v5 v5.0.0-20241127161353-592fb5161f59/go.mod h1:aSSwTYeD7i084QIiiTIFpolFyCP28H1h08AY22VrKIo=
40+
github.com/cfergeau/podman/v5 v5.0.0-20250224120923-ac315765d104 h1:QPRzqxScaJAsQc3qvprUeiO01FGPMxF5AQKP8D8Ez5o=
41+
github.com/cfergeau/podman/v5 v5.0.0-20250224120923-ac315765d104/go.mod h1:DTVzcjHg3KA5RwO36cd+nmJvfBPZKcfLugk7wL47ql0=
4042
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
4143
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
4244
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
@@ -73,8 +75,6 @@ github.com/containers/buildah v1.38.1-0.20241119213149-52437ef15d33 h1:Ih6KuyByK
7375
github.com/containers/buildah v1.38.1-0.20241119213149-52437ef15d33/go.mod h1:RxIuKhwTpRl3ma4d4BF6QzSSeg9zNNvo/xhYJOKeDQs=
7476
github.com/containers/common v0.61.1-0.20241125172552-a801fac4edc0 h1:Vh8IytxprODmjd4sALcSVUzhT28vT537UWsfCXcahWk=
7577
github.com/containers/common v0.61.1-0.20241125172552-a801fac4edc0/go.mod h1:3mUU2/PxkOwvL46fmaRVj0YfBDBxNPOMctIvBHWo4Ak=
76-
github.com/containers/gvisor-tap-vsock v0.8.0 h1:Z8ZEWb+Lio0d+lXexONdUWT4rm9lF91vH0g3ARnMy7o=
77-
github.com/containers/gvisor-tap-vsock v0.8.0/go.mod h1:LVwnMiNvhxyGfhaMEQcXKJhNnN4h8woB9U3wf8rYOPc=
7878
github.com/containers/image/v5 v5.33.0 h1:6oPEFwTurf7pDTGw7TghqGs8K0+OvPtY/UyzU0B2DfE=
7979
github.com/containers/image/v5 v5.33.0/go.mod h1:T7HpASmvnp2H1u4cyckMvCzLuYgpD18dSmabSw0AcHk=
8080
github.com/containers/libhvee v0.9.0 h1:5UxJMka1lDfxTeITA25Pd8QVVttJAG43eQS1Getw1tc=

pkg/env/env.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package env
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/containers/storage/pkg/homedir"
8+
)
9+
10+
const connectionsFile = "macadam-connections.json"
11+
12+
func SetupEnvironment() error {
13+
path, err := homedir.GetConfigHome()
14+
if err != nil {
15+
return err
16+
}
17+
18+
connsFile := filepath.Join(filepath.Dir(path), "macadam", connectionsFile)
19+
// set the path used for storing connection of macadam vms
20+
err = os.Setenv("PODMAN_CONNECTIONS_CONF", connsFile)
21+
if err != nil {
22+
return err
23+
}
24+
25+
// set the directory used when calculating the data and config paths
26+
// config -> <configHome>/containers/macadam/machine (configHome changes based on the OS used e.g. configHome == /home/user/.config)
27+
// data -> <dataHome>/containers/macadam/machine (dataHome changes based on the OS used e.g. dataHome == /home/user/.local/share)
28+
err = os.Setenv("PODMAN_DATA_DIR", filepath.Join("macadam", "machine"))
29+
if err != nil {
30+
return err
31+
}
32+
33+
// set the directory to be used when calculating runtime path
34+
// run -> <runHome>/macadam (runHome changes based on the OS used e.g. runHome == /run)
35+
err = os.Setenv("PODMAN_RUNTIME_DIR", "macadam")
36+
if err != nil {
37+
return err
38+
}
39+
40+
return nil
41+
}

vendor/github.com/containers/gvisor-tap-vsock/pkg/types/gvproxy_command.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/podman/v5/pkg/machine/env/dir.go

Lines changed: 31 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/podman/v5/pkg/machine/shim/networking.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/podman/v5/pkg/util/utils_windows.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ github.com/containers/common/pkg/supplemented
157157
github.com/containers/common/pkg/timetype
158158
github.com/containers/common/pkg/util
159159
github.com/containers/common/version
160-
# github.com/containers/gvisor-tap-vsock v0.8.0
160+
# github.com/containers/gvisor-tap-vsock v0.8.0 => github.com/cfergeau/gvisor-tap-vsock v0.7.3-0.20241209155656-dc16c2d91990
161161
## explicit; go 1.22.0
162162
github.com/containers/gvisor-tap-vsock/pkg/types
163163
# github.com/containers/image/v5 v5.33.0
@@ -251,7 +251,7 @@ github.com/containers/ocicrypt/keywrap/pkcs7
251251
github.com/containers/ocicrypt/spec
252252
github.com/containers/ocicrypt/utils
253253
github.com/containers/ocicrypt/utils/keyprovider
254-
# github.com/containers/podman/v5 v5.3.1 => github.com/cfergeau/podman/v5 v5.0.0-20241127161353-592fb5161f59
254+
# github.com/containers/podman/v5 v5.3.1 => github.com/cfergeau/podman/v5 v5.0.0-20250224120923-ac315765d104
255255
## explicit; go 1.22.6
256256
github.com/containers/podman/v5/libpod/define
257257
github.com/containers/podman/v5/pkg/errorhandling
@@ -1075,5 +1075,6 @@ gopkg.in/yaml.v3
10751075
# tags.cncf.io/container-device-interface v0.8.0
10761076
## explicit; go 1.20
10771077
tags.cncf.io/container-device-interface/pkg/parser
1078-
# github.com/containers/podman/v5 => github.com/cfergeau/podman/v5 v5.0.0-20241127161353-592fb5161f59
1078+
# github.com/containers/podman/v5 => github.com/cfergeau/podman/v5 v5.0.0-20250224120923-ac315765d104
10791079
# github.com/crc-org/machine => github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078
1080+
# github.com/containers/gvisor-tap-vsock => github.com/cfergeau/gvisor-tap-vsock v0.7.3-0.20241209155656-dc16c2d91990

0 commit comments

Comments
 (0)